-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed behaviour of preserving prev calendar data
- Loading branch information
Showing
6 changed files
with
115 additions
and
65 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
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,77 @@ | ||
import { useMediaQuery, useTheme, FormControl, MenuItem, Select, InputLabel } from '@mui/material'; | ||
import React, { useContext } from 'react'; | ||
|
||
import { ThemeType } from '../../constants/theme'; | ||
import { AppContext } from '../../context/AppContext'; | ||
import { CourseContext } from '../../context/CourseContext'; | ||
|
||
|
||
const TermSelect: React.FC = () => { | ||
|
||
const { | ||
term, | ||
termName, | ||
setTermName, | ||
year, | ||
setTerm, | ||
setYear, | ||
setSelectedTimetable, | ||
displayTimetables, | ||
termsData | ||
} = useContext(AppContext); | ||
|
||
const { setSelectedCourses, setSelectedClasses, setCreatedEvents } = | ||
useContext(CourseContext); | ||
|
||
const theme = useTheme<ThemeType>(); | ||
const isMobile = useMediaQuery(theme.breakpoints.down('sm')); | ||
|
||
const termData = new Set([termsData.prevTerm.termName.concat(', ', termsData.prevTerm.year), termsData.newTerm.termName.concat(', ', termsData.newTerm.year)]); | ||
|
||
const selectTerm = (e: any) => { | ||
const defaultStartTimetable = 0; | ||
|
||
let newTermName = e.target.value.split(', ')[0]; | ||
let termNum = 'T' + newTermName.split(' ')[1]; | ||
let newYear = e.target.value.split(', ')[1]; | ||
|
||
if (e.target.value.includes("Summer")) { | ||
// This is a summer term. | ||
termNum = "Summer"; | ||
} | ||
|
||
setTerm(termNum); | ||
setYear(newYear); | ||
setTermName(newTermName); | ||
setSelectedTimetable(defaultStartTimetable); | ||
setSelectedClasses(displayTimetables[termNum][defaultStartTimetable].selectedClasses); | ||
setCreatedEvents(displayTimetables[termNum][defaultStartTimetable].createdEvents); | ||
setSelectedCourses(displayTimetables[termNum][defaultStartTimetable].selectedCourses); | ||
} | ||
|
||
return ( | ||
<FormControl> | ||
<InputLabel sx={{ marginTop: 1, color: 'white' }}>Select your term</InputLabel> | ||
<Select | ||
label="Select your term" | ||
value={isMobile ? term : termName.concat(', ', year)} | ||
sx={{ | ||
marginTop: 1, | ||
color: 'white', | ||
'.MuiSelect-icon': { | ||
color: 'white' | ||
}, | ||
}} | ||
onChange={selectTerm} | ||
> | ||
{ | ||
Array.from(termData).map((term, index) => { | ||
return <MenuItem key={index} value={term}>{term}</MenuItem>; | ||
}) | ||
} | ||
</Select> | ||
</FormControl> | ||
); | ||
}; | ||
|
||
export default TermSelect; |
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