chore: remove localStorage-based persistence
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
defineProps<{
|
||||
updatedAt: string
|
||||
}>()
|
||||
|
||||
defineEmits<{
|
||||
restore: []
|
||||
discard: []
|
||||
}>()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="dialog-overlay" role="dialog" aria-modal="true" aria-labelledby="restore-draft-title">
|
||||
<div class="dialog">
|
||||
<h2 id="restore-draft-title">发现未保存的草稿</h2>
|
||||
<p>检测到本地保存的教案,最近更新时间:{{ updatedAt }}</p>
|
||||
<p>是否恢复上次编辑的内容?</p>
|
||||
<div class="dialog-actions">
|
||||
<button type="button" @click="$emit('restore')">恢复</button>
|
||||
<button type="button" @click="$emit('discard')">放弃</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,26 +0,0 @@
|
||||
import { beforeEach, describe, expect, it } from 'vitest'
|
||||
import { createEmptyBook } from '../domain/teachingDesign'
|
||||
import { clearStoredBook, loadStoredBook, saveBook } from './bookStorage'
|
||||
|
||||
describe('bookStorage', () => {
|
||||
beforeEach(() => localStorage.clear())
|
||||
|
||||
it('round-trips a versioned book', () => {
|
||||
const book = createEmptyBook()
|
||||
book.cover.courseName = 'Web 前端开发'
|
||||
|
||||
expect(saveBook(book)).toEqual({ ok: true })
|
||||
expect(loadStoredBook()?.cover.courseName).toBe('Web 前端开发')
|
||||
})
|
||||
|
||||
it('returns null for malformed storage', () => {
|
||||
localStorage.setItem('teaching-design-book', '{bad json')
|
||||
expect(loadStoredBook()).toBeNull()
|
||||
})
|
||||
|
||||
it('clears saved work', () => {
|
||||
saveBook(createEmptyBook())
|
||||
clearStoredBook()
|
||||
expect(loadStoredBook()).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -1,29 +0,0 @@
|
||||
import { BOOK_SCHEMA_VERSION, type TeachingBook } from '../domain/teachingDesign'
|
||||
|
||||
const STORAGE_KEY = 'teaching-design-book'
|
||||
|
||||
export type SaveResult = { ok: true } | { ok: false; message: string }
|
||||
|
||||
export function saveBook(book: TeachingBook): SaveResult {
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(book))
|
||||
return { ok: true }
|
||||
} catch {
|
||||
return { ok: false, message: '浏览器存储空间不足,当前修改尚未暂存。' }
|
||||
}
|
||||
}
|
||||
|
||||
export function loadStoredBook(): TeachingBook | null {
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEY)
|
||||
if (!raw) return null
|
||||
const parsed = JSON.parse(raw) as TeachingBook
|
||||
return parsed.schemaVersion === BOOK_SCHEMA_VERSION ? parsed : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export function clearStoredBook(): void {
|
||||
localStorage.removeItem(STORAGE_KEY)
|
||||
}
|
||||
Reference in New Issue
Block a user