Skip to content

Commit

Permalink
Change Studentoverview to show current schein status (again).
Browse files Browse the repository at this point in the history
  • Loading branch information
Dudrie committed Feb 11, 2020
1 parent 50da233 commit 4152dec
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { createStyles, makeStyles, Theme } from '@material-ui/core/styles';
import { AccountSearch as SearchIcon } from 'mdi-material-ui';
import { useSnackbar } from 'notistack';
import React, { ChangeEvent, useState } from 'react';
import { ScheinCriteriaSummary } from 'shared/dist/model/ScheinCriteria';
import { Student } from 'shared/dist/model/Student';
import { Tutorial } from 'shared/dist/model/Tutorial';
import { getNameOfEntity } from 'shared/dist/util/helpers';
Expand Down Expand Up @@ -44,8 +43,6 @@ const useStyles = makeStyles((theme: Theme) =>
})
);

type SummariesByStudent = { [studentId: string]: ScheinCriteriaSummary };

interface Props {
tutorials?: Tutorial[];
allowChangeTutorial?: boolean;
Expand All @@ -63,7 +60,7 @@ function Studentoverview({
const [sortOption, setSortOption] = useState<StudentSortOption>(StudentSortOption.ALPHABETICAL);

const dialog = useDialog();
const [{ students, teams, tutorialId, isInitialized }, dispatch] = useStudentStore();
const [{ students, teams, tutorialId, isInitialized, summaries }, dispatch] = useStudentStore();
const { enqueueSnackbar } = useSnackbar();

const handlerParams: HandlerParams = { tutorialId, dispatch, enqueueSnackbar };
Expand Down Expand Up @@ -187,6 +184,7 @@ function Studentoverview({
<StudentRow
className={classes.studentRow}
student={student}
scheinStatus={summaries[student.id]}
onEdit={openEditDialog}
onDelete={openDeleteDialog}
onChangeTutorial={allowChangeTutorial ? openChangeTutorialDialog : undefined}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import {
} from 'mdi-material-ui';
import React from 'react';
import { Link } from 'react-router-dom';
import { ScheinCriteriaSummary } from 'shared/dist/model/ScheinCriteria';
import { Student, TeamInStudent } from 'shared/dist/model/Student';
import { getNameOfEntity } from 'shared/dist/util/helpers';
import EntityListItemMenu from '../../../../components/list-item-menu/EntityListItemMenu';
import { ListItem } from '../../../../components/list-item-menu/ListItemMenu';
import PaperTableRow, { PaperTableRowProps } from '../../../../components/PaperTableRow';
import StudentAvatar from '../../../../components/student-icon/StudentAvatar';
import { getStudentInfoPath } from '../../../../routes/Routing.helpers';
import ScheinStatusBox from '../../student-info/components/ScheinStatusBox';
import { useStudentStore } from '../../student-store/StudentStore';

const useStyles = makeStyles(theme =>
Expand All @@ -39,6 +41,7 @@ interface Props extends PaperTableRowProps {
onDelete: StudentCallback;
onChangeTutorial?: StudentCallback;
subtextPrefix?: string;
scheinStatus?: ScheinCriteriaSummary;
}

interface GetSubtextParams {
Expand All @@ -63,6 +66,7 @@ function StudentRow({
onEdit,
onDelete,
onChangeTutorial,
scheinStatus,
...props
}: Props): JSX.Element {
const classes = useStyles();
Expand Down Expand Up @@ -102,6 +106,10 @@ function StudentRow({
/>
}
>
<TableCell align='right' className={classes.infoButton}>
<ScheinStatusBox scheinStatus={scheinStatus} />
</TableCell>

<TableCell align='right' className={classes.infoButton}>
<Button
variant='outlined'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import {
deleteStudent,
editStudent,
getAllStudents,
getScheinCriteriaSummaryOfAllStudents,
} from '../../../hooks/fetching/Student';
import { createTeam, getTeamsOfTutorial } from '../../../hooks/fetching/Team';
import { getStudentsOfTutorial } from '../../../hooks/fetching/Tutorial';
import {
getStudentsOfTutorial,
getScheinCriteriaSummariesOfAllStudentsOfTutorial,
} from '../../../hooks/fetching/Tutorial';
import { AsyncDispatch } from '../../../util/AsyncReducer';
import { StudentStore } from './StudentStore';
import {
Expand Down Expand Up @@ -109,20 +113,31 @@ async function reduceReinitializeStore(
}

if (!!tutorialId) {
const [students, teams] = await Promise.all([
const [students, teams, summaries] = await Promise.all([
getStudentsOfTutorial(tutorialId),
getTeamsOfTutorial(tutorialId),
getScheinCriteriaSummariesOfAllStudentsOfTutorial(tutorialId),
]);

students.sort(sortByName);

return { ...state, students, teams, isInitialized: true, tutorialId };
return { ...state, students, teams, isInitialized: true, tutorialId, summaries };
} else {
const students = await getAllStudents();
const [students, summaries] = await Promise.all([
getAllStudents(),
getScheinCriteriaSummaryOfAllStudents(),
]);

students.sort(sortByName);

return { ...state, students, teams: undefined, tutorialId: undefined, isInitialized: true };
return {
...state,
students,
teams: undefined,
tutorialId: undefined,
isInitialized: true,
summaries,
};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { useAsyncReducer, AsyncDispatch } from '../../../util/AsyncReducer';
import { StudentStoreAction, StudentStoreActionType } from './StudentStore.actions';
import { Team } from 'shared/dist/model/Team';
import studentStoreReducer from './StudentStore.reducers';
import { ScheincriteriaSummaryByStudents } from 'shared/dist/model/ScheinCriteria';

export interface StudentStore {
students: Student[];
teams?: Team[];
tutorialId?: string;
isInitialized: boolean;
summaries: ScheincriteriaSummaryByStudents;
}

interface StudentContext {
Expand All @@ -22,6 +24,7 @@ const initialState: StudentStore = {
teams: undefined,
tutorialId: 'NOT_INITIALIZED',
isInitialized: false,
summaries: {},
};

const StudentStoreContext = createContext<StudentContext>({
Expand Down

0 comments on commit 4152dec

Please sign in to comment.