@@ -19,12 +19,14 @@ interface CourseDetailPanelProps {
1919 title : string ,
2020 alternativeOf ?: Id < "userCourseOfferings" > ,
2121 ) => void ;
22+ onSwap ?: ( alternativeId : Id < "userCourseOfferings" > ) => void ;
2223}
2324
2425export function CourseDetailPanel ( {
2526 course,
2627 onClose,
2728 onDelete,
29+ onSwap,
2830} : CourseDetailPanelProps ) {
2931 const alternatives = useQuery (
3032 api . userCourseOfferings . getAlternativeCourses ,
@@ -36,6 +38,24 @@ export function CourseDetailPanel({
3638 : "skip" ,
3739 ) ;
3840
41+ // Get the main course info if this course is an alternative
42+ const allUserCourses = useQuery (
43+ api . userCourseOfferings . getUserCourseOfferings ,
44+ ) ;
45+ const currentCourse = course ?. userCourseOfferingId
46+ ? allUserCourses ?. find ( ( c ) => c . _id === course . userCourseOfferingId )
47+ : null ;
48+
49+ const alternativeOfId : Id < "userCourseOfferings" > | null = currentCourse
50+ ? ( currentCourse . alternativeOf as Id < "userCourseOfferings" > | null )
51+ : course ?. alternativeOf
52+ ? ( course . alternativeOf as Id < "userCourseOfferings" > )
53+ : null ;
54+
55+ const mainCourse = alternativeOfId
56+ ? allUserCourses ?. find ( ( c ) => c . _id === alternativeOfId )
57+ : null ;
58+
3959 if ( ! course ) return null ;
4060
4161 const handleDelete = ( ) => {
@@ -44,7 +64,7 @@ export function CourseDetailPanel({
4464 course . userCourseOfferingId as Id < "userCourseOfferings" > ,
4565 course . classNumber ,
4666 course . title ,
47- course . alternativeOf as Id < "userCourseOfferings" > | undefined ,
67+ alternativeOfId ?? undefined ,
4868 ) ;
4969 onClose ( ) ;
5070 }
@@ -214,17 +234,17 @@ export function CourseDetailPanel({
214234 < Separator />
215235 < div className = "space-y-3" >
216236 < h4 className = "text-sm font-semibold text-foreground" >
217- Alternative Courses
237+ Alternative Courses Added by You
218238 </ h4 >
219239 < div className = "space-y-2" >
220240 { alternatives . map ( ( alt ) => (
221241 < div
222242 key = { alt . _id }
223- className = "rounded-lg border p-3 space-y-2 hover:bg-accent/50 transition-colors"
243+ className = "rounded-lg border p-3 space-y-2 hover:bg-accent/50 transition-colors group "
224244 >
225245 < div className = "flex items-start justify-between gap-2" >
226246 < div className = "flex-1 min-w-0" >
227- < p className = "text-sm font-medium break-words" >
247+ < p className = "text-sm font-medium break-words mb-1 " >
228248 { alt . courseOffering . courseCode } -{ " " }
229249 { alt . courseOffering . title }
230250 </ p >
@@ -249,12 +269,45 @@ export function CourseDetailPanel({
249269 • { alt . courseOffering . startTime } -{ " " }
250270 { alt . courseOffering . endTime }
251271 </ div >
272+ < Button
273+ variant = "outline"
274+ size = "sm"
275+ className = "w-full text-xs"
276+ onClick = { ( ) => onSwap ?.( alt . _id ) }
277+ >
278+ Switch to this course
279+ </ Button >
252280 </ div >
253281 ) ) }
254282 </ div >
255283 </ div >
256284 </ >
257285 ) }
286+
287+ { /* Alternative Course Info */ }
288+ { mainCourse && (
289+ < div className = "rounded-lg border p-4 space-y-3" >
290+ < p className = "text-sm text-muted-foreground" >
291+ This course is an alternative of{ " " }
292+ < span className = "text-foreground" >
293+ { mainCourse . courseOffering . title }
294+ </ span >
295+ </ p >
296+ < Button
297+ variant = "outline"
298+ size = "sm"
299+ className = "w-full text-xs"
300+ onClick = { ( ) =>
301+ onSwap ?.(
302+ course . userCourseOfferingId as Id < "userCourseOfferings" > ,
303+ )
304+ }
305+ >
306+ Replace with { mainCourse . courseOffering . courseCode } -
307+ { " Section " } { mainCourse . courseOffering . section }
308+ </ Button >
309+ </ div >
310+ ) }
258311 </ div >
259312 </ ScrollArea >
260313
0 commit comments