Path: blob/master/src/packages/frontend/app/store.ts
1496 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { redux, Store, TypedMap } from "@cocalc/frontend/app-framework";6import target from "@cocalc/frontend/client/handle-target";7import { parse_target } from "../history";8import type { ConatConnectionStatus } from "@cocalc/frontend/conat/client";910type TopTab =11| "about" // the "/help" page12| "account"13| "admin"14| "help" // i.e., the support dialog that makes a ZenDesk ticket....15| "project"16| "projects"17| "file-use"18| "notifications";1920export type ConnectionStatus = "disconnected" | "connecting" | "connected";2122export interface PageState {23active_top_tab: TopTab; // key of the active tab24show_connection: boolean;25ping?: number;26avgping?: number;27connection_status: ConnectionStatus;28connection_quality: "good" | "bad" | "flaky";29new_version?: TypedMap<{ version: number; min_version: number }>;30fullscreen?: "default" | "kiosk" | "project";31test?: string; // test query in the URL32cookie_warning: boolean;33local_storage_warning: boolean;34show_file_use: boolean;35num_ghost_tabs: number;36session?: string; // session query in the URL37last_status_time?: Date;38get_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#authentication39kiosk_project_id?: string;4041// 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 silently43// adding them to a project. If they are explicitly on purpose trying to use a project44// invite token, then they will say yes. Otherwise, they will say no.45popconfirm?: {46title?;47description?;48open?: boolean;49ok?: boolean;50cancelText?: string;51okText?: string;52};5354settingsModal?: string;55conat?: TypedMap<ConatConnectionStatus>;56}5758export class PageStore extends Store<PageState> {}5960export function init_store() {61const DEFAULT_STATE: PageState = {62active_top_tab: parse_target(target).page as TopTab,63show_connection: false,64connection_status: "connecting",65connection_quality: "good",66cookie_warning: false,67local_storage_warning: false,68show_file_use: false,69num_ghost_tabs: 0,70} as const;7172redux.createStore("page", PageStore, DEFAULT_STATE);73}747576