Skip to content

Commit dd2ece4

Browse files
committed
feat: button back to session history from student history
1 parent 950edab commit dd2ece4

7 files changed

Lines changed: 106 additions & 55 deletions

File tree

client/src/App.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import Register from './Components/Startpage/Welcome/Register';
1010
import Welcome from './Components/Startpage/Welcome/Welcome';
1111
import ClassView from './Components/ClassView/ClassView';
1212
import StudentDashboard from './Components/StudentView/StudentDashboard';
13-
import AddForm from './Components/TeacherDashboard/AddForm';
1413
import QrView from './Components/QrView/QrView';
1514
import Overview from './Components/Calendar/Overview';
1615
import SessionHistory from './Components/Calendar/SessionHistory';

client/src/Components/Calendar/SessionHistory.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
import React from 'react';
2+
import { useDispatch } from 'react-redux';
3+
import { setSessionId } from '../../store/actions';
24
import { useParams } from 'react-router';
3-
import { Link } from 'react-router-dom';
5+
import { useNavigate } from 'react-router-dom';
46
import StudentsList from '../ClassView/StudentsList';
57

6-
// const listStyle = 'flex flex-col justify-start items-start';
7-
8-
const btnStyle = "flex bg-green text-white p-4 shadow-lg m-auto my-8";
8+
const btnStyle = 'flex bg-green text-white p-4 shadow-lg m-auto my-8';
99

1010
const SessionHistory: React.FC = () => {
1111
const courseId = Number(useParams().courseId);
12+
const dispatch = useDispatch();
13+
const navigate = useNavigate();
14+
15+
dispatch(setSessionId(null));
16+
17+
function handleClick() {
18+
navigate(`/homepage/classes/${courseId}/history`);
19+
}
1220

1321
return (
1422
<div>
15-
{/* button back to overview */}
16-
<footer className="flex justify-center my-4">
17-
</footer>
18-
{/* student list for this session */}
23+
<footer className="flex justify-center my-4"></footer>
1924
<StudentsList courseId={courseId} />
20-
{/* TODO: each student is clickable to get individual attendance */}
21-
<Link to={`/homepage/classes/${courseId}/history`}>
22-
<button className={btnStyle}>Back to history overview</button>
23-
</Link>
25+
<button className={btnStyle} onClick={handleClick}>
26+
Back to history overview
27+
</button>
2428
</div>
2529
);
2630
};
Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
11
import React from 'react';
22
import { useIndividualAttendanceQuery } from '../../generated/graphql';
33
import { useParams } from 'react-router';
4+
import { useNavigate } from 'react-router-dom';
5+
import { useSelector, useDispatch } from 'react-redux';
46
import { ReactComponent as CheckBoxChecked } from '../../Assets/chekcbox-checked.svg';
57
import { ReactComponent as CheckBoxCrossed } from '../../Assets/chekcbox-cross.svg';
68
import moment from 'moment';
9+
import Student from '../../Types/student';
10+
11+
const btnStyle = 'flex bg-green text-white p-4 shadow-lg m-auto my-8';
712

813
const StudentHistory: React.FC = () => {
14+
const navigate = useNavigate();
915
const courseId = Number(useParams().courseId);
1016
const studentId = Number(useParams().studentId);
11-
const name = 'Friend';
12-
const lastname = 'buddy';
17+
const studentState = useSelector(
18+
(state: { student: Student | null }) => state.student
19+
);
20+
const sessionId = useSelector(
21+
(state: { sessionId: number | null }) => state.sessionId
22+
);
23+
let name;
24+
let lastname;
25+
26+
if (studentState) {
27+
name = studentState.name;
28+
lastname = studentState.lastname;
29+
}
1330

1431
const [{ fetching, data, error }] = useIndividualAttendanceQuery({
1532
variables: { courseId, studentId },
@@ -20,12 +37,22 @@ const StudentHistory: React.FC = () => {
2037
if (error) {
2138
} // TODO handle error
2239

40+
function handleClick() {
41+
console.log('click back from studenthistory', { sessionId });
42+
navigate(`/homepage/classes/${courseId}/${sessionId}`);
43+
}
44+
2345
const indivHistory = data?.getIndividualAttendance?.data; // returns {attended, date}
2446

2547
if (indivHistory) {
2648
return (
2749
<div>
28-
<h1 className="flex justify-center text-lg md:text-xl">{name} {lastname}</h1>
50+
<h1 className="flex justify-center text-lg md:text-xl">
51+
{name} {lastname}
52+
</h1>
53+
<button className={btnStyle} onClick={handleClick}>
54+
Back to session overview
55+
</button>
2956
<section className="flex justify-center h-1/4 md:h-1/2 lg:h-5/6 xl:h-screen p-4">
3057
<div className=" flex flex-row flex-wrap justify-start bg-white w-11/12 md:h-2/3 lx:w-9/12 overflow-scroll border-green border-8">
3158
{indivHistory.map((session) => {
@@ -52,34 +79,3 @@ const StudentHistory: React.FC = () => {
5279
};
5380

5481
export default StudentHistory;
55-
56-
// return (
57-
// <div>
58-
// {!!studentsAttended &&
59-
// studentList?.map((student) => {
60-
// if (
61-
// studentsAttended.some(
62-
// (attendee) => attendee?.email === student?.email
63-
// )
64-
// ) {
65-
// return <CheckBoxChecked className="w-10 h-10" />;
66-
// }
67-
// return <CheckBoxCrossed className="w-10 h-10" />;
68-
// })}
69-
// </div>
70-
// );
71-
72-
// if (session) {
73-
// const date = new Date(Number(session.createdAt));
74-
// const UTCdate = date.toUTCString();
75-
// return (
76-
// <div className="w-26 p-2 md:w-32 text-center border-2 border-black m-1 hover:bg-green-xlight">
77-
// <Link to={`/homepage/classes/${courseId}/${session.id}`}>
78-
// <div>
79-
// <h5 className="text-lg sm:text-xl">{session.attendance}</h5>
80-
// <p className="text-sm sm:text-md">{moment(UTCdate).format('L')}</p>
81-
// </div>
82-
// </Link>
83-
// </div>
84-
// );
85-
// }

client/src/Components/ClassView/StudentElementHistory.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import React from 'react';
2+
import { useDispatch } from 'react-redux';
3+
import { setSessionId, setStudent } from '../../store/actions';
24
import { useNavigate } from 'react-router';
5+
import { useParams } from 'react-router-dom';
36

47
interface Props {
58
courseId: number;
@@ -14,16 +17,23 @@ const StudentElementHistory: React.FC<Props> = ({
1417
courseId,
1518
studentId,
1619
}) => {
20+
const dispatch = useDispatch();
1721
const navigate = useNavigate();
1822

23+
const sessionId: number = Number(useParams().sessionId);
24+
25+
function handleClick() {
26+
dispatch(setStudent({ name, lastname, studentId }));
27+
dispatch(setSessionId(sessionId));
28+
29+
navigate(`/homepage/classes/${courseId}/student/${studentId}`);
30+
}
31+
1932
return (
20-
<button
21-
className="flex place-items-center h-10"
22-
onClick={() =>
23-
navigate(`/homepage/classes/${courseId}/student/${studentId}`)
24-
}
25-
>
26-
<h3 className="mx-4">{lastname} {name}</h3>
33+
<button className="flex place-items-center h-10" onClick={handleClick}>
34+
<h3 className="mx-4">
35+
{lastname} {name}
36+
</h3>
2737
</button>
2838
);
2939
};

client/src/Types/student.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export default interface Student {
22
name: string;
33
lastname: string;
4-
email: string;
4+
studentId: number;
55
}

client/src/store/actions.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import User from '../Types/user';
22
import Course from '../Types/course';
33
import Session from '../Types/session';
4+
import Student from '../Types/student';
45

56
export const setUser = (user: User) => ({
67
type: 'SET_USER',
78
user,
89
});
910

11+
export const setStudent = (student: Student | null) => ({
12+
type: 'SET_STUDENT',
13+
student,
14+
});
15+
1016
export const setCourses = (courses: Course[]) => ({
1117
type: 'SET_COURSES',
1218
courses,
@@ -22,6 +28,11 @@ export const setSession = (session: Session | null) => ({
2228
session,
2329
});
2430

31+
export const setSessionId = (sessionId: number | null) => ({
32+
type: 'SET_SESSION_ID',
33+
sessionId,
34+
});
35+
2536
export const setHistory = (showing: boolean) => ({
2637
type: 'SET_HISTORY',
2738
showing,

client/src/store/reducers.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { combineReducers } from 'redux';
22
import User from '../Types/user';
33
import Course from '../Types/course';
44
import Session from '../Types/session';
5+
import Student from '../Types/student';
56

67
type UserReducer = (
78
state: User | null,
@@ -17,6 +18,20 @@ const user: UserReducer = (state = null, action) => {
1718
}
1819
};
1920

21+
type StudentReducer = (
22+
state: Student | null,
23+
action: { type: string; student: Student }
24+
) => Student | null;
25+
26+
const student: StudentReducer = (state = null, action) => {
27+
switch (action.type) {
28+
case 'SET_STUDENT':
29+
return action.student;
30+
default:
31+
return state;
32+
}
33+
};
34+
2035
type CoursesReducer = (
2136
state: Course[] | null,
2237
action: { type: string; courses: Course[] }
@@ -59,6 +74,20 @@ const session: SessionReducer = (state = null, action) => {
5974
}
6075
};
6176

77+
type SessionIdReducer = (
78+
state: number | null,
79+
action: { type: string; sessionId: number }
80+
) => number | null;
81+
82+
const sessionId: SessionIdReducer = (state = null, action) => {
83+
switch (action.type) {
84+
case 'SET_SESSION_ID':
85+
return action.sessionId;
86+
default:
87+
return state;
88+
}
89+
};
90+
6291
type historyReducer = (
6392
state: boolean,
6493
action: { type: string; showing: boolean }
@@ -89,9 +118,11 @@ const currentList: currentListReducer = (state = null, action) => {
89118

90119
const reducers = combineReducers({
91120
user,
121+
student,
92122
courses,
93123
selectedCourse,
94124
session,
125+
sessionId,
95126
history,
96127
currentList,
97128
});

0 commit comments

Comments
 (0)