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
This commit is contained in:
36
src/lib/drafts.ts
Normal file
36
src/lib/drafts.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user