Skip to content

Commit a2cfeb2

Browse files
committed
Add dots menu and implement Rename Module
1 parent 01bd203 commit a2cfeb2

File tree

7 files changed

+419
-82
lines changed

7 files changed

+419
-82
lines changed

frontend/src/APIClients/CourseAPIClient.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,27 @@ const getModuleById = async (
164164
}
165165
};
166166

167+
const editModule = async (
168+
unitId: string,
169+
moduleId: string,
170+
title: string,
171+
): Promise<CourseModule | null> => {
172+
const bearerToken = `Bearer ${getLocalStorageObjProperty(
173+
AUTHENTICATED_USER_KEY,
174+
"accessToken",
175+
)}`;
176+
try {
177+
const { data } = await baseAPIClient.put(
178+
`/course/${unitId}/${moduleId}`,
179+
{ title },
180+
{ headers: { Authorization: bearerToken } },
181+
);
182+
return data;
183+
} catch (error) {
184+
return null;
185+
}
186+
};
187+
167188
export default {
168189
getUnits,
169190
createUnit,
@@ -174,4 +195,5 @@ export default {
174195
uploadThumbnail,
175196
lessonUpload,
176197
getModuleById,
198+
editModule,
177199
};

frontend/src/components/auth/PrivateRoute.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ const PrivateRoute: React.FC<PrivateRouteProps> = ({
3535

3636
const NavbarWrappedComponent: React.FC<PrivateRouteProps> = () => {
3737
return (
38-
<Box sx={{ height: "100vh", display: "flex", flexFlow: "column" }}>
38+
<Box sx={{ height: "100vh", display: "flex", flexFlow: "column", overflow: "hidden" }}>
3939
<Navbar />
40-
<Box sx={{ height: "100%", flexGrow: 1 }}>
40+
<Box sx={{ height: "100%", flexGrow: 1, overflow: "hidden" }}>
4141
<Component />
4242
</Box>
4343
</Box>

frontend/src/components/course_viewing/CourseModulesGrid.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Grid, Typography } from "@mui/material";
2+
import { useState, useEffect } from "react";
23
import useCourseModules from "../../hooks/useCourseModules";
34
import { useUser } from "../../hooks/useUser";
45
import { CourseModule } from "../../types/CourseTypes";
@@ -14,9 +15,26 @@ export default function CourseModulesGrid({
1415
unitId,
1516
isSidebarOpen,
1617
}: ModuleGridProps) {
17-
const { courseModules, loading, error } = useCourseModules(unitId);
18+
const {
19+
courseModules: initialModules,
20+
loading,
21+
error,
22+
} = useCourseModules(unitId);
23+
const [courseModules, setCourseModules] = useState<CourseModule[]>([]);
1824
const { role } = useUser();
1925

26+
useEffect(() => {
27+
setCourseModules(initialModules);
28+
}, [initialModules]);
29+
30+
const handleModuleUpdate = (updatedModule: CourseModule) => {
31+
setCourseModules((prev) =>
32+
prev.map((module) =>
33+
module.id === updatedModule.id ? updatedModule : module,
34+
),
35+
);
36+
};
37+
2038
if (loading)
2139
return <Typography paddingLeft="10px">Loading modules...</Typography>;
2240
if (error) return <Typography color="error">{error}</Typography>;
@@ -28,7 +46,8 @@ export default function CourseModulesGrid({
2846
<ModuleCardAdmin
2947
key={module.id}
3048
module={module}
31-
isSidebarOpen={isSidebarOpen}
49+
unitId={unitId}
50+
onModuleUpdate={handleModuleUpdate}
3251
/>
3352
) : (
3453
<ModuleCardLearner

frontend/src/components/course_viewing/CourseViewingPage.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import React, { useState } from "react";
2-
import { Box, Button, Stack, Typography, useTheme } from "@mui/material";
3-
import MenuOpenIcon from "@mui/icons-material/MenuOpen";
41
import AddIcon from "@mui/icons-material/Add";
5-
import UnitSidebar from "./sidebar/UnitSidebar";
2+
import MenuOpenIcon from "@mui/icons-material/MenuOpen";
3+
import { Box, Button, Stack, Typography, useTheme } from "@mui/material";
4+
import { useState } from "react";
65
import { CourseUnit } from "../../types/CourseTypes";
76
import CourseModulesGrid from "./CourseModulesGrid";
87
import CreateModuleModal from "./modals/CreateModuleModal";
8+
import UnitSidebar from "./sidebar/UnitSidebar";
99

1010
export default function CourseUnitsPage() {
1111
const theme = useTheme();
@@ -22,15 +22,15 @@ export default function CourseUnitsPage() {
2222
};
2323

2424
return (
25-
<Box display="flex" width="100%">
25+
<Box display="flex" width="100%" height="100vh" overflow="hidden">
2626
<UnitSidebar
2727
setSelectedUnit={setSelectedUnit}
2828
handleClose={handleDrawerClose}
2929
open={sidebarOpen}
3030
selectedUnit={selectedUnit}
3131
/>
3232

33-
<Box sx={{ flexGrow: 1, p: "48px" }}>
33+
<Box sx={{ flexGrow: 1, p: "48px", mb: "48px", overflowY: "scroll" }}>
3434
{selectedUnit ? (
3535
<Stack spacing="14px">
3636
<Box display="flex" alignItems="center" paddingLeft="10px">

0 commit comments

Comments
 (0)