topbar changes:

This commit is contained in:
Maciek Głowacki
2020-12-16 00:23:31 +01:00
parent 39a7e109c8
commit 8f85d605e1
4 changed files with 31 additions and 14 deletions

View File

@ -5,6 +5,8 @@ import { CASContext } from './CASProvider';
interface StudentContext {
students: Array<Student>;
selectedStudent: Student | null;
changeSelectedStudent: (studentId: number) => void;
}
export const studentsContext = createContext<StudentContext | undefined>(undefined);
@ -15,6 +17,7 @@ interface StudentsProviderProps {
export const StudentsProvider = ({ children }: StudentsProviderProps) => {
const [students, setStudents] = useState<Array<Student>>([]);
const [selectedStudent, setSelectedStudent] = useState<Student | null>(null);
//not working currently
const userPrivilige = localStorage.getItem('userPrivilige');
@ -32,6 +35,10 @@ export const StudentsProvider = ({ children }: StudentsProviderProps) => {
}
};
const changeSelectedStudent = (studentId: number) => {
setSelectedStudent(students.find((student) => student.id === studentId)!);
};
useEffect(() => {
setTimeout(() => {
// user?.authorityRole === 'DEANERY' &&
@ -42,7 +49,9 @@ export const StudentsProvider = ({ children }: StudentsProviderProps) => {
return (
<studentsContext.Provider
value={{
selectedStudent,
students,
changeSelectedStudent,
}}
>
{children}