CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/course/configuration/empty-trash.tsx
Views: 687
1
import { Card, Button } from "antd";
2
import { Icon } from "@cocalc/frontend/components";
3
import {
4
useFrameContext,
5
useMemo,
6
useRedux,
7
} from "@cocalc/frontend/app-framework";
8
import { CourseActions } from "../actions";
9
import { plural } from "@cocalc/util/misc";
10
11
export default function EmptyTrash() {
12
const { actions } = useFrameContext();
13
const courseActions = (actions as any).course_actions as CourseActions;
14
const { name } = courseActions;
15
const assignments = useRedux([name, "assignments"]);
16
const students = useRedux([name, "students"]);
17
const handouts = useRedux([name, "handouts"]);
18
const num = useMemo(() => {
19
const num = {
20
assignments: 0,
21
students: 0,
22
handouts: 0,
23
total: 0,
24
desc: "Purge Deleted",
25
};
26
if (assignments) {
27
for (const [, assignment] of assignments) {
28
if (assignment.get("deleted")) {
29
num.assignments += 1;
30
}
31
}
32
}
33
if (students) {
34
for (const [, student] of students) {
35
if (student.get("deleted")) {
36
num.students += 1;
37
}
38
}
39
}
40
if (handouts) {
41
for (const [, handout] of handouts) {
42
if (handout.get("deleted")) {
43
num.handouts += 1;
44
}
45
}
46
}
47
num.total = num.students + num.assignments + num.handouts;
48
num.desc = `Purge ${num.students} deleted ${plural(
49
num.students,
50
"student",
51
)}, ${num.assignments} ${plural(num.assignments, "assignment")}, and ${
52
num.handouts
53
} ${plural(num.handouts, "handout")}`;
54
return num;
55
}, [assignments, students, handouts]);
56
57
return (
58
<Card
59
title={
60
<>
61
<Icon name="trash" /> Empty Trash: {num.desc}
62
</>
63
}
64
>
65
{num.total == 0 ? (
66
"You have no deleted students, assignments or handouts."
67
) : (
68
<>
69
When you delete students, assignments or handouts, they can be shown
70
again by clicking "Show xx deleted students/assignments/handouts" in
71
the corresponding tab of your course, then clicking undelete. You can
72
purge these deleted students, assignments and handouts below.
73
<div style={{ marginTop: "15px", textAlign: "center" }}>
74
<Button
75
onClick={() => {
76
courseActions.configuration.purgeDeleted();
77
}}
78
>
79
{num.desc}
80
</Button>
81
</div>
82
</>
83
)}
84
</Card>
85
);
86
}
87
88