diff --git a/webapp/components/Editor/Editor.story.js b/webapp/components/Editor/Editor.story.js
index c7521a131..38c080a54 100644
--- a/webapp/components/Editor/Editor.story.js
+++ b/webapp/components/Editor/Editor.story.js
@@ -36,18 +36,7 @@ const users = [
storiesOf('Editor', module)
.addDecorator(withA11y)
- .addDecorator(StoryRouter())
- .addDecorator((storyFn) => {
- const ctx = storyFn()
- return {
- components: { ctx },
- template: `
-
-
-
- `,
- }
- })
+ .addDecorator(helpers.wrapInCard)
.addDecorator(helpers.layout)
.add('Empty', () => ({
components: { HcEditor },
@@ -150,3 +139,43 @@ storiesOf('Editor', module)
}),
template: ``,
}))
+
+storiesOf('Editor/AutoSave', module)
+ .addDecorator(
+ StoryRouter(
+ {},
+ {
+ initialEntry: '/post/create',
+ },
+ ),
+ )
+ .addDecorator(helpers.wrapInCard)
+ .addDecorator(helpers.layout)
+ .add('creating a post', () => ({
+ components: { HcEditor },
+ store: helpers.store,
+ data: () => ({
+ users,
+ }),
+ template: ``,
+ }))
+
+storiesOf('Editor/AutoSave', module)
+ .addDecorator(
+ StoryRouter(
+ {},
+ {
+ initialEntry: '/post/f00-b00-1d/post-slug-I-comment-on',
+ },
+ ),
+ )
+ .addDecorator(helpers.wrapInCard)
+ .addDecorator(helpers.layout)
+ .add('creating a comment', () => ({
+ components: { HcEditor },
+ store: helpers.store,
+ data: () => ({
+ users,
+ }),
+ template: ``,
+ }))
diff --git a/webapp/components/Editor/plugins/autoSave.js b/webapp/components/Editor/plugins/autoSave.js
index e90b4e1e3..a839b6a95 100644
--- a/webapp/components/Editor/plugins/autoSave.js
+++ b/webapp/components/Editor/plugins/autoSave.js
@@ -7,9 +7,10 @@ export default class AutoSave extends Extension {
super()
this.route = $route
- const { id = hash(Date.now().toString(), 0xb0b).toString(16), editorType } = AutoSave.fromPath(
- this.route.path,
- )
+ const {
+ id = hash(Date.now().toString(), 0xb0b).toString(16),
+ editorType = this.route.path,
+ } = AutoSave.fromPath(this.route.path)
this.id = id
this.editorType = editorType
}
@@ -35,9 +36,13 @@ export default class AutoSave extends Extension {
}
static load(path) {
- const { id = localStorage.getItem('autosave:post:last'), editorType } = AutoSave.fromPath(path)
- const key = AutoSave.getStorageKey(id, editorType)
- return key ? localStorage[key] : null
+ const { id, editorType = path } = AutoSave.fromPath(path)
+ const _id = localStorage.getItem(`autosave:${editorType}:last`)
+ if (!_id) {
+ return null
+ }
+ const key = AutoSave.getStorageKey(_id, editorType)
+ return localStorage[key]
}
static getStorageKey(id, editorType) {
@@ -62,9 +67,7 @@ export default class AutoSave extends Extension {
this.storageKey,
AutoSave.toHTML(tr.doc.content, editorState.config.schema),
)
- if (this.editorType === 'post') {
- localStorage.setItem('autosave:post:last', this.id)
- }
+ localStorage.setItem(`autosave:${this.editorType}:last`, this.id)
}
return tr
},
diff --git a/webapp/storybook/helpers.js b/webapp/storybook/helpers.js
index 677a2bf94..aa51e162f 100644
--- a/webapp/storybook/helpers.js
+++ b/webapp/storybook/helpers.js
@@ -57,6 +57,17 @@ const helpers = {
`,
}
},
+ wrapInCard(storyFn) {
+ const ctx = storyFn()
+ return {
+ components: { ctx },
+ template: `
+
+
+
+ `,
+ }
+ }
}
export default helpers