import { CourseActions } from "../actions";
import { Map } from "immutable";
export class ActivityActions {
private actions: CourseActions;
private activity_id: number = -1;
constructor(actions: CourseActions) {
this.actions = actions;
}
set_activity = (
opts: { id: number; desc?: string } | { id?: number; desc: string },
): number => {
if (this.actions.is_closed()) return -1;
if (opts.id == null) {
this.activity_id += 1;
opts.id = this.activity_id;
}
const store = this.actions.get_store();
if (store == null) {
return -1;
}
let activity = store.get("activity");
if (opts.desc == null) {
activity = activity.delete(opts.id);
} else {
activity = activity.set(opts.id, opts.desc);
}
this.actions.setState({ activity });
return opts.id;
};
clear_activity = (id?: number): void => {
if (this.actions.is_closed()) return;
if (id != null) {
this.set_activity({ id });
} else {
this.actions.setState({ activity: Map() });
}
};
}