This repository was archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCourseBanner.tsx
103 lines (96 loc) · 3.74 KB
/
CourseBanner.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"use client"
import React, {useEffect, useState} from 'react';
import {Box, Typography, Skeleton} from "@mui/material";
import EditCourseButton from "@app/[locale]/components/EditCourseButton";
import {APIError, Course, getCourse, UserData, getUserData} from "@lib/api";
import defaultBanner from "../../../public/ugent_banner.png";
interface CourseBannerProps {
course_id: number;
}
const CourseBanner = ({course_id}: CourseBannerProps) => {
/*
* Banner component displayed in the course details page
* @param course_id: id of the course.
* */
const [user, setUser] = useState<UserData | null>(null);
const [course, setCourse] = useState<Course | null>(null);
const [error, setError] = useState<APIError | null>(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
const fetchCourse = async () => {
try {
setCourse(await getCourse(course_id));
setUser(await getUserData());
} catch (error) {
if (error instanceof APIError) setError(error);
console.log(error);
}
};
fetchCourse().then(() => setLoading(false));
}, [course_id]);
return (
loading ? (
<Skeleton
variant="rounded"
height={"150px"}
sx={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
borderRadius: '16px',
margin: "0 auto",
}}
/>
) : (
<Box
sx={{
backgroundImage: `url(${course?.banner || defaultBanner.src})`,
backgroundSize: "cover",
backgroundPosition: "center",
backgroundRepeat: "no-repeat",
color: 'whiteS',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
height: '150px',
borderRadius: '16px',
}}
>
<Box
display="flex"
justifyContent={{ xs: 'center', sm: 'flex-start' }}
alignItems="center"
width={{ xs: '100%', sm: "calc(100% - 200px)" }}
height={{ xs: 'auto', sm: '100%' }}
textAlign={{ xs: 'center', sm: 'left' }}
>
<Typography
variant="h4"
sx={{
color: 'white',
height: 'fit-content',
fontSize: { xs: '1.5rem', sm: '2rem', md: '2.5rem' },
whiteSpace: { xs: 'normal', sm: 'nowrap' },
overflow: 'hidden',
textOverflow: 'ellipsis',
}}
>
{course?.name + (course?.year === null ? "" : " " + course?.year) /*Display the course name + the year of the course*/}
</Typography>
</Box>
{user?.role !== 3 ? ( //Do not display edit button if the user is a student.
<Box
display="flex"
justifyContent={{ xs: 'center', sm: 'flex-start' }}
alignItems="center"
paddingY={{ xs: 1, sm: 0 }}
width={{ xs: '100%', sm: 'auto' }}
>
<EditCourseButton course_id={course_id} />
</Box>
) : null}
</Box>
)
);
}
export default CourseBanner;