44 */
55
66import { useState , useEffect } from "react" ;
7+ import { useLocation , useNavigate } from "react-router" ;
78import { getCohorts , getStudentsByCohort } from "../api/client" ;
89import type { Student , Cohort } from "../api/client" ;
910import { MessageFeed } from "../components/MessageFeed" ;
@@ -17,11 +18,16 @@ import { SimulationsHub } from "../components/SimulationsHub";
1718import { useAuth } from "../hooks/useAuth" ;
1819
1920type Tab = "students" | "simulations" | "observers" | "messages" | "testing" | "diagnostics" ;
21+ const VALID_TABS : Tab [ ] = [ "students" , "simulations" , "observers" , "messages" , "testing" , "diagnostics" ] ;
2022
2123/** Instructor admin dashboard with tabs and impersonation. */
2224export function InstructorPage ( ) {
2325 const { username, sessionInvalid, logout } = useAuth ( ) ;
24- const [ activeTab , setActiveTab ] = useState < Tab > ( "students" ) ;
26+ const location = useLocation ( ) ;
27+ const navigate = useNavigate ( ) ;
28+
29+ const segment = location . pathname . split ( "/" ) [ 2 ] ?? "" ;
30+ const activeTab : Tab = VALID_TABS . includes ( segment as Tab ) ? ( segment as Tab ) : "students" ;
2531 const [ impersonating , setImpersonating ] = useState < { discordId : string ; name : string ; cohortId : number } | null > ( null ) ;
2632 const [ impersonateStudents , setImpersonateStudents ] = useState < { discordId : string ; name : string ; cohortId : number } [ ] > ( [ ] ) ;
2733 const [ cohorts , setCohorts ] = useState < Cohort [ ] > ( [ ] ) ;
@@ -115,37 +121,37 @@ export function InstructorPage() {
115121 < nav className = "tab-navigation" >
116122 < button
117123 className = { `tab-btn ${ activeTab === "students" ? "active" : "" } ` }
118- onClick = { ( ) => setActiveTab ( " students") }
124+ onClick = { ( ) => navigate ( "/instructor/ students") }
119125 >
120126 Students
121127 </ button >
122128 < button
123129 className = { `tab-btn ${ activeTab === "simulations" ? "active" : "" } ` }
124- onClick = { ( ) => setActiveTab ( " simulations") }
130+ onClick = { ( ) => navigate ( "/instructor/ simulations") }
125131 >
126132 Simulations
127133 </ button >
128134 < button
129135 className = { `tab-btn ${ activeTab === "observers" ? "active" : "" } ` }
130- onClick = { ( ) => setActiveTab ( " observers") }
136+ onClick = { ( ) => navigate ( "/instructor/ observers") }
131137 >
132138 Observers
133139 </ button >
134140 < button
135141 className = { `tab-btn ${ activeTab === "messages" ? "active" : "" } ` }
136- onClick = { ( ) => setActiveTab ( " messages") }
142+ onClick = { ( ) => navigate ( "/instructor/ messages") }
137143 >
138144 Messages
139145 </ button >
140146 < button
141147 className = { `tab-btn ${ activeTab === "testing" ? "active" : "" } ` }
142- onClick = { ( ) => setActiveTab ( " testing") }
148+ onClick = { ( ) => navigate ( "/instructor/ testing") }
143149 >
144150 Testing
145151 </ button >
146152 < button
147153 className = { `tab-btn ${ activeTab === "diagnostics" ? "active" : "" } ` }
148- onClick = { ( ) => setActiveTab ( " diagnostics") }
154+ onClick = { ( ) => navigate ( "/instructor/ diagnostics") }
149155 >
150156 Configuration
151157 </ button >
0 commit comments