fix: prevent saving empty drafts to localStorage

This commit is contained in:
csr4422
2025-11-28 13:19:06 +05:30
parent f452e0279e
commit bd092c5b1e
+8 -6
View File
@@ -19,7 +19,6 @@ export const useDraftStore = defineStore('drafts', () => {
write: (v) => JSON.stringify(v)
}
})
const getDraft = (uuid) => {
if (!uuid) return { htmlContent: '', textContent: '' }
return drafts.value[uuid] || { htmlContent: '', textContent: '' }
@@ -28,12 +27,15 @@ export const useDraftStore = defineStore('drafts', () => {
const setDraft = (uuid, htmlContent, textContent) => {
if (!uuid) return
const isEmpty = (!htmlContent || htmlContent.trim() === '') &&
(!textContent || textContent.trim() === '')
if (isEmpty) return
drafts.value[uuid] = {
htmlContent,
textContent,
timestamp: Date.now()
}
htmlContent,
textContent,
timestamp: Date.now()
}
const keys = Object.keys(drafts.value)
if (keys.length > MAX_ENTRIES) {
const sorted = keys