From f4062fee54570fae3977e363afaa605d5b0844ae Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 25 Feb 2018 22:56:23 +0900 Subject: [PATCH] #1145 --- .../views/components/messaging-room.form.vue | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/web/app/common/views/components/messaging-room.form.vue b/src/web/app/common/views/components/messaging-room.form.vue index 670040a57..9b5f1522f 100644 --- a/src/web/app/common/views/components/messaging-room.form.vue +++ b/src/web/app/common/views/components/messaging-room.form.vue @@ -36,8 +36,28 @@ export default Vue.extend({ sending: false }; }, + computed: { + draftId(): string { + return this.user.id; + } + }, + watch: { + text() { + this.saveDraft(); + }, + file() { + this.saveDraft(); + } + }, mounted() { autosize(this.$refs.textarea); + + // 書きかけの投稿を復元 + const draft = JSON.parse(localStorage.getItem('message_drafts') || '{}')[this.draftId]; + if (draft) { + this.text = draft.data.text; + this.file = draft.data.file; + } }, methods: { onPaste(e) { @@ -89,7 +109,30 @@ export default Vue.extend({ clear() { this.text = ''; this.file = null; - } + this.deleteDraft(); + }, + + saveDraft() { + const data = JSON.parse(localStorage.getItem('message_drafts') || '{}'); + + data[this.draftId] = { + updated_at: new Date(), + data: { + text: this.text, + file: this.file + } + } + + localStorage.setItem('message_drafts', JSON.stringify(data)); + }, + + deleteDraft() { + const data = JSON.parse(localStorage.getItem('message_drafts') || '{}'); + + delete data[this.draftId]; + + localStorage.setItem('message_drafts', JSON.stringify(data)); + }, } });