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