Skip to content

Commit 53ad64f

Browse files
committed
course: switch to using popconfirms
1 parent 3ac3b67 commit 53ad64f

File tree

7 files changed

+116
-226
lines changed

7 files changed

+116
-226
lines changed

src/packages/frontend/course/assignments/assignment.tsx

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
Tip,
1414
} from "@cocalc/frontend/components";
1515
import { capitalize, trunc_middle } from "@cocalc/util/misc";
16-
import { Alert, Button, Card, Col, Input, Row, Space } from "antd";
16+
import { Alert, Button, Card, Col, Input, Popconfirm, Row, Space } from "antd";
1717
import { ReactElement, useState } from "react";
1818
import { DebounceInput } from "react-debounce-input";
1919
import { CourseActions } from "../actions";
@@ -92,7 +92,6 @@ export function Assignment({
9292
}: AssignmentProps) {
9393
const size = useButtonSize();
9494

95-
const [confirm_delete, set_confirm_delete] = useState<boolean>(false);
9695
const [
9796
copy_assignment_confirm_overwrite,
9897
set_copy_assignment_confirm_overwrite,
@@ -239,6 +238,10 @@ export function Assignment({
239238
}
240239

241240
function render_no_content() {
241+
if (assignment.get("deleted")) {
242+
// no point
243+
return null;
244+
}
242245
return (
243246
<div style={{ margin: "15px auto", maxWidth: "800px", fontSize: "12pt" }}>
244247
There are no files in this assignment yet. Please{" "}
@@ -293,15 +296,6 @@ export function Assignment({
293296
</Row>,
294297
);
295298
}
296-
if (confirm_delete) {
297-
v.push(
298-
<Row key="header2-delete" style={bottom}>
299-
<Col md={20} offset={4}>
300-
{render_confirm_delete()}
301-
</Col>
302-
</Row>,
303-
);
304-
}
305299

306300
const peer = is_peer_graded();
307301
if (peer) {
@@ -1112,7 +1106,6 @@ export function Assignment({
11121106

11131107
function delete_assignment() {
11141108
actions.assignments.delete_assignment(assignment.get("assignment_id"));
1115-
return set_confirm_delete(false);
11161109
}
11171110

11181111
function undelete_assignment() {
@@ -1121,28 +1114,6 @@ export function Assignment({
11211114
);
11221115
}
11231116

1124-
function render_confirm_delete() {
1125-
const message = (
1126-
<div>
1127-
Are you sure you want to delete this assignment?
1128-
<br /> <br />
1129-
<Space>
1130-
<Button
1131-
key="no"
1132-
onClick={() => set_confirm_delete(false)}
1133-
size={size}
1134-
>
1135-
Cancel
1136-
</Button>
1137-
<Button key="yes" onClick={delete_assignment} danger size={size}>
1138-
<Icon name="trash" /> Delete
1139-
</Button>
1140-
</Space>
1141-
</div>
1142-
);
1143-
return <Alert type="warning" key="confirm_delete" message={message} />;
1144-
}
1145-
11461117
function render_delete_button() {
11471118
if (assignment.get("deleted")) {
11481119
return (
@@ -1159,20 +1130,25 @@ export function Assignment({
11591130
);
11601131
} else {
11611132
return (
1162-
<Tip
1163-
key="delete"
1164-
placement="left"
1165-
title="Delete assignment"
1166-
tip="Deleting this assignment removes it from the assignment list and student grade lists, but does not delete any files off of disk. You can always undelete an assignment later by showing it using the 'show deleted assignments' button."
1133+
<Popconfirm
1134+
title={
1135+
<div style={{ maxWidth: "400px" }}>
1136+
<b>
1137+
Are you sure you want to delete "
1138+
{trunc_middle(assignment.get("path"), 24)}"?
1139+
</b>
1140+
<br /> This removes it from the assignment list and student grade
1141+
lists, but does not delete any files off of disk. You can undelete
1142+
an assignment later by showing it using the 'Show deleted
1143+
assignments' button.
1144+
</div>
1145+
}
1146+
onConfirm={delete_assignment}
11671147
>
1168-
<Button
1169-
onClick={() => set_confirm_delete(true)}
1170-
disabled={confirm_delete}
1171-
size={size}
1172-
>
1173-
<Icon name="trash" /> Delete
1148+
<Button size={size}>
1149+
<Icon name="trash" /> Delete...
11741150
</Button>
1175-
</Tip>
1151+
</Popconfirm>
11761152
);
11771153
}
11781154
}

src/packages/frontend/course/configuration/start-stop-panel.tsx

Lines changed: 40 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Alert, Button, Card, Row, Col, Space, Spin } from "antd";
2-
import { Icon } from "../../components";
3-
import { useState, useActions, useRedux } from "../../app-framework";
4-
import { CourseActions } from "../actions";
1+
import { Alert, Button, Card, Row, Col, Popconfirm, Space, Spin } from "antd";
2+
import { Icon } from "@cocalc/frontend/components/icon";
3+
import { useActions, useRedux } from "@cocalc/frontend/app-framework";
4+
import type { CourseActions } from "../actions";
55
import { capitalize } from "@cocalc/util/misc";
66

77
interface Props {
@@ -19,11 +19,6 @@ export function StudentProjectsStartStopPanel({
1919
name,
2020
"action_all_projects_state",
2121
]);
22-
const [confirm_stop_all_projects, set_confirm_stop_all_projects] =
23-
useState<boolean>(false);
24-
const [confirm_start_all_projects, set_confirm_start_all_projects] =
25-
useState<boolean>(false);
26-
2722
const actions: CourseActions = useActions(name);
2823

2924
function render_in_progress_action() {
@@ -63,67 +58,6 @@ export function StudentProjectsStartStopPanel({
6358
);
6459
}
6560

66-
function render_confirm_stop_all_projects() {
67-
return (
68-
<Alert
69-
type="warning"
70-
message={
71-
<div>
72-
Are you sure you want to stop all student projects (this might be
73-
disruptive)?
74-
<br />
75-
<br />
76-
<Space>
77-
<Button onClick={() => set_confirm_stop_all_projects(false)}>
78-
Cancel
79-
</Button>
80-
<Button
81-
danger
82-
type="primary"
83-
onClick={() => {
84-
set_confirm_stop_all_projects(false);
85-
actions.student_projects.action_all_student_projects("stop");
86-
}}
87-
>
88-
<Icon name="PoweroffOutlined" /> Stop all
89-
</Button>
90-
</Space>
91-
</div>
92-
}
93-
/>
94-
);
95-
}
96-
97-
function render_confirm_start_all_projects() {
98-
return (
99-
<Alert
100-
type="info"
101-
message={
102-
<div>
103-
Are you sure you want to start all student projects? This will
104-
ensure the projects are already running when the students open them.
105-
<br />
106-
<br />
107-
<Space>
108-
<Button onClick={() => set_confirm_start_all_projects(false)}>
109-
Cancel
110-
</Button>{" "}
111-
<Button
112-
type="primary"
113-
onClick={() => {
114-
set_confirm_start_all_projects(false);
115-
actions.student_projects.action_all_student_projects("start");
116-
}}
117-
>
118-
<Icon name="bolt" /> Start all
119-
</Button>
120-
</Space>
121-
</div>
122-
}
123-
/>
124-
);
125-
}
126-
12761
const r = num_running_projects;
12862
const n = num_students;
12963
return (
@@ -142,35 +76,51 @@ export function StudentProjectsStartStopPanel({
14276
<Row style={{ marginTop: "10px" }}>
14377
<Col md={24}>
14478
<Space>
145-
<Button
146-
onClick={() => set_confirm_start_all_projects(true)}
147-
disabled={
148-
n === 0 ||
149-
n === r ||
150-
confirm_start_all_projects ||
151-
action_all_projects_state === "starting"
79+
<Popconfirm
80+
title={
81+
<div style={{ maxWidth: "400px" }}>
82+
<b>Are you sure you want to start all student projects?</b>
83+
<br /> This will ensure the projects are already running when
84+
the students open them, and can make assigning and collecting
85+
homework more robust.
86+
</div>
15287
}
88+
onConfirm={() => {
89+
actions.student_projects.action_all_student_projects("start");
90+
}}
15391
>
154-
<Icon name="bolt" /> Start all...
155-
</Button>
156-
<Button
157-
onClick={() => set_confirm_stop_all_projects(true)}
158-
disabled={
159-
n === 0 ||
160-
r === 0 ||
161-
confirm_stop_all_projects ||
162-
action_all_projects_state === "stopping"
92+
<Button
93+
disabled={
94+
n === 0 || n === r || action_all_projects_state === "starting"
95+
}
96+
>
97+
<Icon name="bolt" /> Start all...
98+
</Button>
99+
</Popconfirm>
100+
<Popconfirm
101+
title={
102+
<div style={{ maxWidth: "400px" }}>
103+
Are you sure you want to stop all student projects (this might
104+
be disruptive)?
105+
</div>
163106
}
107+
onConfirm={() => {
108+
actions.student_projects.action_all_student_projects("stop");
109+
}}
164110
>
165-
<Icon name="PoweroffOutlined" /> Stop all...
166-
</Button>
111+
<Button
112+
disabled={
113+
n === 0 || r === 0 || action_all_projects_state === "stopping"
114+
}
115+
>
116+
<Icon name="PoweroffOutlined" /> Stop all...
117+
</Button>
118+
</Popconfirm>
167119
</Space>
168120
</Col>
169121
</Row>
170122
<Row style={{ marginTop: "10px" }}>
171123
<Col md={24}>
172-
{confirm_start_all_projects && render_confirm_start_all_projects()}
173-
{confirm_stop_all_projects && render_confirm_stop_all_projects()}
174124
{action_all_projects_state !== "any" && render_in_progress_action()}
175125
</Col>
176126
</Row>

src/packages/frontend/course/handouts/handout.tsx

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { redux, CSS } from "@cocalc/frontend/app-framework";
77
import { useState } from "react";
88
import { capitalize, trunc_middle } from "@cocalc/util/misc";
9-
import { Alert, Button, Input, Card, Col, Row, Space } from "antd";
9+
import { Alert, Button, Input, Card, Col, Popconfirm, Row, Space } from "antd";
1010
import { Icon, MarkdownInput, Tip } from "../../components";
1111
import { UserMap } from "../../todo-types";
1212
import { CourseActions } from "../actions";
@@ -65,14 +65,6 @@ interface HandoutProps {
6565
project_id: string;
6666
}
6767

68-
// interface HandoutState {
69-
// confirm_delete: boolean;
70-
// copy_confirm: boolean;
71-
// copy_confirm_handout: boolean;
72-
// copy_handout_confirm_overwrite: boolean;
73-
// copy_handout_confirm_overwrite_text: string;
74-
// }
75-
7668
export function Handout({
7769
frame_id,
7870
name,
@@ -84,7 +76,6 @@ export function Handout({
8476
user_map,
8577
project_id,
8678
}: HandoutProps) {
87-
const [confirm_delete, set_confirm_delete] = useState<boolean>(false);
8879
const [copy_confirm, set_copy_confirm] = useState<boolean>(false);
8980
const [copy_confirm_handout, set_copy_confirm_handout] =
9081
useState<boolean>(false);
@@ -420,36 +411,12 @@ export function Handout({
420411

421412
function delete_handout(): void {
422413
actions.handouts.delete_handout(handout.get("handout_id"));
423-
set_confirm_delete(false);
424414
}
425415

426416
function undelete_handout(): void {
427417
actions.handouts.undelete_handout(handout.get("handout_id"));
428418
}
429419

430-
function render_confirm_delete() {
431-
return (
432-
<Alert
433-
type="warning"
434-
key="confirm_delete"
435-
message={
436-
<div>
437-
Are you sure you want to delete this handout?
438-
<br /> <br />
439-
<Space>
440-
<Button key="no" onClick={() => set_confirm_delete(false)}>
441-
Cancel
442-
</Button>
443-
<Button key="yes" onClick={delete_handout} danger>
444-
<Icon name="trash" /> Delete
445-
</Button>
446-
</Space>
447-
</div>
448-
}
449-
/>
450-
);
451-
}
452-
453420
function render_delete_button() {
454421
if (handout.get("deleted")) {
455422
return (
@@ -466,20 +433,27 @@ export function Handout({
466433
);
467434
} else {
468435
return (
469-
<Tip
436+
<Popconfirm
470437
key="delete"
471-
placement="left"
472-
title="Delete handout"
473-
tip="Deleting this handout removes it from the handout list and student grade lists, but does not delete any files off of disk. You can always undelete an handout later by showing it using the 'show deleted handouts' button."
438+
onConfirm={delete_handout}
439+
title={
440+
<div style={{ maxWidth: "400px" }}>
441+
<b>
442+
Are you sure you want to delete "
443+
{trunc_middle(handout.get("path"), 24)}"?
444+
</b>
445+
<br />
446+
This removes it from the handout list and student grade lists, but
447+
does not delete any files off of disk. You can always undelete an
448+
handout later by showing it using the 'show deleted handouts'
449+
button.
450+
</div>
451+
}
474452
>
475-
<Button
476-
onClick={() => set_confirm_delete(true)}
477-
disabled={confirm_delete}
478-
style={outside_button_style}
479-
>
453+
<Button style={outside_button_style}>
480454
<Icon name="trash" /> Delete...
481455
</Button>
482-
</Tip>
456+
</Popconfirm>
483457
);
484458
}
485459
}
@@ -576,7 +550,6 @@ export function Handout({
576550
<Row>
577551
<span className="pull-right">{render_delete_button()}</span>
578552
</Row>
579-
<Row>{confirm_delete ? render_confirm_delete() : undefined}</Row>
580553
</Col>
581554
</Row>
582555
);

0 commit comments

Comments
 (0)