57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
/**
|
|
* Shared, in-memory state for the interests onboarding's nudge, so the
|
|
* profile tab's dot (QuickNav), the banner, and the Profile card agree
|
|
* without each re-reading settings. The stored truth is
|
|
* `settings.onboardingState` (src/libs/onboarding.ts); this mirrors it.
|
|
*/
|
|
|
|
import { reactive } from "vue";
|
|
|
|
import { isNudgeOn, parseOnboardingState } from "@/libs/onboarding";
|
|
|
|
export const onboardingNudge = reactive({
|
|
/** Set by the first {@link refreshNudge} of this launch. */
|
|
loaded: false,
|
|
/** The red dot on the profile tab. */
|
|
on: false,
|
|
/** The dot's pulse while the banner shows. */
|
|
pulse: false,
|
|
});
|
|
|
|
/**
|
|
* Module state lives for one launch of the app, so this is how the prompt's
|
|
* "x" waits for the next cold start instead of the next visit to Home.
|
|
*/
|
|
let interestsPromptShownThisLaunch = false;
|
|
|
|
export function markInterestsPromptShown(): void {
|
|
interestsPromptShownThisLaunch = true;
|
|
}
|
|
|
|
export function wasInterestsPromptShown(): boolean {
|
|
return interestsPromptShownThisLaunch;
|
|
}
|
|
|
|
export function refreshNudge(settings: {
|
|
onboardingState?: string;
|
|
isRegistered?: boolean;
|
|
}): void {
|
|
onboardingNudge.loaded = true;
|
|
onboardingNudge.on = isNudgeOn(
|
|
parseOnboardingState(settings.onboardingState),
|
|
!!settings.isRegistered,
|
|
);
|
|
}
|
|
|
|
export function setNudgeOn(on: boolean): void {
|
|
onboardingNudge.on = on;
|
|
if (!on) onboardingNudge.pulse = false;
|
|
}
|
|
|
|
export function pulseNudge(ms: number): void {
|
|
onboardingNudge.pulse = true;
|
|
setTimeout(() => {
|
|
onboardingNudge.pulse = false;
|
|
}, ms);
|
|
}
|