Files
motor-de-encuestas/lib/storage.ts
2026-06-02 10:27:52 -03:00

28 lines
710 B
TypeScript

import type { FormAnswers } from './types'
const PREFIX = 'survey_draft_'
// Only store answer data — nothing identifiable about the respondent.
export function saveDraft(surveyId: string, answers: FormAnswers): void {
try {
localStorage.setItem(PREFIX + surveyId, JSON.stringify(answers))
} catch {
// Storage quota or private-mode — silently ignore
}
}
export function loadDraft(surveyId: string): FormAnswers {
try {
const raw = localStorage.getItem(PREFIX + surveyId)
return raw ? (JSON.parse(raw) as FormAnswers) : {}
} catch {
return {}
}
}
export function clearDraft(surveyId: string): void {
try {
localStorage.removeItem(PREFIX + surveyId)
} catch {}
}