-
Notifications
You must be signed in to change notification settings - Fork 9
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 #16 from Krishnansh5/main
made final fixes except the template
- Loading branch information
Showing
16 changed files
with
580 additions
and
313 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,6 @@ yarn-debug.log* | |
yarn-error.log* | ||
yarn.lock | ||
.next/ | ||
.clash-hai-bhai-key.json | ||
clash-hai-bhai-key.json | ||
|
||
backend/env/ |
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,9 @@ | ||
import { course_data } from "@js/course_data.js" | ||
import { template_data } from '@js/template.js' | ||
|
||
export const allDepts = Object.keys(course_data); | ||
|
||
export const allTemplates = template_data; | ||
export const allBranches: string[] = Object.keys(allTemplates); | ||
|
||
export const semesters = ["1","2","3","4","5","6","7","8"]; |
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,6 @@ | ||
import React from "react"; | ||
import { globalContextType } from "./types"; | ||
|
||
export const GlobalContext = React.createContext<globalContextType | null>(null); | ||
|
||
export default GlobalContext; |
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,250 @@ | ||
import { SelectChangeEvent } from "@mui/material"; | ||
import { Dispatch, SetStateAction } from "react"; | ||
import { courses, semTemplate } from "./types"; | ||
import { allTemplates } from "./constants"; | ||
import { get_all_dept_eligible_courses, get_course_details, get_eligible_courses } from "@js/get_course_utils"; | ||
import { getCredits, removeLastChars } from "./utils"; | ||
|
||
const setTemplateWithoutLastChars = (template: string[], setTemplate: Dispatch<SetStateAction<string[]>>) => { | ||
setTemplate(template.map((course) => { | ||
return removeLastChars(course); | ||
})) | ||
} | ||
|
||
const getTemplateRows = (template: string[]):courses[] => { | ||
return template.reduce((filtered_courses: courses[], course: string) => { | ||
const course_details = get_course_details(course); | ||
if (course_details !== undefined) { | ||
filtered_courses.push(course_details as courses); | ||
} | ||
return filtered_courses; | ||
}, []) | ||
} | ||
// handler function called on change of branch dropdown | ||
export const handleChangeBranch = ( | ||
{ | ||
event, | ||
allSemTemplates, | ||
sem, | ||
deptToChooseCourseFrom, | ||
setAllSemTemplates, | ||
setTemplate, | ||
setTemplateRows, | ||
setBranch, | ||
setTotalCredits, | ||
setAllAvailableCourses | ||
} : { | ||
event: SelectChangeEvent, | ||
allSemTemplates: semTemplate, | ||
sem: string, | ||
deptToChooseCourseFrom: string, | ||
setAllSemTemplates: Dispatch<SetStateAction<semTemplate>>, | ||
setTemplate: Dispatch<SetStateAction<string[]>>, | ||
setTemplateRows: Dispatch<SetStateAction<courses[]>>, | ||
setBranch: Dispatch<SetStateAction<string>>, | ||
setTotalCredits: Dispatch<SetStateAction<number>>, | ||
setAllAvailableCourses: Dispatch<SetStateAction<courses[]>> | ||
}) => { | ||
let allSemTemplatesCopy: semTemplate = allSemTemplates; | ||
setBranch(event.target.value as string); | ||
|
||
//iterate through all templates and find the branch template | ||
for (const key in allTemplates) { | ||
if (key === event.target.value) { | ||
setAllSemTemplates(allTemplates[key as keyof typeof allTemplates]); | ||
allSemTemplatesCopy = allTemplates[key as keyof typeof allTemplates]; | ||
} | ||
} | ||
|
||
//if sem is not empty, set template and template rows | ||
if (sem !== "") { | ||
for (const key in allSemTemplatesCopy) { | ||
if (key === sem) { | ||
const newTemplate = allSemTemplatesCopy[key as keyof typeof allSemTemplatesCopy]; | ||
setTemplateWithoutLastChars(newTemplate,setTemplate); | ||
const tempObject: courses[] = getTemplateRows(newTemplate); | ||
setTemplateRows(tempObject); | ||
let credits = 0; | ||
tempObject.forEach((course) => { | ||
credits += getCredits(course.credits); | ||
}) | ||
setTotalCredits(credits); | ||
if (deptToChooseCourseFrom === "") { | ||
const elegible_courses = get_all_dept_eligible_courses(newTemplate); | ||
setAllAvailableCourses(elegible_courses); | ||
} | ||
else if (deptToChooseCourseFrom !== "") { | ||
const elegible_courses = get_eligible_courses(newTemplate, deptToChooseCourseFrom); | ||
setAllAvailableCourses(elegible_courses); | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
export const handleChangeSem = ( | ||
{ | ||
event, | ||
allSemTemplates, | ||
deptToChooseCourseFrom, | ||
setSem, | ||
setTemplate, | ||
setTemplateRows, | ||
setTotalCredits, | ||
setAllAvailableCourses | ||
}:{ | ||
event: SelectChangeEvent, | ||
allSemTemplates: semTemplate, | ||
deptToChooseCourseFrom: string, | ||
setSem: Dispatch<SetStateAction<string>>, | ||
setTemplate: Dispatch<SetStateAction<string[]>>, | ||
setTemplateRows: Dispatch<SetStateAction<courses[]>>, | ||
setTotalCredits: Dispatch<SetStateAction<number>>, | ||
setAllAvailableCourses: Dispatch<SetStateAction<courses[]>> | ||
}) => { | ||
setSem(event.target.value as string); | ||
for (const key in allSemTemplates) { | ||
if (key === event.target.value) { | ||
const newTemplate = allSemTemplates[key as keyof typeof allSemTemplates]; | ||
setTemplateWithoutLastChars(newTemplate,setTemplate); | ||
const tempObject: courses[] = getTemplateRows(allSemTemplates[key as keyof typeof allSemTemplates]); | ||
setTemplateRows(tempObject); | ||
let credits = 0; | ||
tempObject.forEach((course) => { | ||
credits += getCredits(course.credits); | ||
}) | ||
setTotalCredits(credits); | ||
if (deptToChooseCourseFrom === "") { | ||
const elegible_courses = get_all_dept_eligible_courses(newTemplate); | ||
setAllAvailableCourses(elegible_courses); | ||
} | ||
if (deptToChooseCourseFrom !== "") { | ||
const elegible_courses = get_eligible_courses(newTemplate, deptToChooseCourseFrom); | ||
setAllAvailableCourses(elegible_courses); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
export const handleChangeDepttoChooseFrom = ( | ||
{ | ||
event, | ||
template, | ||
setDeptToChooseCourseFrom, | ||
setAllAvailableCourses, | ||
}:{ | ||
event: SelectChangeEvent, | ||
template: string[], | ||
setDeptToChooseCourseFrom: Dispatch<SetStateAction<string>>, | ||
setAllAvailableCourses: Dispatch<SetStateAction<courses[]>> | ||
}) => { | ||
setDeptToChooseCourseFrom(event.target.value as string); | ||
if (event.target.value === "") { | ||
const elegible_courses = get_all_dept_eligible_courses(template); | ||
setAllAvailableCourses(elegible_courses); | ||
} | ||
else { | ||
const elegible_courses = get_eligible_courses(template, event.target.value); | ||
setAllAvailableCourses(elegible_courses); | ||
} | ||
} | ||
|
||
export const handleCourseDrop = ( | ||
{ | ||
dropCourse, | ||
template, | ||
deptToChooseCourseFrom, | ||
setAllAvailableCourses, | ||
setTemplate, | ||
setTemplateRows, | ||
setTotalCredits, | ||
}:{ | ||
dropCourse: string, | ||
template: string[], | ||
deptToChooseCourseFrom: string, | ||
setAllAvailableCourses: Dispatch<SetStateAction<courses[]>>, | ||
setTemplate: Dispatch<SetStateAction<string[]>>, | ||
setTemplateRows: Dispatch<SetStateAction<courses[]>>, | ||
setTotalCredits: Dispatch<SetStateAction<number>> | ||
}) => { | ||
setAllAvailableCourses([]); | ||
const templateFiltered = template.filter((value) => (removeLastChars(value) !== removeLastChars(dropCourse))); | ||
setTemplateWithoutLastChars(templateFiltered,setTemplate); | ||
const tempObject: courses[] = getTemplateRows(templateFiltered); | ||
setTemplateRows(tempObject); | ||
let credits = 0; | ||
tempObject.forEach((course) => { | ||
credits += getCredits(course.credits); | ||
}) | ||
setTotalCredits(credits); | ||
if (deptToChooseCourseFrom === "") { | ||
const elegible_courses = get_all_dept_eligible_courses(templateFiltered); | ||
setAllAvailableCourses(elegible_courses); | ||
} | ||
else { | ||
const elegible_courses = get_eligible_courses(templateFiltered, deptToChooseCourseFrom); | ||
setAllAvailableCourses(elegible_courses); | ||
} | ||
} | ||
|
||
export const handleCourseAdd = ( | ||
{ | ||
addCourse, | ||
template, | ||
deptToChooseCourseFrom, | ||
setTemplate, | ||
setTemplateRows, | ||
setTotalCredits, | ||
setAllAvailableCourses, | ||
}:{ | ||
template: string[], | ||
addCourse: string, | ||
deptToChooseCourseFrom: string, | ||
setTemplate: Dispatch<SetStateAction<string[]>>, | ||
setTemplateRows: Dispatch<SetStateAction<courses[]>>, | ||
setTotalCredits: Dispatch<SetStateAction<number>>, | ||
setAllAvailableCourses: Dispatch<SetStateAction<courses[]>>, | ||
}) => { | ||
const newTemplate: string[] = template.concat([addCourse]); | ||
const tempObject: courses[] = getTemplateRows(newTemplate); | ||
setTemplateWithoutLastChars(newTemplate,setTemplate); | ||
setTemplateRows(tempObject); | ||
let credits = 0; | ||
tempObject.forEach((course) => { | ||
credits += getCredits(course.credits); | ||
}) | ||
setTotalCredits(credits); | ||
if (deptToChooseCourseFrom === "") { | ||
const elegible_courses = get_all_dept_eligible_courses(newTemplate); | ||
setAllAvailableCourses(elegible_courses); | ||
} | ||
else { | ||
const elegible_courses = get_eligible_courses(newTemplate, deptToChooseCourseFrom); | ||
setAllAvailableCourses(elegible_courses); | ||
} | ||
} | ||
|
||
export const handleCustomTemplate = ( | ||
{ | ||
setBranch, | ||
setSem, | ||
setTemplate, | ||
setTemplateRows, | ||
setTotalCredits, | ||
setAllAvailableCourses, | ||
}:{ | ||
setBranch: Dispatch<React.SetStateAction<string>>, | ||
setSem: Dispatch<React.SetStateAction<string>>, | ||
setTemplate: Dispatch<SetStateAction<string[]>>, | ||
setTemplateRows: Dispatch<SetStateAction<courses[]>>, | ||
setTotalCredits: Dispatch<SetStateAction<number>>, | ||
setAllAvailableCourses: Dispatch<SetStateAction<courses[]>> | ||
}) => { | ||
setTemplate([]); | ||
setTemplateRows([] as courses[]); | ||
setTotalCredits(0); | ||
setBranch("") | ||
setSem("") | ||
const elegible_courses = get_all_dept_eligible_courses([]); | ||
setAllAvailableCourses(elegible_courses); | ||
} |
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,79 @@ | ||
import { Button, InputLabel, MenuItem, Select, Stack, Typography } from "@mui/material" | ||
import { semesters, allDepts, allBranches } from "@components/constants" | ||
import { handleChangeBranch, handleChangeSem, handleChangeDepttoChooseFrom, handleCustomTemplate } from "./handlers" | ||
import React from "react"; | ||
import GlobalContext from "./globalContext"; | ||
import { courses, globalContextType } from "./types"; | ||
|
||
export default function Options() { | ||
const { branch,sem,deptToChooseCourseFrom,template,templateRows,allAvailableCourses,totalCredits,allSemTemplates,setBranch,setSem,setDeptToChooseCourseFrom,setTemplate,setTemplateRows,setAllAvailableCourses,setTotalCredits,setAllSemTemplates } = React.useContext(GlobalContext) as globalContextType; | ||
return ( | ||
<Stack | ||
direction={{ xs: 'column', sm: 'row' }} | ||
spacing={{ xs: 1, sm: 2, md: 4 }} | ||
justifyContent = "space-between" | ||
padding={4} | ||
> | ||
<Stack spacing={1}> | ||
<Stack direction={{xs: 'column', sm: 'row'}} spacing={2}> | ||
<Stack> | ||
<InputLabel id="branch-select">Select Branch</InputLabel> | ||
<Select | ||
labelId = "branch-select" | ||
id="branch-select" | ||
value={branch} | ||
label="Select Branch" | ||
onChange={(event) => { | ||
if(event.target.value.length==0)return | ||
return handleChangeBranch({ event, allSemTemplates, sem, deptToChooseCourseFrom, setAllSemTemplates, setTemplate, setTemplateRows, setBranch, setTotalCredits, setAllAvailableCourses }); | ||
}} | ||
> | ||
{ | ||
(allBranches.map((branch,index) => { | ||
return (<MenuItem key={index} value={branch}>{branch}</MenuItem>) | ||
})) | ||
} | ||
<MenuItem value="" onClick={() => {handleCustomTemplate({setBranch,setSem,setTemplate,setTemplateRows,setTotalCredits,setAllAvailableCourses});}}>others</MenuItem> | ||
</Select> | ||
</Stack> | ||
<Stack> | ||
<InputLabel id="sem-select">Select Semester</InputLabel> | ||
<Select | ||
labelId = "sem-select" | ||
id="sem-select" | ||
value={sem} | ||
label="Select Semester" | ||
onChange={(event) => handleChangeSem({event, allSemTemplates, deptToChooseCourseFrom, setTemplate, setTemplateRows, setSem, setTotalCredits, setAllAvailableCourses})} | ||
> | ||
{ | ||
(branch!=="" && (semesters.map((sem,index) => { | ||
return (<MenuItem key={index} value={sem}>{sem}</MenuItem>) | ||
}))) | ||
} | ||
</Select> | ||
</Stack> | ||
</Stack> | ||
<Typography><b>Total Credits = {totalCredits}</b></Typography> | ||
</Stack> | ||
<Stack direction={{xs: 'column', sm: 'row'}} spacing={2} alignItems="center"> | ||
<Stack> | ||
<InputLabel id="dept-select ">Dept to choose courses from</InputLabel> | ||
<Select | ||
labelId = "dept-select" | ||
id="dept-select" | ||
value={deptToChooseCourseFrom} | ||
label="Select Branch" | ||
onChange={(event) => handleChangeDepttoChooseFrom({event, template, setDeptToChooseCourseFrom, setAllAvailableCourses})} | ||
> | ||
<MenuItem key={0} value="">All Departments</MenuItem> | ||
{ | ||
(allDepts.map((dept,index) => { | ||
return (<MenuItem key={index} value={dept}>{dept}</MenuItem>) | ||
})) | ||
} | ||
</Select> | ||
</Stack> | ||
</Stack> | ||
</Stack> | ||
) | ||
} |
Oops, something went wrong.