-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #155 from maingockien01/Update-Frontend-Structure
Fix FE file structure
- Loading branch information
Showing
21 changed files
with
209 additions
and
208 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,145 @@ | ||
import React, {useState} from 'react'; | ||
import {CourseDTO} from '@team8/types/dtos/course/course.dto'; | ||
import {Chip, Fade, Grid} from '@mui/material'; | ||
import '../css/CourseTree.css'; | ||
import Tooltip from '@mui/material/Tooltip'; | ||
|
||
export interface CourseTreeProps { | ||
courses: CourseDTO[]; | ||
onRemoveCourse?: (course: CourseDTO) => void | undefined; | ||
} | ||
|
||
interface CourseChipProps { | ||
course: CourseDTO; | ||
isSelected: boolean; | ||
isPrerequisite: boolean; | ||
label: string; | ||
} | ||
|
||
const courseTree = ({courses, onRemoveCourse = undefined}: CourseTreeProps) => { | ||
const [courseChips, setCourseChips] = useState<CourseChipProps[]>( | ||
courses.map((course: CourseDTO) => { | ||
return { | ||
course, | ||
isSelected: false, | ||
isPrerequisite: false, | ||
label: `${course.department.abbreviation} ${course.courseNumber}`, | ||
}; | ||
}), | ||
); | ||
const toggleHightlightCourses = ( | ||
selected: CourseDTO, | ||
prerequisite: CourseDTO[], | ||
hightlight = true, | ||
) => { | ||
const cids = prerequisite.map((course) => course.cid); | ||
const newCourseChips = courseChips | ||
.map((courseChip) => { | ||
if (cids.includes(courseChip.course.cid)) { | ||
courseChip.isPrerequisite = hightlight; | ||
} | ||
return courseChip; | ||
}) | ||
.map((courseChip) => { | ||
if (courseChip.course.cid === selected.cid) { | ||
courseChip.isSelected = hightlight; | ||
} | ||
return courseChip; | ||
}); | ||
setCourseChips(newCourseChips); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h3>Recommended courses</h3> | ||
<Grid | ||
container | ||
spacing={2} | ||
className="course_tree--grid_container" | ||
rowSpacing={5} | ||
> | ||
{courseChips.map( | ||
({course, isSelected, isPrerequisite, label}: CourseChipProps) => ( | ||
<Grid item xs="auto"> | ||
<Tooltip | ||
TransitionComponent={Fade} | ||
TransitionProps={{timeout: 600}} | ||
title={course.courseName} | ||
placement="bottom-start" | ||
> | ||
{onRemoveCourse ? ( | ||
<Chip | ||
className="course_tree--chip" | ||
label={label} | ||
color={ | ||
isSelected | ||
? 'primary' | ||
: isPrerequisite | ||
? 'secondary' | ||
: 'default' | ||
} | ||
key={course.cid} | ||
variant="filled" | ||
onMouseOver={() => | ||
// eslint-disable-next-line max-len | ||
toggleHightlightCourses( | ||
course, | ||
course.prerequisites, | ||
true, | ||
) | ||
} | ||
onMouseOut={() => | ||
// eslint-disable-next-line max-len | ||
toggleHightlightCourses( | ||
course, | ||
course.prerequisites, | ||
false, | ||
) | ||
} | ||
onDelete={() => { | ||
if (onRemoveCourse) { | ||
onRemoveCourse(course); | ||
} | ||
}} | ||
/> | ||
) : ( | ||
<Chip | ||
className="course_tree--chip" | ||
label={label} | ||
color={ | ||
isSelected | ||
? 'primary' | ||
: isPrerequisite | ||
? 'secondary' | ||
: 'default' | ||
} | ||
key={course.cid} | ||
variant="filled" | ||
onMouseOver={() => | ||
// eslint-disable-next-line max-len | ||
toggleHightlightCourses( | ||
course, | ||
course.prerequisites, | ||
true, | ||
) | ||
} | ||
onMouseOut={() => | ||
// eslint-disable-next-line max-len | ||
toggleHightlightCourses( | ||
course, | ||
course.prerequisites, | ||
false, | ||
) | ||
} | ||
/> | ||
)} | ||
</Tooltip> | ||
</Grid> | ||
), | ||
)} | ||
</Grid> | ||
</div> | ||
); | ||
}; | ||
|
||
export default courseTree; |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.