-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCourseWrapper.tsx
More file actions
176 lines (165 loc) · 8.12 KB
/
CourseWrapper.tsx
File metadata and controls
176 lines (165 loc) · 8.12 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import { useContext, useState, useEffect, MutableRefObject } from "react";
import { Grid, Segment, Header, Icon, Popup } from "semantic-ui-react";
import { useMediaQuery } from "@material-ui/core";
import CourseSidebar from "./CourseSidebarNav";
import { AuthUserContext } from "../../context/auth";
import { useCourse, useStaff } from "../../hooks/data-fetching/course";
import * as bellAudio from "./InstructorQueuePage/notification.mp3";
import * as aolAudio from "./InstructorQueuePage/aol.mp3";
import Footer from "../common/Footer";
import { usePlayer } from "../../hooks/player";
import { Course as CourseType, Membership } from "../../types";
import CourseSidebarInstructorList from "./CourseSidebarInstructorList";
import { MOBILE_BP } from "../../constants";
import { browserSupportsNotifications } from "../../utils/notifications";
import { isAprilFools } from "../../utils/branding";
interface CourseProps {
render: (
staff: boolean,
play: MutableRefObject<(string) => void | undefined>,
notifs?: boolean,
setNotifs?: (boolean) => void
) => JSX.Element;
course: CourseType;
leadership: Membership[];
}
const CourseWrapper = ({ render, ...props }: CourseProps) => {
const { course: rawCourse, leadership } = props;
const { data: course } = useCourse(rawCourse.id, rawCourse);
const { user: initialUser } = useContext(AuthUserContext);
if (!initialUser) {
throw new Error(
"Invariant broken: withAuth must be used with component"
);
}
const { staff } = useStaff(rawCourse.id, initialUser);
const [notifs, setNotifs, play] = usePlayer(
isAprilFools ? aolAudio : bellAudio
);
const [supportsNotifs, setSupportsNotifs] = useState(false);
useEffect(() => setSupportsNotifs(browserSupportsNotifications()), []);
const toggleNotifs = () => {
const newNotifs = !notifs;
setNotifs(newNotifs);
localStorage.setItem("notifs", newNotifs ? "true" : "false");
document.body.focus();
};
const isMobile = useMediaQuery(`(max-width: ${MOBILE_BP})`);
return course ? (
// Need to override semantic UI Grid.Row's display: flex for instructor list to clear the row
<Grid.Row style={{ display: "block" }}>
<Grid.Column width={3}>
<CourseSidebar course={course} />
</Grid.Column>
<Grid.Column
width={13}
style={{
display: "flex",
flexDirection: "column",
float: "right",
...(!isMobile && { minHeight: "100%" }),
}}
>
{course.department && (
<Grid columns="equal" style={{ marginBottom: "-2rem" }}>
<Grid.Column>
<Segment basic>
<Header as="h1">
{`${course.department} ${course.courseCode}`}
<Header.Subheader>
{course.courseTitle}
</Header.Subheader>
</Header>
</Segment>
</Grid.Column>
{supportsNotifs && (
<Grid.Column>
<Segment basic>
<div
style={{
float: "right",
paddingTop: "0.71rem",
}}
>
{!isMobile && (
<Popup
trigger={
<div
style={{
display: "inline",
position:
"relative",
top: "0.14rem",
fontSize: "1.29rem",
fontFamily: "Lato",
color: "#666666",
}}
>
Notifications are{" "}
{notifs ? "ON" : "OFF"}
</div>
}
size="mini"
>
<p>
Browser permissions are{" "}
{typeof Notification !==
"undefined" && (
<strong>
{
Notification.permission
}
</strong>
)}
.
</p>
{typeof Notification !==
"undefined" &&
Notification.permission ===
"denied" && (
<p>
Enable notification
permisions to
receive browser
notifications.
</p>
)}
</Popup>
)}
<Icon
size="large"
style={{
paddingLeft: "0.71rem",
cursor: "pointer",
color: "rgba(0, 0, 0, 0.6)",
}}
name={
notifs
? "bell outline"
: "bell slash outline"
}
onClick={toggleNotifs}
/>
</div>
</Segment>
</Grid.Column>
)}
</Grid>
)}
<Segment basic>
{render(staff, play, notifs, setNotifs)}
</Segment>
{!isMobile && <Footer />}
</Grid.Column>
<Grid.Column style={{ clear: "left" }} width={3}>
{leadership && (
<CourseSidebarInstructorList
courseId={course.id}
leadership={leadership}
/>
)}
</Grid.Column>
</Grid.Row>
) : null;
};
export default CourseWrapper;