Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/browser.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 } from "./app-framework";
7
8
// Calling set_window_title will set the title, but also put a notification
9
// count to the left of the title; if called with no arguments just updates
10
// the count, maintaining the previous title.
11
export function notifyCount() {
12
const mentions = redux.getStore("mentions");
13
const account = redux.getStore("account");
14
const news = redux.getStore("news");
15
// we always count balance_alert as "1", since we don't even
16
// know how many of them there are until querying stripe.
17
return (
18
(mentions?.getUnreadSize() ?? 0) +
19
(account?.get("unread_message_count") ?? 0) +
20
(news?.get("unread") ?? 0) +
21
(account?.get("balance_alert") ? 1 : 0)
22
);
23
}
24
25
let last_title: string = "";
26
27
export function set_window_title(title?: string): void {
28
if (title == null) {
29
title = last_title;
30
}
31
last_title = title;
32
const u = notifyCount();
33
if (u) {
34
title = `(${u}) ${title}`;
35
}
36
const site_name = redux.getStore("customize").get("site_name");
37
if (title.length > 0) {
38
document.title = title + " - " + site_name;
39
} else {
40
document.title = site_name;
41
}
42
}
43
44