Files
recall/src/lib/drafts.ts
Daniel Arroyo a40ab18b1b feat: MVP-5 Sprint 3 - Sidebar, Work Mode, and Drafts
- Enhance note-connections with collapsible sections and recent versions
- Add work mode toggle in header for focused work
- Add draft autosave with 7-day TTL and recovery banner
- Save drafts on changes for new notes
2026-03-22 18:28:14 -03:00

37 lines
965 B
TypeScript

const DRAFT_KEY_PREFIX = 'recall_draft_'
const DRAFT_TTL = 7 * 24 * 60 * 60 * 1000 // 7 days
interface Draft {
title: string
content: string
type: string
tags: string[]
savedAt: number
}
export function saveDraft(noteId: string, data: Draft): void {
if (typeof window === 'undefined') return
localStorage.setItem(DRAFT_KEY_PREFIX + noteId, JSON.stringify({ ...data, savedAt: Date.now() }))
}
export function loadDraft(noteId: string): Draft | null {
if (typeof window === 'undefined') return null
const stored = localStorage.getItem(DRAFT_KEY_PREFIX + noteId)
if (!stored) return null
try {
const draft = JSON.parse(stored) as Draft
if (Date.now() - draft.savedAt > DRAFT_TTL) {
deleteDraft(noteId)
return null
}
return draft
} catch {
return null
}
}
export function deleteDraft(noteId: string): void {
if (typeof window === 'undefined') return
localStorage.removeItem(DRAFT_KEY_PREFIX + noteId)
}