mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2026-02-06 09:56:03 +00:00
Add: load last autosave for /post/create
This commit is contained in:
parent
d07d2ba5b3
commit
f98ee6a1f6
@ -226,6 +226,12 @@ describe('Editor.vue', () => {
|
||||
const lastEditedId = localStorage.getItem('autosave:post:last')
|
||||
expect(lastEditedId).toMatch(/^[a-f\d]{8}$/)
|
||||
})
|
||||
|
||||
it('loads last edited autosave', () => {
|
||||
const wrapper = Wrapper()
|
||||
const { value: autosaveHTML } = getFirstInStorage()
|
||||
expect(wrapper.vm.editor.getHTML()).toBe(autosaveHTML)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when editing a comment', () => {
|
||||
|
||||
@ -7,14 +7,16 @@ export default class AutoSave extends Extension {
|
||||
super()
|
||||
|
||||
this.route = $route
|
||||
const { id, editorType } = AutoSave.for(this.route.path)
|
||||
const { id = hash(Date.now().toString(), 0xb0b).toString(16), editorType } = AutoSave.for(
|
||||
this.route.path,
|
||||
)
|
||||
this.id = id
|
||||
this.editorType = editorType
|
||||
}
|
||||
|
||||
static for(path) {
|
||||
if (path === '/post/create') {
|
||||
return { editorType: 'post', id: hash(Date.now().toString(), 0xb0b).toString(16) }
|
||||
return { editorType: 'post' }
|
||||
}
|
||||
|
||||
const commentMatch = path.match(/^\/post\/([0-9a-f-]*)\/[\w-]*$/)
|
||||
@ -33,7 +35,7 @@ export default class AutoSave extends Extension {
|
||||
}
|
||||
|
||||
static load(path) {
|
||||
const { id, editorType } = AutoSave.for(path)
|
||||
const { id = localStorage.getItem('autosave:post:last'), editorType } = AutoSave.for(path)
|
||||
const key = AutoSave.getStorageKey(id, editorType)
|
||||
return key ? localStorage[key] : null
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user