Skip to content

Commit cbb2551

Browse files
author
Alexandra Zwinger
committed
Add save function & api-calls
1 parent b193763 commit cbb2551

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ export enum Resources {
4646
MEETING = "meeting",
4747
USER = "user",
4848
MODULES = "module",
49+
USER_MODULE = "userModule",
50+
CHECKBOX = "checkbox",
4951
USERGROUP = "studygroup"
5052
}
5153

src/api/ModuleApi.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {AxiosInstance} from "axios";
22
import {Resources} from "../App";
33
import {handleErrorResponse, handleSuccessResponse} from "./ErrorHandling";
4-
import {ModuleDto} from "../dtos/ModuleDto";
4+
import {ModuleDto, UserModule} from "../dtos/ModuleDto";
55

66
export function getModules(axios: AxiosInstance): Promise<ModuleDto[]> {
77
const url = `/${Resources.MODULES}`;
@@ -13,4 +13,17 @@ 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+
export function saveModuleProgress(axios: AxiosInstance, userModule: UserModule) {
19+
const url = `/${Resources.USER_MODULE}`;
20+
axios.put(url, userModule)
21+
.then(handleSuccessResponse, handleErrorResponse);
22+
}
23+
24+
//TODO HANDLE TOGGLE FUNCTION. WHAT ENDPOINT TO USE? ASK BACKEND
25+
export function toggleCheckbox(axios: AxiosInstance,) {
26+
const url = `/${Resources.CHECKBOX}`;
27+
axios.put(url,)
28+
.then(handleSuccessResponse, handleErrorResponse);
1629
}

src/components/ModuleProgressSettings.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React, {useState} from 'react';
22
import '../styles/Modal.css';
33
import {CuteButton} from './CuteButton';
44
import {Chapter, UserModule} from "../dtos/ModuleDto";
5+
import axiosInstance from "../AxiosConfig";
6+
import {saveModuleProgress} from "../api/ModuleApi";
57

68
interface ModalProps {
79
isOpen: boolean;
@@ -70,7 +72,12 @@ const ModuleProgressSettings: React.FC<ModalProps> = ({onClose, module}) => {
7072
};
7173

7274
const saveProgress = () => {
73-
//TODO
75+
try {
76+
module.chapter = chapters;
77+
saveModuleProgress(axiosInstance, module);
78+
} catch (error) {
79+
console.error("Error saving progress:" + error);
80+
}
7481
}
7582

7683
return (

0 commit comments

Comments
 (0)