Skip to content

Commit b373721

Browse files
author
Alexandra Zwinger
committed
Cleanup
1 parent 9ea3382 commit b373721

File tree

9 files changed

+245
-223
lines changed

9 files changed

+245
-223
lines changed

src/api/ModuleApi.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,4 @@ export function createModule(axios: AxiosInstance, moduleName: string) {
1313
const url = `/${Resources.MODULES}`;
1414
axios.post(url, {name: moduleName})
1515
.then(handleSuccessResponse, handleErrorResponse);
16-
}
17-
18-
//TODO HANDLE TOGGLE FUNCTION. WHAT ENDPOINT TO USE? ASK BACKEND
19-
export function toggleCheckbox(axios: AxiosInstance) {
20-
const url = `/${Resources.CHECKBOX}`;
21-
axios.put(url)
22-
.then(handleSuccessResponse, handleErrorResponse);
2316
}

src/api/UserApi.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ export function updateUsername(axios: AxiosInstance, name: string) {
1515
}
1616

1717
export function updateUserModules(axios: AxiosInstance, modules: UserModule[]) {
18-
const fullModules = addExamData(modules);
19-
return axios.put(Resources.USER, fullModules)
18+
return axios.put(Resources.USER, modules)
2019
.then(handleSuccessResponse, handleErrorResponse);
21-
}
22-
23-
const addExamData = (userModules: UserModule[]) => {
24-
return userModules.map(userModule => ({
25-
...userModule,
26-
examDate: "JJJJ-MM-DD",
27-
examLoc: "loco",
28-
}));
29-
};
20+
}

src/components/ModuleProgressSettings.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const ModuleProgressSettings: React.FC<ModalProps> = ({onClose, module, allUserM
2424
setProgress(percent);
2525
}, [chapters]);
2626

27-
const toggleCheckbox = (chapterId: number, checkboxId: number) => {
27+
const clickCheckbox = (chapterId: number, checkboxId: string) => {
2828
setChapters((prevChapters) =>
2929
prevChapters.map((chapter) =>
3030
chapter.id === chapterId
@@ -43,7 +43,7 @@ const ModuleProgressSettings: React.FC<ModalProps> = ({onClose, module, allUserM
4343

4444
const addCheckbox = (chapterId: number) => {
4545
const newCheckbox = {
46-
id: Date.now() + Math.floor(Math.random() * 1000),
46+
id: Date.now().toString(),
4747
title: `Add Title`,
4848
checked: false,
4949
};
@@ -57,7 +57,7 @@ const ModuleProgressSettings: React.FC<ModalProps> = ({onClose, module, allUserM
5757
);
5858
};
5959

60-
const deleteCheckbox = (chapterId: number, checkboxId: number) => {
60+
const deleteCheckbox = (chapterId: number, checkboxId: string) => {
6161
setChapters((prevChapters) =>
6262
prevChapters.map((chapter) =>
6363
chapter.id === chapterId
@@ -104,7 +104,7 @@ const ModuleProgressSettings: React.FC<ModalProps> = ({onClose, module, allUserM
104104

105105
{/* Progress-Bar */}
106106
<div className="progress-container sm:ml-3 mb-6">
107-
<div className="progress-bar" style={{ width: `${progress}%` }} />
107+
<div className="progress-bar" style={{width: `${progress}%`}}/>
108108
<span className="text-white text-sm ml-2">{progress}%</span>
109109
</div>
110110

@@ -116,7 +116,7 @@ const ModuleProgressSettings: React.FC<ModalProps> = ({onClose, module, allUserM
116116
</p>
117117
<button
118118
className="delete-btn"
119-
onClick={() => deleteCheckbox(chapter.id, -1)}
119+
onClick={() => deleteCheckbox(chapter.id, "-1")}
120120
>
121121
x
122122
</button>
@@ -128,7 +128,7 @@ const ModuleProgressSettings: React.FC<ModalProps> = ({onClose, module, allUserM
128128
type="checkbox"
129129
className={"min-w-[30px]"}
130130
checked={checkbox.checked}
131-
onChange={() => toggleCheckbox(chapter.id, checkbox.id)}
131+
onChange={() => clickCheckbox(chapter.id, checkbox.id)}
132132
/>
133133
<input
134134
type="text"
Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,59 @@
1-
import React, { useState } from 'react';
1+
import React, {useEffect, useState} from 'react';
22
import '../../styles/Modal.css';
3-
import { CuteButton } from '../CuteButton';
4-
import { UserModule } from '../../dtos/ModuleDto';
3+
import {CuteButton} from '../CuteButton';
4+
import {UserModule} from '../../dtos/ModuleDto';
55

66
interface Props {
7-
isOpen: boolean;
8-
modules: UserModule[];
9-
onClose: () => void;
10-
onSubmit: (moduleName: string, date: string, time: string, room: string) => void;
7+
isOpen: boolean;
8+
modules: UserModule[];
9+
onClose: () => void;
10+
onSubmit: (moduleName: string, date: string, time: string, room: string) => void;
1111
}
1212

13-
export default function ExamDateModal({ isOpen, modules, onClose, onSubmit }: Props) {
14-
const [pick, setPick] = useState(modules[0]?.name || '');
15-
const [day, setDay] = useState('');
16-
const [hour, setHour] = useState('');
17-
const [loc, setLoc] = useState('');
13+
export default function ExamDateModal({isOpen, modules, onClose, onSubmit}: Props) {
14+
const [pick, setPick] = useState(modules[0] || '');
15+
const [day, setDay] = useState(pick.examDate);
16+
const [hour, setHour] = useState(pick.examTime);
17+
const [loc, setLoc] = useState(pick.examLoc);
1818

19-
if (!isOpen) return null;
19+
useEffect(() => {
20+
setDay(pick.examDate);
21+
setHour(pick.examTime);
22+
setLoc(pick.examLoc);
23+
}, [pick])
2024

21-
return (
22-
<div className="modal-overlay" onClick={onClose}>
23-
<div className="modal-content max-w-[90%] w-[500px] p-7 relative" onClick={e => e.stopPropagation()}>
24-
<button onClick={onClose} className="absolute top-4 right-4 text-white text-2xl hover:text-red-400">×</button>
25-
<h2 className="text-2xl font-bold text-white mb-4">Prüfungstermin hinzufügen</h2>
26-
<div className="flex flex-col gap-4 mb-6">
27-
<select value={pick} onChange={e => setPick(e.target.value)} className="p-2 rounded bg-[#2A2A2A] text-white">
28-
{modules.map(m => <option key={m.name}>{m.name}</option>)}
29-
</select>
30-
<input type="date" value={day} onChange={e => setDay(e.target.value)} className="p-2 rounded bg-[#2A2A2A] text-white" />
31-
<input type="time" value={hour} onChange={e => setHour(e.target.value)} className="p-2 rounded bg-[#2A2A2A] text-white" />
32-
<input type="text" placeholder="Raum" value={loc} onChange={e => setLoc(e.target.value)} className="p-2 rounded bg-[#2A2A2A] text-white" />
33-
</div>
34-
<div className="flex justify-end gap-4">
35-
<CuteButton onClick={onClose} text="Abbrechen" bgColor="#974242" textColor="#e8fcf6" classname="px-4 py-2" />
36-
<CuteButton onClick={() => onSubmit(pick, day, hour, loc)} text="Speichern" bgColor="#56A095" textColor="#e6ebfc" classname="px-4 py-2" />
25+
if (!isOpen) return null;
26+
27+
return (
28+
<div className="modal-overlay" onClick={onClose}>
29+
<div className="modal-content max-w-[90%] w-[500px] p-7 relative" onClick={e => e.stopPropagation()}>
30+
<button onClick={onClose} className="absolute top-4 right-4 text-white text-2xl hover:text-red-400">×
31+
</button>
32+
<h2 className="text-2xl font-bold text-white mb-4">Prüfungstermin hinzufügen</h2>
33+
<div className="flex flex-col gap-4 mb-6">
34+
<select value={pick.name}
35+
onChange={e => {
36+
const selectedModule = modules.find(m => m.name === e.target.value);
37+
if (selectedModule)
38+
setPick(selectedModule);
39+
}}
40+
className="p-2 rounded bg-[#2A2A2A] text-white">
41+
{modules.map(m => <option key={m.name}>{m.name}</option>)}
42+
</select>
43+
<input type="date" value={day} onChange={e => setDay(e.target.value)}
44+
className="p-2 rounded bg-[#2A2A2A] text-white"/>
45+
<input type="time" value={hour} onChange={e => setHour(e.target.value)}
46+
className="p-2 rounded bg-[#2A2A2A] text-white"/>
47+
<input type="text" placeholder="Raum" value={loc} onChange={e => setLoc(e.target.value)}
48+
className="p-2 rounded bg-[#2A2A2A] text-white"/>
49+
</div>
50+
<div className="flex justify-end gap-4">
51+
<CuteButton onClick={onClose} text="Abbrechen" bgColor="#974242" textColor="#e8fcf6"
52+
classname="px-4 py-2"/>
53+
<CuteButton onClick={() => onSubmit(pick.name, day, hour, loc)} text="Speichern" bgColor="#56A095"
54+
textColor="#e6ebfc" classname="px-4 py-2"/>
55+
</div>
56+
</div>
3757
</div>
38-
</div>
39-
</div>
40-
);
58+
);
4159
}

src/components/meeting/MeetingDetails.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const MeetingDetails: React.FC<ModalProps> = ({isOpen, meeting, onClose, openMee
9191
{userIds.length === 0 && <></>}
9292
</ul>
9393
</div>
94-
{meeting.creator == myUser.uuid ? (
94+
{meeting.creator === myUser.uuid ? (
9595
<div className="flex flex-row gap-4 mb-4 justify-end mt-auto items-center">
9696
<div>
9797
<CuteButton

src/components/meeting/MeetingSearchResult.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ export default function MeetingSearchResult(
165165
<div className="flex gap-2 pt-2">
166166
{!loading && !isMember && (
167167
<CuteButton
168-
onClick={isExpanded == false ? joinSuperMeeting : joinMeeting}
169-
text={isExpanded == false ? 'An allen Meetings teilnehmen' : 'Teilnehmen'}
168+
onClick={isExpanded === false ? joinSuperMeeting : joinMeeting}
169+
text={isExpanded === false ? 'An allen Meetings teilnehmen' : 'Teilnehmen'}
170170
textColor="#e8fcf6"
171171
bgColor="#56A095"
172172
classname="text-sm w-full"
@@ -177,8 +177,8 @@ export default function MeetingSearchResult(
177177

178178
{!loading && isMember && (
179179
<CuteButton
180-
onClick={isExpanded == false ? leaveSuperMeeting : leaveMeeting}
181-
text={isExpanded == false ? 'Alle Meetings verlassen' : 'Meeting verlassen'}
180+
onClick={isExpanded === false ? leaveSuperMeeting : leaveMeeting}
181+
text={isExpanded === false ? 'Alle Meetings verlassen' : 'Meeting verlassen'}
182182
textColor="#e8fcf6"
183183
bgColor="#974242"
184184
classname="text-sm w-full"

0 commit comments

Comments
 (0)