@@ -37,13 +37,14 @@ import {
3737 DropdownMenuItem ,
3838} from "@shared/components/ui/dropdown-menu" ;
3939import { ModeToggle } from "./mode-toggle" ;
40- import { usePathname } from "next/navigation" ;
40+ import { usePathname , useSearchParams } from "next/navigation" ;
4141import { getPageAspectsByPath } from "./nav-utils" ;
4242import { Skeleton } from "../skeleton" ;
4343import { useContext } from "react" ;
4444import { UserContext } from "@shared/lib/userContext/userContext" ;
4545import { ClassroomWithMembers } from "@shared/lib/userContext/contextFetcher" ;
4646import LogoComponent from "@shared/components/Logo" ;
47+ import Link from "next/link" ;
4748
4849// Menu items.
4950// const items = [
@@ -109,7 +110,7 @@ export function AppSidebar() {
109110 } ,
110111 adminManage : {
111112 title : "Manage courses" ,
112- url : "/classrooms" ,
113+ url : "/classrooms?tab=admin " ,
113114 icon : UserRoundCog ,
114115 isActive : false ,
115116 } ,
@@ -140,7 +141,8 @@ export function AppSidebar() {
140141 } ;
141142
142143 const pathname = usePathname ( ) ;
143- const activePageHierarchy = getPageAspectsByPath ( pathname ) ;
144+ const searchParams = useSearchParams ( ) ;
145+ const activePageHierarchy = getPageAspectsByPath ( pathname , searchParams ) ;
144146
145147 const userContext = useContext ( UserContext ) ;
146148 if ( ! userContext ) {
@@ -160,7 +162,11 @@ export function AppSidebar() {
160162 let classroomInfo : ClassroomWithMembers | undefined ,
161163 isAdminOfActiveClass : boolean = false ;
162164 if ( activePageHierarchy ?. classroomLanding ) {
163- items . enrolled . isActive = true ;
165+ if ( activePageHierarchy . classroomLanding . admin ) {
166+ items . adminManage . isActive = true
167+ } else {
168+ items . enrolled . isActive = true ;
169+ }
164170 } else if ( activePageHierarchy ?. activeClassroom ) {
165171 classroomInfo = userContext . userAndClassData . classroomsData . find (
166172 ( x ) => x . id === activePageHierarchy ?. activeClassroom . id
@@ -187,7 +193,7 @@ export function AppSidebar() {
187193 < SidebarMenu >
188194 < SidebarMenuItem >
189195 < SidebarMenuButton size = "lg" asChild >
190- < a href = "# " >
196+ < Link href = "/ " >
191197 < div className = "flex aspect-square size-8 items-center justify-center rounded-lg bg-sidebar-primary text-sidebar-primary-foreground" >
192198 { /* <div className="relative h-[90%] w-[90%] object-contain"> */ }
193199 { /* <Image src={"/logo.svg"} fill alt="Logo" className="fill-red-600"/> */ }
@@ -197,83 +203,36 @@ export function AppSidebar() {
197203 < div className = "grid flex-1 text-left text-lg leading-tight" >
198204 < span className = "truncate font-semibold" > ClassroomLM</ span >
199205 </ div >
200- </ a >
206+ </ Link >
201207 </ SidebarMenuButton >
202208 </ SidebarMenuItem >
203209 </ SidebarMenu >
204210 </ SidebarHeader >
205211 < SidebarContent >
206- { /** <SidebarGroup>
207- <SidebarGroupContent>
208- <SidebarMenu>
209- {items.map((item) => (
210- <Collapsible
211- defaultOpen
212- className="group/collapsible"
213- key={item.title}
214- >
215- <SidebarMenuItem>
216- <CollapsibleTrigger asChild>
217- <SidebarMenuButton isActive
218- // asChild
219- // style={{
220- // pointerEvents: item.url != "#" ? "auto" : "none",
221- // }}
222- >
223- <a href={item.url == "/" ? "#" : item.url}>
224- {item.icon != null ? <item.icon /> : <span></span>}
225- <span>{item.title}</span>
226- </a>
227- </SidebarMenuButton>
228- </CollapsibleTrigger>
229-
230- <CollapsibleContent>
231- {item.subItems.map((sub) => (
232- <SidebarMenuSub
233- key={sub.title}
234- className="rounded-r-lg hover:bg-[#858fad]"
235- >
236- <SidebarMenuSubItem>
237- <a href={sub.url}>
238- <span>{sub.title}</span>
239- </a>
240- </SidebarMenuSubItem>
241- </SidebarMenuSub>
242- ))}
243- </CollapsibleContent>
244- </SidebarMenuItem>
245- </Collapsible>
246- ))}
247- </SidebarMenu>
248- </SidebarGroupContent>
249- </SidebarGroup> */ }
250- < SidebarGroup >
251- < SidebarGroupLabel className = "text-lg"
252- > Classes</ SidebarGroupLabel >
212+ < SidebarGroup >
213+ < SidebarGroupLabel className = "text-lg" > Classes</ SidebarGroupLabel >
253214 < SidebarMenu className = "space-y-1" >
254215 { Object . entries ( items ) . map ( ( [ itemKey , item ] ) => (
255- < SidebarMenuItem key = { item . title } >
216+ < SidebarMenuItem key = { item . title } >
256217 < SidebarMenuButton
257- className = "text-lg"
258-
218+ className = "text-lg"
259219 tooltip = { item . title }
260220 isActive = { item . isActive }
261221 asChild
262222 size = "default"
263223 >
264- < a href = { item . url } >
224+ < Link href = { item . url } >
265225 { item . icon && < item . icon /> }
266226 < span > { item . title } </ span >
267- </ a >
227+ </ Link >
268228 </ SidebarMenuButton >
269229 { activePageHierarchy ?. activeClassroom &&
270230 classroomInfo &&
271231 ( ( itemKey == "enrolled" && ! isAdminOfActiveClass ) ||
272232 ( itemKey == "adminManage" && isAdminOfActiveClass ) ) && (
273- < SidebarMenuSub >
233+ < SidebarMenuSub >
274234 < SidebarMenuSubItem
275235 key = { activePageHierarchy ?. activeClassroom ?. id }
276-
277236 >
278237 < SidebarMenuSubButton
279238 // size="md"
@@ -305,10 +264,10 @@ export function AppSidebar() {
305264 isActive = { item . isActive }
306265 asChild
307266 >
308- < a href = { item . suffixURL } >
267+ < Link href = { item . suffixURL } >
309268 { item . icon && < item . icon /> }
310269 < span > { item . title } </ span >
311- </ a >
270+ </ Link >
312271 </ SidebarMenuButton >
313272 </ SidebarMenuItem >
314273 ) ) }
0 commit comments