mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-15 10:43:07 +00:00
Merge client-side recent visits and last-acted municipality storage into wizard municipality suggest idle list ahead of B92 server rankings. - Add campaignLastActedMunicipality + wizardMunicipalitySuggestMerge libs - Extend wizard-municipality-suggest with scopeMunicipalities for hit lookup - Record last-acted on wizard write success (votes, signal, trend, leadership) - Clear last-acted on logout alongside recent visits Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
/** Device-local last municipality where the staff actor completed a wizard write. */
|
|
|
|
export const LAST_ACTED_MUNICIPALITY_STORAGE_KEY = 'teqo:campaign:last-acted-municipality'
|
|
|
|
const isStoredSlug = (value: unknown): value is string =>
|
|
typeof value === 'string' && value.trim().length > 0
|
|
|
|
export const getLastActedMunicipalitySlug = (): string | null => {
|
|
if (typeof window === 'undefined') return null
|
|
try {
|
|
const raw = localStorage.getItem(LAST_ACTED_MUNICIPALITY_STORAGE_KEY)
|
|
if (!raw) return null
|
|
const parsed: unknown = JSON.parse(raw)
|
|
if (isStoredSlug(parsed)) return parsed.trim()
|
|
return null
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
export const recordLastActedMunicipality = (slug: string): void => {
|
|
if (typeof window === 'undefined') return
|
|
const trimmed = slug.trim()
|
|
if (!trimmed) return
|
|
try {
|
|
localStorage.setItem(LAST_ACTED_MUNICIPALITY_STORAGE_KEY, JSON.stringify(trimmed))
|
|
} catch {
|
|
// Ignore quota / private-mode failures.
|
|
}
|
|
}
|
|
|
|
export const clearLastActedMunicipality = (): void => {
|
|
if (typeof window === 'undefined') return
|
|
try {
|
|
localStorage.removeItem(LAST_ACTED_MUNICIPALITY_STORAGE_KEY)
|
|
} catch {
|
|
// Ignore private-mode failures.
|
|
}
|
|
}
|