teqo-backup/src/lib/campaignLastActedMunicipality.ts
Cursor Agent dbf6a7fdce
B93 — wizard empty state continuity (visitados + última ação)
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>
2026-08-01 07:21:56 +00:00

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.
}
}