Files
faunosteo/src/state/practitionerCache.ts
T

30 lines
865 B
TypeScript

import {
PractitionerSchema,
type Practitioner,
} from '@/domain/schema/practitioner'
const STORAGE_KEY = 'osteo:lastPractitioner'
export function readCachedPractitioner(): Practitioner | undefined {
if (typeof localStorage === 'undefined') return undefined
const raw = localStorage.getItem(STORAGE_KEY)
if (!raw) return undefined
try {
const data = JSON.parse(raw)
const parsed = PractitionerSchema.safeParse(data)
return parsed.success ? parsed.data : undefined
} catch {
return undefined
}
}
export function writeCachedPractitioner(practitioner: Practitioner): void {
if (typeof localStorage === 'undefined') return
localStorage.setItem(STORAGE_KEY, JSON.stringify(practitioner))
}
export function clearPractitionerCache(): void {
if (typeof localStorage === 'undefined') return
localStorage.removeItem(STORAGE_KEY)
}