Skip to content

Commit

Permalink
feat: Data for calculating the grade
Browse files Browse the repository at this point in the history
  • Loading branch information
NyctibiusVII committed May 24, 2023
1 parent 641dbb1 commit 5c1551f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 28 deletions.
27 changes: 5 additions & 22 deletions src/components/sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const Sidebar = () => {

const {
schoolReport,
setSchoolReport,
updateTotalClasses,
addSubjects,
removeSubjects
} = useSchoolReport()
Expand Down Expand Up @@ -117,45 +117,39 @@ export const Sidebar = () => {
label='Nota de aprovação:'
withForm={false}
type='number'
className={`w-[2.6rem] inputNumberValues cursor-not-allowed`}
className={`w-[2.6rem] inputNumberValues`}
onChange={event => setMinimumPassingGrade(Number(event.target.value))}
value={minimumPassingGrade}
step='1'
min='1'
max='10'
container
readOnly
disabled
/>
<Input
name='insufficientGrade'
label='Nota de recuperação:'
withForm={false}
type='number'
className={`w-[2.6rem] inputNumberValues cursor-not-allowed`}
className={`w-[2.6rem] inputNumberValues`}
onChange={event => setMinimumRecoveryGrade(Number(event.target.value))}
value={minimumRecoveryGrade}
step='1'
min='1'
max='10'
container
readOnly
disabled
/>
<Input
name='frequencyPercentage'
label='Porcentagem minima de frequência para aprovação:'
withForm={false}
type='number'
className={`w-[2.6rem] inputNumberValues cursor-not-allowed`}
className={`w-[2.9rem] inputNumberValues`}
onChange={event => setMinimumAttendancePercentageToPass(Number(event.target.value))}
value={minimumAttendancePercentageToPass}
step='1'
min='1'
max='100'
container
readOnly
disabled
/>

<Details summary='Habilitar / Desabilitar'>
Expand Down Expand Up @@ -320,18 +314,7 @@ export const Sidebar = () => {
withForm={false}
type='number'
className={`w-12 inputNumberValues`}
onChange={event => {
setSchoolReport({
...schoolReport,
studentAcademicRecord: {
...schoolReport.studentAcademicRecord,
[subjects[activeSubjectIndex]]: {
...schoolReport.studentAcademicRecord[subjects[activeSubjectIndex]],
totalClasses: Number(event.target.value)
}
}
})
}}
onChange={event => updateTotalClasses(Number(event.target.value), subjects[activeSubjectIndex])}
value={schoolReport.studentAcademicRecord[subjects[activeSubjectIndex]].totalClasses}
step='1'
min='1'
Expand Down
6 changes: 6 additions & 0 deletions src/contexts/SchoolReportConfigContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export interface SchoolReportConfigContextData {
setSchoolReportColors (value: SchoolReportColors): void
maintainReportCardData: MaintainReportCardData
setMaintainReportCardData (value: MaintainReportCardData): void
updateTotalClassesRecalculatedComponents: number
setUpdateTotalClassesRecalculatedComponents (value: number): void
minimumAttendancePercentageToPass: number
minimumPassingGrade: number
minimumRecoveryGrade: number
Expand All @@ -46,6 +48,8 @@ interface SchoolReportConfigProviderProps { children: ReactNode }
export const SchoolReportConfigContext = createContext({} as SchoolReportConfigContextData)

export function SchoolReportConfigProvider({ children }: SchoolReportConfigProviderProps) {
const [updateTotalClassesRecalculatedComponents, setUpdateTotalClassesRecalculatedComponents] = useState(0)

const [minimumAttendancePercentageToPass, setMinimumAttendancePercentageToPass] = useState(25)
const [minimumPassingGrade, setMinimumPassingGrade] = useState(6)
const [minimumRecoveryGrade, setMinimumRecoveryGrade] = useState(4)
Expand Down Expand Up @@ -131,6 +135,8 @@ export function SchoolReportConfigProvider({ children }: SchoolReportConfigProvi
setSchoolReportColors,
maintainReportCardData,
setMaintainReportCardData,
updateTotalClassesRecalculatedComponents,
setUpdateTotalClassesRecalculatedComponents,
minimumAttendancePercentageToPass,
minimumPassingGrade,
minimumRecoveryGrade,
Expand Down
33 changes: 27 additions & 6 deletions src/contexts/SchoolReportContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface SchoolReportContextData {
bimester: keyof Bimester,
academicRecord: 'grades' | 'absences'
) => void
updateTotalClasses: (value: number, subject: Matter) => void
newAcademicRecord: AcademicRecord
addSubjects: (subject: string, custom?: boolean) => void
removeSubjects: (subject: string) => void
Expand All @@ -51,6 +52,8 @@ export function SchoolReportProvider({ children }: SchoolReportProviderProps) {
setInactiveSubjects,
activeQuarter,
maintainReportCardData,
updateTotalClassesRecalculatedComponents,
setUpdateTotalClassesRecalculatedComponents,
minimumAttendancePercentageToPass,
minimumPassingGrade,
minimumRecoveryGrade
Expand Down Expand Up @@ -101,11 +104,13 @@ export function SchoolReportProvider({ children }: SchoolReportProviderProps) {
}

setSubjects([...subjects, subject])
setSchoolReport({
...schoolReport,
studentAcademicRecord: {
...schoolReport.studentAcademicRecord,
[subject]: newAcademicRecord
setSchoolReport(prevState => {
return {
...prevState,
studentAcademicRecord: {
...prevState.studentAcademicRecord,
[subject]: newAcademicRecord
}
}
})
setInactiveSubjects(inactiveSubjects.filter(item => item !== subject))
Expand Down Expand Up @@ -197,6 +202,21 @@ export function SchoolReportProvider({ children }: SchoolReportProviderProps) {
}
})
}
const updateTotalClasses = (value: number, subject: Matter) => {
setSchoolReport(prevState => {
return {
...prevState,
studentAcademicRecord: {
...prevState.studentAcademicRecord,
[subject]: {
...prevState.studentAcademicRecord[subject],
totalClasses: value
}
}
}
})
setUpdateTotalClassesRecalculatedComponents(updateTotalClassesRecalculatedComponents + 1)
}

useEffect(() => {
const recalculatingComponentWithOwnValues = () => {
Expand Down Expand Up @@ -241,7 +261,7 @@ export function SchoolReportProvider({ children }: SchoolReportProviderProps) {

recalculatingComponentWithOwnValues()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [activeQuarter, subjects])
}, [activeQuarter, subjects, minimumPassingGrade, minimumRecoveryGrade, minimumAttendancePercentageToPass, updateTotalClassesRecalculatedComponents])

useEffect(() => {
const { school, teacher, name, number, yearAndClass } = maintainReportCardData
Expand All @@ -263,6 +283,7 @@ export function SchoolReportProvider({ children }: SchoolReportProviderProps) {
setSchoolReport,
schoolReportStartup,
updateStudentAcademicRecord,
updateTotalClasses,
newAcademicRecord,
addSubjects,
removeSubjects
Expand Down

1 comment on commit 5c1551f

@vercel
Copy link

@vercel vercel bot commented on 5c1551f May 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.