You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.9 KiB
75 lines
1.9 KiB
// The backend can still report `pending_info` for a short moment after a match
|
|
// request is accepted. Without a grace window the user is bounced from
|
|
// /finding-match straight back to /questions-list.
|
|
//
|
|
// This lives in sessionStorage on purpose: it must not survive a WebView
|
|
// restart the way the old `match_submitted` localStorage flag did, because a
|
|
// sticky flag shadows the real profile status forever.
|
|
|
|
const STORAGE_KEY = "marriage:match-start-at";
|
|
const LEGACY_STORAGE_KEY = "match_submitted";
|
|
const GRACE_MS = 60_000;
|
|
|
|
export function markMatchStarted() {
|
|
if (typeof window === "undefined") {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
window.sessionStorage.setItem(STORAGE_KEY, String(Date.now()));
|
|
} catch {
|
|
// Storage can throw in private mode or when the quota is exhausted.
|
|
}
|
|
}
|
|
|
|
export function isWithinMatchStartGrace() {
|
|
if (typeof window === "undefined") {
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
const rawValue = window.sessionStorage.getItem(STORAGE_KEY);
|
|
|
|
if (!rawValue) {
|
|
return false;
|
|
}
|
|
|
|
const startedAt = Number(rawValue);
|
|
|
|
if (!Number.isFinite(startedAt) || Date.now() - startedAt > GRACE_MS) {
|
|
window.sessionStorage.removeItem(STORAGE_KEY);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export function clearMatchStartGrace() {
|
|
if (typeof window === "undefined") {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
window.sessionStorage.removeItem(STORAGE_KEY);
|
|
} catch {
|
|
// Ignore storage failures – the grace window expires on its own anyway.
|
|
}
|
|
}
|
|
|
|
// Older builds wrote a `match_submitted` flag to localStorage and never removed
|
|
// it, which pinned affected users to /finding-match permanently. Drop it on boot
|
|
// so devices already carrying the flag recover without a manual data clear.
|
|
export function clearLegacyMatchSubmittedFlag() {
|
|
if (typeof window === "undefined") {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
window.localStorage.removeItem(LEGACY_STORAGE_KEY);
|
|
} catch {
|
|
// Ignore storage failures.
|
|
}
|
|
}
|