Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/cookie-consent/state.ts
14422 views
1
/*
2
* This file is part of CoCalc: Copyright © 2026 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
// Tiny shared-state module so ./init can flip flags that ./index reads,
7
// without a circular import. Importing this module is side-effect free.
8
//
9
// Three observable states:
10
// undecided → customize hasn't loaded yet, we don't know if the banner
11
// will activate. Gate helpers should be conservative (treat
12
// as "not yet acknowledged") so modals like verify-email
13
// don't render on top of a banner that's about to appear.
14
// active → initCookieConsent ran with enabled=true; v3 runtime is up.
15
// decided-disabled → admin has the banner off; helpers pass through.
16
17
const EVENT_NAME = "cc:internalStateChange";
18
19
let active = false;
20
let decided = false;
21
22
function emit(): void {
23
if (typeof window !== "undefined") {
24
window.dispatchEvent(new Event(EVENT_NAME));
25
}
26
}
27
28
export function markBannerActive(): void {
29
active = true;
30
decided = true;
31
emit();
32
}
33
34
export function markBannerDecidedDisabled(): void {
35
// active stays false. decided=true tells helpers to stop being conservative.
36
decided = true;
37
emit();
38
}
39
40
export function isBannerActive(): boolean {
41
return active;
42
}
43
44
export function isBannerDecided(): boolean {
45
return decided;
46
}
47
48
export const BANNER_STATE_EVENT = EVENT_NAME;
49
50