Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/course/activity/actions.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/* Showing what is currently happening to the user67The actual react component that displays activity is8ActivityDisplay in components.9*/1011import { CourseActions } from "../actions";12import { Map } from "immutable";1314export class ActivityActions {15private actions: CourseActions;16private activity_id: number = -1;1718constructor(actions: CourseActions) {19this.actions = actions;20}2122set_activity = (23opts: { id: number; desc?: string } | { id?: number; desc: string },24): number => {25if (this.actions.is_closed()) return -1;26if (opts.id == null) {27this.activity_id += 1;28opts.id = this.activity_id;29}30const store = this.actions.get_store();31if (store == null) {32// course was closed33return -1;34}35let activity = store.get("activity");36if (opts.desc == null) {37activity = activity.delete(opts.id);38} else {39activity = activity.set(opts.id, opts.desc);40}41this.actions.setState({ activity });42return opts.id;43};4445clear_activity = (id?: number): void => {46if (this.actions.is_closed()) return;47if (id != null) {48this.set_activity({ id }); // clears for this id since desc not provided49} else {50this.actions.setState({ activity: Map() }); // clear all activity51}52};53}545556