-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGES: db rename all chinese columns to english.
feat(CourseDetails): updated UI for selecting courses
- Loading branch information
1 parent
d09cd22
commit 4c7cd19
Showing
6 changed files
with
181 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
'use client'; | ||
import { CourseDefinition } from '@/config/supabase'; | ||
import useDictionary from '@/dictionaries/useDictionary'; | ||
import { getGECType } from '@/helpers/courses'; | ||
import { DetailedHTMLProps, FC, HTMLAttributes, PropsWithChildren } from 'react'; | ||
import { Users } from 'react-feather'; | ||
|
||
const HighlightItem: FC<PropsWithChildren<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>>> = ({ | ||
children, | ||
className = "", | ||
...props | ||
}) => { | ||
return <div | ||
className={`flex flex-row items-center justify-center min-w-[65px] space-x-2 px-2 py-2 select-none rounded-md bg-indigo-50 text-indigo-900 dark:bg-indigo-950 dark:text-indigo-100 ${className}`} | ||
{...props} | ||
> | ||
{children} | ||
</div> | ||
} | ||
const CourseTagList = ({ course }: { course: CourseDefinition }) => { | ||
const dict = useDictionary(); | ||
return ( | ||
<div className='flex flex-row flex-wrap gap-1 text-sm'> | ||
<HighlightItem> | ||
<span className=""> | ||
{course.capacity ?? '-'} | ||
{(course.reserve ?? 0) > 0 && <> | ||
{` 保 ${course.reserve}`} | ||
</>} | ||
</span> | ||
|
||
<Users strokeWidth={2.5} className='w-5 h-5' /> | ||
</HighlightItem> | ||
<HighlightItem> | ||
<span className="">{course.credits}</span> | ||
<span className="">{dict.course.credits}</span> | ||
</HighlightItem> | ||
{course.tags.includes('16周') && <HighlightItem> | ||
<span className="">16 週</span> | ||
</HighlightItem>} | ||
{course.tags.includes('18周') && <HighlightItem> | ||
<span className="">18 週</span> | ||
</HighlightItem>} | ||
{course.language == '英' ? | ||
<HighlightItem className='bg-cyan-50 text-cyan-900 dark:bg-cyan-950 dark:text-cyan-100'> | ||
English | ||
</HighlightItem> : | ||
<HighlightItem className='bg-amber-50 text-amber-900 dark:bg-amber-950 dark:text-amber-100'> | ||
國語 | ||
</HighlightItem> | ||
} | ||
{/* bg-indigo-50 text-indigo-900 dark:bg-indigo-950 dark:text-indigo-100 */} | ||
{course.tags.includes('X-Class') && | ||
<HighlightItem className='bg-red-50 text-red-900 dark:bg-red-950 dark:text-red-100'> | ||
X-Class | ||
</HighlightItem>} | ||
{(course.ge_target?.trim() || "").length > 0 && | ||
<HighlightItem className='bg-pink-50 text-pink-900 dark:bg-pink-950 dark:text-pink-100'> | ||
{course.ge_target} 通識 | ||
</HighlightItem>} | ||
{getGECType(course.ge_type || "") && | ||
<HighlightItem className='bg-green-50 text-green-900 dark:bg-green-950 dark:text-green-100'> | ||
核通 {getGECType(course.ge_type!)} | ||
</HighlightItem>} | ||
|
||
|
||
</div> | ||
) | ||
} | ||
|
||
export default CourseTagList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use client'; | ||
import useDictionary from "@/dictionaries/useDictionary"; | ||
import { useSettings } from "@/hooks/contexts/settings" | ||
import { RawCourseID } from "@/types/courses"; | ||
import { Button } from "@mui/joy"; | ||
import { useMemo } from "react"; | ||
import { Minus, Plus } from "react-feather"; | ||
|
||
const SelectCourseButton = ({ courseId }: { courseId: RawCourseID }) => { | ||
const { courses, setCourses } = useSettings(); | ||
const dict = useDictionary(); | ||
|
||
const isCourseSelected = useMemo(() => courses.includes(courseId), [courses, courseId]); | ||
|
||
if(isCourseSelected) return <Button | ||
color="danger" | ||
variant="outlined" | ||
onClick={() => setCourses(courses => courses.filter(m => m != courseId))} | ||
startDecorator={<Minus/>} | ||
> | ||
{dict.course.item.remove_from_semester} | ||
</Button> | ||
else return <Button | ||
variant="outlined" | ||
onClick={() => setCourses(courses => [...courses, courseId])} | ||
startDecorator={<Plus/>} | ||
> | ||
{dict.course.item.add_to_semester} | ||
</Button> | ||
} | ||
|
||
export default SelectCourseButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters