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/app/store.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
import { redux, Store, TypedMap } from "@cocalc/frontend/app-framework";
7
import target from "@cocalc/frontend/client/handle-target";
8
import { parse_target } from "../history";
9
10
type TopTab =
11
| "about" // the "/help" page
12
| "account"
13
| "admin"
14
| "help" // i.e., the support dialog that makes a ZenDesk ticket....
15
| "project"
16
| "projects"
17
| "file-use"
18
| "notifications";
19
20
export type ConnectionStatus = "disconnected" | "connecting" | "connected";
21
22
export interface PageState {
23
active_top_tab: TopTab; // key of the active tab
24
show_connection: boolean;
25
ping?: number;
26
avgping?: number;
27
connection_status: ConnectionStatus;
28
connection_quality: "good" | "bad" | "flaky";
29
new_version?: TypedMap<{ version: number; min_version: number }>;
30
fullscreen?: "default" | "kiosk" | "project";
31
test?: string; // test query in the URL
32
cookie_warning: boolean;
33
local_storage_warning: boolean;
34
show_file_use: boolean;
35
num_ghost_tabs: number;
36
session?: string; // session query in the URL
37
last_status_time?: Date;
38
get_api_key?: string; // Set, e.g., when you visit https://cocalc.com/app?get_api_key=myapp -- see https://doc.cocalc.com/api/index.html#authentication
39
kiosk_project_id?: string;
40
41
// If true, a modal asking whether you want to use a project invite token appears.
42
// This is 100% for avoiding tricking a user into clicking on a link and silently
43
// adding them to a project. If they are explicitly on purpose trying to use a project
44
// invite token, then they will say yes. Otherwise, they will say no.
45
popconfirm?: {
46
title?;
47
description?;
48
open?: boolean;
49
ok?: boolean;
50
cancelText?: string;
51
okText?: string;
52
};
53
54
settingsModal?: string;
55
}
56
57
export class PageStore extends Store<PageState> {}
58
59
export function init_store() {
60
const DEFAULT_STATE: PageState = {
61
active_top_tab: parse_target(target).page as TopTab,
62
show_connection: false,
63
connection_status: "connecting",
64
connection_quality: "good",
65
cookie_warning: false,
66
local_storage_warning: false,
67
show_file_use: false,
68
num_ghost_tabs: 0,
69
} as const;
70
71
redux.createStore("page", PageStore, DEFAULT_STATE);
72
}
73
74