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/activity/actions.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
/* Showing what is currently happening to the user
7
8
The actual react component that displays activity is
9
ActivityDisplay in components.
10
*/
11
12
import { CourseActions } from "../actions";
13
import { Map } from "immutable";
14
15
export class ActivityActions {
16
private actions: CourseActions;
17
private activity_id: number = -1;
18
19
constructor(actions: CourseActions) {
20
this.actions = actions;
21
}
22
23
set_activity = (
24
opts: { id: number; desc?: string } | { id?: number; desc: string },
25
): number => {
26
if (this.actions.is_closed()) return -1;
27
if (opts.id == null) {
28
this.activity_id += 1;
29
opts.id = this.activity_id;
30
}
31
const store = this.actions.get_store();
32
if (store == null) {
33
// course was closed
34
return -1;
35
}
36
let activity = store.get("activity");
37
if (opts.desc == null) {
38
activity = activity.delete(opts.id);
39
} else {
40
activity = activity.set(opts.id, opts.desc);
41
}
42
this.actions.setState({ activity });
43
return opts.id;
44
};
45
46
clear_activity = (id?: number): void => {
47
if (this.actions.is_closed()) return;
48
if (id != null) {
49
this.set_activity({ id }); // clears for this id since desc not provided
50
} else {
51
this.actions.setState({ activity: Map() }); // clear all activity
52
}
53
};
54
}
55
56