Terminado sprint 2A
This commit is contained in:
27
lib/storage.ts
Normal file
27
lib/storage.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
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 {}
|
||||
}
|
||||
Reference in New Issue
Block a user