Skip to content

Commit 56bca01

Browse files
committed
course: add modal and menu item for adding students
1 parent 3e5c29f commit 56bca01

File tree

6 files changed

+80
-16
lines changed

6 files changed

+80
-16
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Alert, Modal } from "antd";
2+
import type { StudentsMap } from "./store";
3+
import type { UserMap } from "@cocalc/frontend/todo-types";
4+
import AddStudents from "@cocalc/frontend/course/students/add-students";
5+
import { Icon } from "@cocalc/frontend/components/icon";
6+
7+
interface Props {
8+
actions;
9+
modal?: string;
10+
name: string;
11+
students?: StudentsMap;
12+
user_map?: UserMap;
13+
project_id;
14+
}
15+
16+
export default function Modals(props: Props) {
17+
const { students, user_map, modal } = props;
18+
if (students == null || user_map == null || !modal) {
19+
return null;
20+
}
21+
const close = () => {
22+
props.actions.setState({ modal: "" });
23+
};
24+
if (modal == "add-students") {
25+
return (
26+
<Modal
27+
onCancel={close}
28+
onOk={close}
29+
cancelButtonProps={{ style: { display: "none" } }}
30+
okText="Close"
31+
open
32+
title={
33+
<>
34+
<Icon name="users" /> Add Students
35+
</>
36+
}
37+
width={800}
38+
>
39+
<AddStudents {...props} students={students} user_map={user_map} />
40+
</Modal>
41+
);
42+
} else {
43+
return (
44+
<Alert type="warning" message={<>BUG -- Unknown modal: {modal}</>} />
45+
);
46+
}
47+
return null;
48+
}

src/packages/frontend/course/students/add-students.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99
useActions,
1010
useIsMountedRef,
1111
} from "@cocalc/frontend/app-framework";
12-
import { Button, Col, Form, Input, Row, Checkbox, Flex } from "antd";
13-
import { ErrorDisplay, Icon, Gap } from "@cocalc/frontend/components";
12+
import { Button, Col, Form, Input, Row, Checkbox, Flex, Space } from "antd";
13+
import { ErrorDisplay, Icon } from "@cocalc/frontend/components";
1414
import type { StudentsMap } from "../store";
1515
import type { UserMap } from "@cocalc/frontend/todo-types";
1616
import {
@@ -286,13 +286,11 @@ export default function AddStudents({
286286
{options}
287287
</select>
288288
</Form.Item>
289-
<Form.Item>
289+
<Space>
290290
{render_cancel()}
291-
<Gap />
292291
{render_add_selector_button(options)}
293-
<Gap />
294292
{render_add_all_students_button(options)}
295-
</Form.Item>
293+
</Space>
296294
</>
297295
);
298296
}

src/packages/frontend/frame-editors/course-editor/actions.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import { FrameTree } from "../frame-tree/types";
1111
import { Actions, CodeEditorState } from "../code-editor/actions";
1212
import { open_new_tab } from "@cocalc/frontend/misc";
1313

14-
interface CourseEditorState extends CodeEditorState {}
14+
export interface CourseEditorState extends CodeEditorState {
15+
modal?: string;
16+
}
1517

1618
import {
1719
CourseActions,
@@ -110,6 +112,10 @@ export class CourseEditorActions extends Actions<CourseEditorState> {
110112
help = (): void => {
111113
open_new_tab("https://doc.cocalc.com/teaching-instructors.html");
112114
};
115+
116+
setModal = (modal: string) => {
117+
this.setState({ modal });
118+
};
113119
}
114120

115121
export { CourseEditorActions as Actions };

src/packages/frontend/frame-editors/course-editor/course-actions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
* License: MS-RSL – see LICENSE.md for details
44
*/
55

6-
import { CourseActions } from "../../course/actions";
6+
import { CourseActions } from "@cocalc/frontend/course/actions";
77
export { CourseActions };
88

9-
import { init_redux, remove_redux } from "../../course/redux";
9+
import { init_redux, remove_redux } from "@cocalc/frontend/course/redux";
1010

1111
export function course_redux_name(project_id: string, path: string): string {
1212
return `course-editor-${project_id}-${path}`;
@@ -33,6 +33,6 @@ export function close_course_actions_and_store(opts: {
3333
opts.path,
3434
opts.redux,
3535
opts.project_id,
36-
course_redux_name(opts.project_id, opts.path)
36+
course_redux_name(opts.project_id, opts.path),
3737
);
3838
}

src/packages/frontend/frame-editors/course-editor/course-panel-wrapper.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,27 @@ import {
1616
Rendered,
1717
redux,
1818
AppRedux,
19+
useEditorRedux,
1920
useRedux,
2021
useTypedRedux,
2122
} from "@cocalc/frontend/app-framework";
22-
import { Loading, ActivityDisplay } from "../../components";
23+
import { Loading, ActivityDisplay } from "@cocalc/frontend/components";
2324
import ShowError from "@cocalc/frontend/components/error";
2425
import {
2526
AssignmentsMap,
2627
CourseSettingsRecord,
2728
StudentsMap,
2829
HandoutsMap,
29-
} from "../../course/store";
30+
} from "@cocalc/frontend/course/store";
3031
import { Map } from "immutable";
3132
import { ProjectMap, UserMap } from "../../todo-types";
3233
import { CourseActions, course_redux_name } from "./course-actions";
3334
import { values } from "@cocalc/util/misc";
3435
import { CourseTabBar } from "./course-tab-bar";
35-
import { CourseEditorActions } from "./actions";
36-
import { CourseStore } from "../../course/store";
37-
import { PayBanner } from "../../course/pay-banner";
36+
import type { CourseEditorActions, CourseEditorState } from "./actions";
37+
import { CourseStore } from "@cocalc/frontend/course/store";
38+
import { PayBanner } from "@cocalc/frontend/course/pay-banner";
39+
import Modals from "@cocalc/frontend/course/modals";
3840

3941
export interface FrameProps {
4042
id: string;
@@ -68,7 +70,8 @@ const CoursePanelWrapper: React.FC<FrameProps> = React.memo(
6870
(props: FrameProps) => {
6971
const { id, project_id, path, font_size, course_panel, actions, desc } =
7072
props;
71-
73+
const useEditor = useEditorRedux<CourseEditorState>({ project_id, path });
74+
const modal = useEditor("modal");
7275
const name = course_redux_name(project_id, path);
7376

7477
const students: StudentsMap | undefined = useRedux(name, "students");
@@ -212,6 +215,14 @@ const CoursePanelWrapper: React.FC<FrameProps> = React.memo(
212215
}}
213216
className="smc-vfill"
214217
>
218+
<Modals
219+
actions={actions}
220+
modal={modal}
221+
name={name}
222+
students={students}
223+
user_map={user_map}
224+
project_id={project_id}
225+
/>
215226
{render_panel()}
216227
</div>
217228
);

src/packages/frontend/frame-editors/course-editor/editor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const COMMANDS = {
5454
onClick: ({ props }) => {
5555
const { id, actions } = props;
5656
actions.set_frame_type(id, "course_students");
57+
actions.setModal("add-students");
5758
},
5859
},
5960
};

0 commit comments

Comments
 (0)