Skip to content

Commit ce63541

Browse files
authored
Merge pull request #91 from usingbrain/nobrain
fix: add form
2 parents b6eda65 + 950edab commit ce63541

9 files changed

Lines changed: 70 additions & 84 deletions

File tree

client/src/App.tsx

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import Homepage from './Components/TeacherHomepage/Homepage';
88
import Login from './Components/Startpage/Welcome/Login';
99
import Register from './Components/Startpage/Welcome/Register';
1010
import Welcome from './Components/Startpage/Welcome/Welcome';
11-
import Instruction from './Components/TeacherHomepage/Instruction';
1211
import ClassView from './Components/ClassView/ClassView';
1312
import StudentDashboard from './Components/StudentView/StudentDashboard';
1413
import AddForm from './Components/TeacherDashboard/AddForm';
1514
import QrView from './Components/QrView/QrView';
1615
import Overview from './Components/Calendar/Overview';
1716
import SessionHistory from './Components/Calendar/SessionHistory';
1817
import StudentHistory from './Components/Calendar/StudentHistory';
18+
import MainTeacherView from './Components/TeacherHomepage/MainTeacherView';
1919

2020
const client = createClient({
2121
url: 'http://localhost:4000/graphql',
@@ -28,32 +28,27 @@ function App() {
2828
return (
2929
<Provider value={client}>
3030
<BrowserRouter>
31-
<div className='App'>
31+
<div className="App">
3232
<Routes>
3333
<Route exact path="/" element={<Welcome />} />
3434
<Route path="/homepage" element={<Homepage />}>
35-
<Route path="/homepage/new-course" element={<AddForm />}></Route>
36-
<Route path="/homepage/classes/:courseId" element={<ClassView />}>
35+
{/* <Route path="classes/new-course" element={<AddForm />}></Route> */}
36+
<Route path=":type" element={<MainTeacherView />}></Route>
37+
<Route path="classes/:courseId" element={<ClassView />}>
38+
<Route path="history" element={<Overview />}></Route>
39+
<Route path=":sessionId" element={<SessionHistory />}></Route>
3740
<Route
38-
path='/homepage/classes/:courseId/history'
39-
element={<Overview />}
40-
></Route>
41-
<Route
42-
path='/homepage/classes/:courseId/:sessionId'
43-
element={<SessionHistory />}
44-
></Route>
45-
<Route
46-
path='/homepage/classes/:courseId/student/:studentId'
41+
path="student/:studentId"
4742
element={<StudentHistory />}
4843
></Route>
4944
</Route>
5045
</Route>
5146
<Route>
52-
<Route path='/login' element={<Login />} />
53-
<Route path='/register' element={<Register />} />
47+
<Route path="/login" element={<Login />} />
48+
<Route path="/register" element={<Register />} />
5449
</Route>
55-
<Route path='/student' element={<StudentDashboard />}></Route>
56-
<Route path='/:type/:id' element={<QrView />}></Route>
50+
<Route path="/student" element={<StudentDashboard />}></Route>
51+
<Route path="/:type/:id" element={<QrView />}></Route>
5752
</Routes>
5853
</div>
5954
</BrowserRouter>

client/src/Components/ClassView/ClassView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const ClassView: React.FC = () => {
3333
return (
3434
<section className="h-screen flex flex-col justify-start w-3/4 h-full">
3535
<div className={headerStyle}>
36-
<h1 className="font-bold">{course.name?.toUpperCase()}</h1>
36+
<h1 className="font-bold">{course.name.toUpperCase()}</h1>
3737
<Link to="/homepage">
3838
<button onClick={() => dispatch(setSelected(null))}>
3939
<CloseBtn className="w-10 h-10" />

client/src/Components/QrView/QrView.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { useParams } from 'react-router-dom';
33
import QRCode from 'react-qr-code';
44

55
const QrView: React.FC = () => {
6-
const type = useParams().type;
7-
const id = useParams().id;
6+
const { id, type } = useParams();
87
let qrValue;
98

109
if (type && id) {

client/src/Components/TeacherDashboard/AddForm.tsx

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React, { useState, useEffect } from 'react';
2-
import { Link } from 'react-router-dom';
32
import { useNavigate } from 'react-router';
43
import { useSelector, useDispatch } from 'react-redux';
5-
import { setForm, setSelected } from '../../store/actions';
4+
import { setSelected } from '../../store/actions';
65
import { useCreateCourseMutation } from '../../generated/graphql';
76
import { ReactComponent as CloseBtn } from '../../Assets/window-close-regular.svg';
87
import Course from '../../Types/course';
@@ -14,7 +13,6 @@ const lottieStyle = 'invisible md:visible w-0 h-0 md:w-4/12 md:h-auto';
1413

1514
const AddForm: React.FC = () => {
1615
const [title, setTitle] = useState('');
17-
const open = useSelector((state: { form: boolean }) => state.form);
1816
const selected = useSelector(
1917
(state: { selectedCourse: Course | null }) => state.selectedCourse
2018
);
@@ -32,8 +30,8 @@ const AddForm: React.FC = () => {
3230

3331
useEffect(() => {
3432
// display new Course in ClassView
35-
if (selected && !open) navigate(`/homepage/classes/${selected.id}`);
36-
}, [selected, open, navigate]);
33+
if (selected) navigate(`/homepage/classes/${selected.id}`);
34+
}, [selected, navigate]);
3735

3836
async function addCourse(name: string) {
3937
const response = await createCourse({ name });
@@ -45,46 +43,47 @@ const AddForm: React.FC = () => {
4543

4644
function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
4745
e.preventDefault();
46+
console.log('handling form submit');
4847
if (title.length > 1) addCourse(title);
4948
else {
5049
// TODO: display error
5150
}
5251
setTitle('');
53-
dispatch(setForm(open));
5452
}
53+
54+
function handleClose() {
55+
console.log('handling close');
56+
dispatch(setSelected(null));
57+
navigate('/homepage');
58+
}
59+
5560
return (
56-
<div className='h-full w-1/2 flex justify-center flex-row border-4 mx-auto mt-16'>
61+
<div className="w-2/3 flex justify-center flex-row border-4 mx-auto mt-24">
5762
<section className={popUpStyle}>
58-
<section className='flex flex-row justify-between items-center bg-black p-8 h-20 mb-4 text-3xl'>
59-
<h1 className='font-bold md:text-3xl text-xl'>Add new class.</h1>
60-
<Link to='/homepage'>
61-
<button
62-
onClick={() => {
63-
dispatch(setForm(open));
64-
}}
65-
>
66-
<CloseBtn className='w-10 h-10' />
67-
</button>
68-
</Link>
63+
<section className="flex flex-row justify-between items-center bg-black p-8 h-20 mb-4 text-3xl">
64+
<h1 className="font-bold md:text-3xl text-xl">Add new class.</h1>
65+
<button onClick={handleClose}>
66+
<CloseBtn className="w-10 h-10" />
67+
</button>
6968
</section>
70-
<article className='flex flex-col md:h-3/4 w-full justify-center items-center p-0 h-0'>
69+
<article className="flex flex-col md:h-3/4 w-full justify-center items-center p-0 h-0">
7170
<div className={lottieStyle}>
7271
<Lottie options={defaultOptions} height={'100%'} width={'100%'} />
7372
</div>
7473
<form
7574
onSubmit={(e) => handleSubmit(e)}
76-
className='flex flex-row items-center w-7/12 border-4 border-green'
75+
className="flex flex-row items-center w-7/12 border-4 border-green"
7776
>
7877
<input
79-
className='h-14 w-full sm:w-full text-2xl text-black px-6 focus:outline-none'
80-
type='text'
78+
className="h-14 w-full sm:w-full text-2xl text-black px-6 focus:outline-none"
79+
type="text"
8180
value={title}
82-
placeholder='Input class title.'
81+
placeholder="Input class title."
8382
onChange={(e) => setTitle(e.target.value)}
8483
/>
8584
<button
86-
type='submit'
87-
className='bg-green text-white text-lg lg:text-2xl sm:text-xl w-5/12 lg:w-3/12 h-14'
85+
type="submit"
86+
className="bg-green text-white text-lg lg:text-2xl sm:text-xl w-5/12 lg:w-3/12 h-14"
8887
>
8988
Add
9089
</button>
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
import React from 'react';
2-
import { Link } from 'react-router-dom';
3-
import { useSelector, useDispatch } from 'react-redux';
4-
import { setForm } from '../../store/actions';
2+
import { useNavigate } from 'react-router-dom';
3+
import { useDispatch } from 'react-redux';
4+
import { setSelected } from '../../store/actions';
55
import CourseList from './CourseList';
66

7-
87
const sidemenuStyle =
98
'bg-green flex flex-col justify-start items-center w-1/4 h-screen shadow-2xl overflow-hidden overflow-scroll';
10-
const btnStyle = 'bg-white hover:bg-green-xlight p-3 rounded-sm my-4 w-3/5 text-center';
9+
const btnStyle =
10+
'bg-white hover:bg-green-xlight p-3 rounded-sm my-4 w-3/5 text-center';
1111
const btnTextStyle = 'text-green font-bold text-sm';
1212

1313
const Sidemenu: React.FC = () => {
14-
const open = useSelector((state: { form: boolean }) => state.form);
14+
const navigate = useNavigate();
1515
const dispatch = useDispatch();
1616

17+
function handleClick() {
18+
console.log('add button');
19+
dispatch(setSelected(null));
20+
navigate('/homepage/new-course');
21+
}
1722
return (
1823
<nav className={sidemenuStyle}>
1924
<div className={btnStyle}>
20-
<Link to="/homepage/new-course">
21-
<button
22-
onClick={() => dispatch(setForm(open))}
23-
className={btnTextStyle}
24-
>
25-
<p className="invisible sm:visible h-0 sm:h-full w-0 sm:w-full">ADD NEW CLASS</p>
26-
<p className="text-5xl visible sm:invisible h-full sm:h-0">+</p>
27-
</button>
28-
</Link>
25+
<button onClick={handleClick} className={btnTextStyle}>
26+
<p className="invisible sm:visible h-0 sm:h-full w-0 sm:w-full">
27+
ADD NEW CLASS
28+
</p>
29+
<p className="text-5xl visible sm:invisible h-full sm:h-0">+</p>
30+
</button>
2931
</div>
3032
<CourseList />
3133
</nav>
3234
);
3335
};
3436

3537
export default Sidemenu;
36-
37-
// bg-opacity-15

client/src/Components/TeacherHomepage/Homepage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { Outlet } from 'react-router-dom';
44
import Sidemenu from '../TeacherDashboard/Sidemenu';
55
import Navbar from './Navbar';
66
import Course from '../../Types/course';
7-
import Instruction from './Instruction';
87
import { useCoursesQuery } from '../../generated/graphql';
98
import { setCourses } from '../../store/actions';
9+
import MainTeacherView from './MainTeacherView';
1010

1111
const Homepage: React.FC = () => {
1212
const dispatch = useDispatch();
@@ -31,7 +31,7 @@ const Homepage: React.FC = () => {
3131
<Navbar />
3232
<main className="flex flex-row justify-start w-full h-screen">
3333
<Sidemenu />
34-
{selectedCourse ? <Outlet /> : <Instruction />}
34+
{selectedCourse ? <Outlet /> : <MainTeacherView />}
3535
</main>
3636
</div>
3737
);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
import { useParams } from 'react-router';
3+
import AddForm from '../TeacherDashboard/AddForm';
4+
import Instruction from './Instruction';
5+
6+
const MainTeacherView = () => {
7+
const { type } = useParams();
8+
const addForm = type === 'new-course' && true;
9+
10+
return <div className="w-3/4">{addForm ? <AddForm /> : <Instruction />}</div>;
11+
};
12+
13+
export default MainTeacherView;

client/src/store/actions.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ export const setSession = (session: Session | null) => ({
2222
session,
2323
});
2424

25-
export const setForm = (open: boolean) => ({
26-
type: 'SET_FORM',
27-
open,
28-
});
29-
3025
export const setHistory = (showing: boolean) => ({
3126
type: 'SET_HISTORY',
3227
showing,

client/src/store/reducers.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,6 @@ const session: SessionReducer = (state = null, action) => {
5959
}
6060
};
6161

62-
type formReducer = (
63-
state: boolean,
64-
action: { type: string; open: boolean }
65-
) => boolean;
66-
67-
const form: formReducer = (state = false, action) => {
68-
switch (action.type) {
69-
case 'SET_FORM':
70-
return !action.open;
71-
default:
72-
return state;
73-
}
74-
};
75-
7662
type historyReducer = (
7763
state: boolean,
7864
action: { type: string; showing: boolean }
@@ -106,7 +92,6 @@ const reducers = combineReducers({
10692
courses,
10793
selectedCourse,
10894
session,
109-
form,
11095
history,
11196
currentList,
11297
});

0 commit comments

Comments
 (0)