@@ -6,23 +6,30 @@ import Link from "next/link";
66import { usePathname } from "next/navigation" ;
77import ccLogo from "../assets/codechef_logo.svg" ;
88import ModeToggle from "@/components/toggle-theme" ;
9- import { ArrowDownLeftIcon , Pin , ArrowUpRight , ChevronDown } from "lucide-react" ;
9+ import {
10+ ArrowDownLeftIcon ,
11+ Pin ,
12+ ArrowUpRight ,
13+ ChevronDown ,
14+ } from "lucide-react" ;
1015import FloatingNavbar from "./FloatingNavbar" ;
1116import PWAInstallButton from "./ui/PWAInstallButton" ;
1217import SearchBarChild from "./Searchbar/searchbar-child" ;
13- import Banner from "@/components/bannerDismiss"
14- import type { ICourses } from "@/interface" ;
18+ import Banner from "@/components/bannerDismiss" ;
19+ import type { ICourses } from "@/interface" ;
1520import {
1621 DropdownMenu ,
1722 DropdownMenuTrigger ,
1823 DropdownMenuContent ,
1924 DropdownMenuItem ,
2025} from "@/components/ui/dropdown-menu" ;
26+ import { useCourses } from "@/context/courseContext" ;
2127
2228function Navbar ( ) {
2329 const pathname : string = usePathname ( ) ?? "/" ;
2430 const [ subjects , setSubjects ] = useState < string [ ] > ( [ ] ) ;
2531 const [ dropdownOpen , setDropdownOpen ] = useState < boolean > ( false ) ;
32+ const { courses, loading, error, refetch } = useCourses ( ) ;
2633
2734 useEffect ( ( ) => {
2835 if ( pathname !== "/catalogue" ) return ;
@@ -36,8 +43,11 @@ function Navbar() {
3643
3744 if ( Array . isArray ( json ) ) {
3845 const filtered = json
39- . filter ( ( item ) : item is ICourses => typeof item === "object" && item !== null && "name" in item )
40- . map ( item => item . name ) ;
46+ . filter (
47+ ( item ) : item is ICourses =>
48+ typeof item === "object" && item !== null && "name" in item ,
49+ )
50+ . map ( ( item ) => item . name ) ;
4151 setSubjects ( filtered ) ;
4252 } else {
4353 console . error ( "Invalid data returned from API:" , json ) ;
@@ -53,36 +63,14 @@ function Navbar() {
5363 const renderHomePageButtons = ( ) => (
5464 < >
5565 < Link href = "/pinned" className = "ml-2" >
56- < div className = "flex items-center
57- gap-1 sm:gap-2
58- rounded-full border border-[#3A3745]
59- bg-[#e8e9ff] dark:bg-black
60- px-2.5 sm:px-3.5 md:px-4
61- py-1 sm:py-1.5 md:py-2
62- text-xs sm:text-sm md:text-base
63- font-semibold
64- text-gray-700 dark:text-white
65- transition hover:bg-slate-50 dark:hover:bg-[#1A1823]
66- h-8 sm:h-9 md:h-10" >
67-
66+ < div className = "flex h-8 items-center gap-1 rounded-full border border-[#3A3745] bg-[#e8e9ff] px-2.5 py-1 text-xs font-semibold text-gray-700 transition hover:bg-slate-50 dark:bg-black dark:text-white dark:hover:bg-[#1A1823] sm:h-9 sm:gap-2 sm:px-3.5 sm:py-1.5 sm:text-sm md:h-10 md:px-4 md:py-2 md:text-base" >
6867 < Pin className = "h-3.5 w-3.5 sm:h-4 sm:w-4" />
6968 < span className = "truncate" > Pinned Subjects</ span >
7069 </ div >
7170 </ Link >
7271
7372 < Link href = "/request" className = "ml-2 mt-2 sm:mt-0" >
74- < div className = "flex items-center
75- gap-1 sm:gap-2
76- rounded-full border border-[#3A3745]
77- bg-[#e8e9ff] dark:bg-black
78- px-2.5 sm:px-3.5 md:px-4
79- py-1 sm:py-1.5 md:py-2
80- text-xs sm:text-sm md:text-base
81- font-semibold
82- text-gray-700 dark:text-white
83- transition hover:bg-slate-50 dark:hover:bg-[#1A1823]
84- h-8 sm:h-9 md:h-10" >
85-
73+ < div className = "flex h-8 items-center gap-1 rounded-full border border-[#3A3745] bg-[#e8e9ff] px-2.5 py-1 text-xs font-semibold text-gray-700 transition hover:bg-slate-50 dark:bg-black dark:text-white dark:hover:bg-[#1A1823] sm:h-9 sm:gap-2 sm:px-3.5 sm:py-1.5 sm:text-sm md:h-10 md:px-4 md:py-2 md:text-base" >
8674 < ArrowUpRight className = "h-3.5 w-3.5 sm:h-4 sm:w-4" />
8775 < span className = "truncate" > Paper Request</ span >
8876 </ div >
@@ -92,20 +80,25 @@ function Navbar() {
9280
9381 return (
9482 < div className = "sticky top-0 z-[50] w-full bg-[#B2B8FF] dark:bg-[#130E1F]" >
95- < Banner
96- bannerId = "freshers"
97- bgColor = "#fef3c7"
98- textColor = "#5a3000"
99- iconColor = "#d97706"
100- accentColor = "#78350f"
101- title = "Attention Freshers!"
102- message = "If papers for your subject are not yet available, click on your subject and explore related subjects until papers become available, as these are newly introduced courses."
103- />
104- < div className = "flex items-center justify-between bg-inherit px-4 py-4 md:px-8 md:py-5" >
83+ < Banner
84+ bannerId = "freshers"
85+ bgColor = "#fef3c7"
86+ textColor = "#5a3000"
87+ iconColor = "#d97706"
88+ accentColor = "#78350f"
89+ title = "Attention Freshers!"
90+ message = "If papers for your subject are not yet available, click on your subject and explore related subjects until papers become available, as these are newly introduced courses."
91+ />
92+ < div className = "flex items-center justify-between bg-inherit px-4 py-4 md:px-8 md:py-5" >
10593 { }
106- < div className = "flex items-center gap-4 relative " >
94+ < div className = "relative flex items-center gap-4" >
10795 < Link href = "https://www.codechefvit.com/" target = "_blank" >
108- < Image src = { ccLogo as StaticImageData } alt = "codechef-logo" height = { 60 } width = { 60 } />
96+ < Image
97+ src = { ccLogo as StaticImageData }
98+ alt = "codechef-logo"
99+ height = { 60 }
100+ width = { 60 }
101+ />
109102 </ Link >
110103
111104 < Link
@@ -116,7 +109,7 @@ function Navbar() {
116109 </ Link >
117110
118111 { pathname === "/catalogue" ? (
119- < div className = "ml-4 hidden xl:block relative " >
112+ < div className = "relative ml-4 hidden xl:block" >
120113 < DropdownMenu open = { dropdownOpen } onOpenChange = { setDropdownOpen } >
121114 < DropdownMenuTrigger asChild >
122115 < button
@@ -130,7 +123,7 @@ function Navbar() {
130123 </ DropdownMenuTrigger >
131124
132125 < DropdownMenuContent
133- className = "w-56 rounded-2xl bg-[#4B22D1] text-white border border-[rgba(255,255,255,0.1)] shadow-2xl backdrop-blur-sm"
126+ className = "w-56 rounded-2xl border border-[rgba(255,255,255,0.1)] bg-[#4B22D1] text-white shadow-2xl backdrop-blur-sm"
134127 align = "start"
135128 >
136129 < DropdownMenuItem asChild >
@@ -150,72 +143,70 @@ function Navbar() {
150143 </ div >
151144 ) : (
152145 < >
153- < div className = "ml-2 hidden lg:block xl:hidden relative" >
154- < DropdownMenu open = { dropdownOpen } onOpenChange = { setDropdownOpen } >
155- < DropdownMenuTrigger asChild >
156- < button
157- className = "flex h-10 w-10 items-center justify-center rounded-full bg-[#4B22D1] text-white shadow-lg transition-transform duration-200 hover:scale-105 active:scale-95"
158- aria-label = "Toggle dropdown"
159- >
160- < ChevronDown
161- className = { `h-5 w-5 transition-transform duration-200 ${ dropdownOpen ? "rotate-180" : "" } ` }
162- />
163- </ button >
164- </ DropdownMenuTrigger >
165-
166- < DropdownMenuContent
167- className = "w-56 rounded-2xl bg-[#4B22D1] text-white border border-[rgba(255,255,255,0.1)] shadow-2xl backdrop-blur-sm"
168- align = "start"
146+ < div className = "relative ml-2 hidden lg:block xl:hidden" >
147+ < DropdownMenu
148+ open = { dropdownOpen }
149+ onOpenChange = { setDropdownOpen }
169150 >
170- < DropdownMenuItem asChild >
171- < Link href = "/pinned" className = "flex items-center gap-3" >
172- < Pin className = "h-4 w-4" />
173- < span className = "font-medium" > Pinned Subjects</ span >
174- </ Link >
175- </ DropdownMenuItem >
176- < DropdownMenuItem asChild >
177- < Link href = "/request" className = "flex items-center gap-3" >
178- < ArrowUpRight className = "h-4 w-4" />
179- < span className = "font-medium" > Paper Request</ span >
180- </ Link >
181- </ DropdownMenuItem >
182- </ DropdownMenuContent >
183- </ DropdownMenu >
184- </ div >
185- < div className = "hidden xl:flex items-center h-10" > { renderHomePageButtons ( ) } </ div > </ >
151+ < DropdownMenuTrigger asChild >
152+ < button
153+ className = "flex h-10 w-10 items-center justify-center rounded-full bg-[#4B22D1] text-white shadow-lg transition-transform duration-200 hover:scale-105 active:scale-95"
154+ aria-label = "Toggle dropdown"
155+ >
156+ < ChevronDown
157+ className = { `h-5 w-5 transition-transform duration-200 ${ dropdownOpen ? "rotate-180" : "" } ` }
158+ />
159+ </ button >
160+ </ DropdownMenuTrigger >
161+
162+ < DropdownMenuContent
163+ className = "w-56 rounded-2xl border border-[rgba(255,255,255,0.1)] bg-[#4B22D1] text-white shadow-2xl backdrop-blur-sm"
164+ align = "start"
165+ >
166+ < DropdownMenuItem asChild >
167+ < Link href = "/pinned" className = "flex items-center gap-3" >
168+ < Pin className = "h-4 w-4" />
169+ < span className = "font-medium" > Pinned Subjects</ span >
170+ </ Link >
171+ </ DropdownMenuItem >
172+ < DropdownMenuItem asChild >
173+ < Link href = "/request" className = "flex items-center gap-3" >
174+ < ArrowUpRight className = "h-4 w-4" />
175+ < span className = "font-medium" > Paper Request</ span >
176+ </ Link >
177+ </ DropdownMenuItem >
178+ </ DropdownMenuContent >
179+ </ DropdownMenu >
180+ </ div >
181+ < div className = "hidden h-10 items-center xl:flex" >
182+ { renderHomePageButtons ( ) }
183+ </ div >
184+ </ >
186185 ) }
187186 </ div >
188187
189188 { }
190189 { pathname === "/catalogue" && (
191- < div className = "hidden md: flex flex -1 justify-center mr-12 ml-8 " >
190+ < div className = "ml-8 mr-12 hidden flex-1 justify-center md:flex " >
192191 < div className = "w-full max-w-[700px]" >
193- < SearchBarChild initialSubjects = { subjects } />
192+ < SearchBarChild initialSubjects = { courses } />
194193 </ div >
195194 </ div >
196195 ) }
197196
198197 { }
199- < div className = { `${ pathname === "/catalogue" ? "xl:flex" : "lg:flex" } hidden items-center gap-4` } >
200- < div className = "rounded-full border border-[#3A3745] p-1" >
198+ < div
199+ className = { `${ pathname === "/catalogue" ? "xl:flex" : "lg:flex" } hidden items-center gap-4` }
200+ >
201+ < div className = "rounded-full border border-[#3A3745] p-1" >
201202 < ModeToggle />
202203 </ div >
203204 < div className = "hidden max-w-[200px] md:block" >
204205 < PWAInstallButton />
205206 </ div >
206207 < Link href = { pathname === "/upload" ? "/" : "/upload" } >
207- < div className = "flex items-center
208- gap-1 sm:gap-1.5 md:gap-2
209- rounded-full border border-[#3A3745]
210- bg-[#e8e9ff] dark:bg-black
211- px-2.5 sm:px-3.5 md:px-4
212- py-1 sm:py-1.5 md:py-2
213- text-xs sm:text-sm md:text-base
214- font-semibold
215- text-gray-700 dark:text-white
216- transition hover:bg-slate-50 dark:hover:bg-[#1A1823]
217- h-8 sm:h-9 md:h-10" >
218- < ArrowDownLeftIcon className = "h-3.5 w-3.5 sm:h-4 sm:w-4 rotate-90" />
208+ < div className = "flex h-8 items-center gap-1 rounded-full border border-[#3A3745] bg-[#e8e9ff] px-2.5 py-1 text-xs font-semibold text-gray-700 transition hover:bg-slate-50 dark:bg-black dark:text-white dark:hover:bg-[#1A1823] sm:h-9 sm:gap-1.5 sm:px-3.5 sm:py-1.5 sm:text-sm md:h-10 md:gap-2 md:px-4 md:py-2 md:text-base" >
209+ < ArrowDownLeftIcon className = "h-3.5 w-3.5 rotate-90 sm:h-4 sm:w-4" />
219210 < span className = "truncate" >
220211 { pathname === "/upload" ? "Search Papers" : "Upload Papers" }
221212 </ span >
@@ -224,12 +215,14 @@ function Navbar() {
224215 </ div >
225216
226217 { }
227- < div className = { `${ pathname === "/catalogue" ? "xl:hidden" : "lg:hidden" } ` } >
218+ < div
219+ className = { `${ pathname === "/catalogue" ? "xl:hidden" : "lg:hidden" } ` }
220+ >
228221 < FloatingNavbar onNavigate = { ( ) => void 0 } />
229222 </ div >
230223 </ div >
231224 </ div >
232225 ) ;
233226}
234227
235- export default Navbar ;
228+ export default Navbar ;
0 commit comments