Path: blob/master/src/packages/frontend/cookie-consent/state.ts
14422 views
/*1* This file is part of CoCalc: Copyright © 2026 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45// Tiny shared-state module so ./init can flip flags that ./index reads,6// without a circular import. Importing this module is side-effect free.7//8// Three observable states:9// undecided → customize hasn't loaded yet, we don't know if the banner10// will activate. Gate helpers should be conservative (treat11// as "not yet acknowledged") so modals like verify-email12// don't render on top of a banner that's about to appear.13// active → initCookieConsent ran with enabled=true; v3 runtime is up.14// decided-disabled → admin has the banner off; helpers pass through.1516const EVENT_NAME = "cc:internalStateChange";1718let active = false;19let decided = false;2021function emit(): void {22if (typeof window !== "undefined") {23window.dispatchEvent(new Event(EVENT_NAME));24}25}2627export function markBannerActive(): void {28active = true;29decided = true;30emit();31}3233export function markBannerDecidedDisabled(): void {34// active stays false. decided=true tells helpers to stop being conservative.35decided = true;36emit();37}3839export function isBannerActive(): boolean {40return active;41}4243export function isBannerDecided(): boolean {44return decided;45}4647export const BANNER_STATE_EVENT = EVENT_NAME;484950