From 0cab127a586ef96e38fc4d7ebb000d87196e70ab Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 10 Mar 2017 09:30:43 +0900 Subject: [PATCH] wip #258 --- src/web/app/desktop/tags/post-form.tag | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/web/app/desktop/tags/post-form.tag b/src/web/app/desktop/tags/post-form.tag index 39b6e0f20..bc99e0c0a 100644 --- a/src/web/app/desktop/tags/post-form.tag +++ b/src/web/app/desktop/tags/post-form.tag @@ -333,6 +333,12 @@ this.autocomplete = new this.Autocomplete(this.refs.text); this.autocomplete.attach(); + + let draft = localStorage.getItem('post-draft'); + if (draft) { + draft = JSON.parse(draft); + this.refs.text.value = draft.text; + } }); this.on('unmount', () => { @@ -446,6 +452,7 @@ reply_to_id: this.inReplyToPost ? this.inReplyToPost.id : undefined, poll: this.poll ? this.refs.poll.get() : undefined }).then(data => { + localStorage.removeItem('post-draft'); this.trigger('post'); this.notify(this.inReplyToPost ? '返信しました!' : '投稿しました!'); }).catch(err => { @@ -460,5 +467,19 @@ this.cat = () => { this.refs.text.value += getCat(); }; + + this.on('update', () => { + this.save(); + }); + + this.save = () => { + const context = { + text: this.refs.text.value, + files: this.files, + poll: this.poll ? this.refs.poll.get() : undefined + }; + + localStorage.setItem('post-draft', JSON.stringify(context)); + };