From 0600b738a9580c6867647d90d4c1e165653236b8 Mon Sep 17 00:00:00 2001 From: Yulia Hermak Date: Wed, 22 Nov 2023 23:13:27 +0000 Subject: [PATCH 1/9] =?UTF-8?q?feat:=20Save=20texts=20in=20input=20fields?= =?UTF-8?q?=E2=80=94message=20drafts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/AChat/AChatForm.vue | 15 +++++++++++ src/components/Chat/Chat.vue | 1 + src/store/index.js | 25 ++++++++++------- src/store/modules/draft-message/index.js | 34 ++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 src/store/modules/draft-message/index.js diff --git a/src/components/AChat/AChatForm.vue b/src/components/AChat/AChatForm.vue index 3d3baa78e..c33b72741 100644 --- a/src/components/AChat/AChatForm.vue +++ b/src/components/AChat/AChatForm.vue @@ -7,6 +7,7 @@ - @@ -485,7 +484,9 @@ export default { 'Windows 10': this.$t('chats.message_windows_10') }[detect().os] || this.$t('chats.message') - if (this.$route.query.replyToId) { + if (this.$store.getters['draftMessage/draftReplyTold'](this.partnerId)) { + this.replyMessageId = this.$store.getters['draftMessage/draftReplyTold'](this.partnerId) + } else if (this.$route.query.replyToId) { this.replyMessageId = this.$route.query.replyToId } }, @@ -512,6 +513,7 @@ export default { } }, sendMessage(message) { + this.$store.commit('draftMessage/deleteMessage', this.partnerId) const replyToId = this.replyMessageId > -1 ? this.replyMessageId : undefined return this.$store @@ -668,6 +670,10 @@ export default { this.replyMessageId = message.id this.$refs.chatForm.focus() + this.$store.commit('draftMessage/saveReplyToId', { + replyToId: message.id, + partnerId: this.partnerId + }) }, copyMessageToClipboard({ message }) { this.closeActionsMenu() diff --git a/src/store/modules/draft-message/index.js b/src/store/modules/draft-message/index.js index caf0c7a3b..4035d3aaa 100644 --- a/src/store/modules/draft-message/index.js +++ b/src/store/modules/draft-message/index.js @@ -3,8 +3,24 @@ const state = () => ({ }) const mutations = { + saveReplyToId(state, payload) { + if (state.drafts[payload.partnerId]) { + state.drafts[payload.partnerId].replyToId = payload.replyToId + } else { + state.drafts[payload.partnerId] = { + replyToId: payload.replyToId + } + } + }, + saveMessage(state, payload) { - state.drafts[payload.partnerId] = payload.message + if (state.drafts[payload.partnerId]) { + state.drafts[payload.partnerId].message = payload.message + } else { + state.drafts[payload.partnerId] = { + message: payload.message + } + } }, deleteMessage(state, partnerId) { @@ -16,7 +32,21 @@ const mutations = { } const getters = { draftMessage: (state) => (partnerId) => { - return state.drafts[partnerId] + const objMessage = state.drafts[partnerId] + if (objMessage === undefined) { + return '' + } else { + return objMessage.message + } + }, + + draftReplyTold: (state) => (partnerId) => { + const objMessage = state.drafts[partnerId] + if (objMessage === undefined) { + return '' + } else { + return objMessage.replyToId + } } } From c7afbed301b41a4a764ad72315ff802afd7c9163 Mon Sep 17 00:00:00 2001 From: Yulia Hermak Date: Thu, 30 Nov 2023 16:58:43 +0000 Subject: [PATCH 3/9] refactor(chat): move getter outside AChatForm --- src/components/AChat/AChatForm.vue | 3 --- src/components/Chat/Chat.vue | 4 +++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/components/AChat/AChatForm.vue b/src/components/AChat/AChatForm.vue index a6abb629d..19f36e5c2 100644 --- a/src/components/AChat/AChatForm.vue +++ b/src/components/AChat/AChatForm.vue @@ -126,9 +126,6 @@ export default { if (this.messageText) { this.message = this.messageText this.focus() - } else if (this.$store.getters['draftMessage/draftMessage'](this.partnerId)) { - this.message = this.$store.getters['draftMessage/draftMessage'](this.partnerId) - this.focus() } }, methods: { diff --git a/src/components/Chat/Chat.vue b/src/components/Chat/Chat.vue index 1e990e512..a735d638c 100644 --- a/src/components/Chat/Chat.vue +++ b/src/components/Chat/Chat.vue @@ -206,7 +206,9 @@ :send-on-enter="sendMessageOnEnter" :show-divider="true" :label="chatFormLabel" - :message-text="$route.query.messageText" + :message-text=" + $route.query.messageText || $store.getters['draftMessage/draftMessage'](this.partnerId) + " @message="onMessage" @error="onMessageError" @esc="replyMessageId = -1" From 8c86b3dd7892a5bb9ffdc1a2825a7d8db32b1f73 Mon Sep 17 00:00:00 2001 From: Yulia Hermak Date: Thu, 30 Nov 2023 18:33:23 +0000 Subject: [PATCH 4/9] refactor: changed variable names --- src/components/AChat/AChatForm.vue | 4 ++-- src/store/modules/draft-message/index.js | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/AChat/AChatForm.vue b/src/components/AChat/AChatForm.vue index 19f36e5c2..fd61f3c1a 100644 --- a/src/components/AChat/AChatForm.vue +++ b/src/components/AChat/AChatForm.vue @@ -7,7 +7,7 @@ (partnerId) => { const objMessage = state.drafts[partnerId] - if (objMessage === undefined) { - return '' - } else { + if (objMessage) { return objMessage.message + } else { + return '' } }, draftReplyTold: (state) => (partnerId) => { const objMessage = state.drafts[partnerId] - if (objMessage === undefined) { - return '' - } else { + if (objMessage) { return objMessage.replyToId + } else { + return '' } } } const actions = { resetState(context) { - context.commit('deleteAllSaveMessage') + context.commit('reset') } } export default { From aa31673ead5cdb13e8a76449720d49855711c3de Mon Sep 17 00:00:00 2001 From: Yulia Hermak Date: Sun, 3 Dec 2023 05:08:39 +0000 Subject: [PATCH 5/9] refactor: line space --- src/store/modules/draft-message/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/store/modules/draft-message/index.js b/src/store/modules/draft-message/index.js index 4872c893b..83f3018df 100644 --- a/src/store/modules/draft-message/index.js +++ b/src/store/modules/draft-message/index.js @@ -30,6 +30,7 @@ const mutations = { state.drafts = {} } } + const getters = { draftMessage: (state) => (partnerId) => { const objMessage = state.drafts[partnerId] @@ -55,6 +56,7 @@ const actions = { context.commit('reset') } } + export default { state, mutations, From c7cb539c6f4cb92c68489b5daaa55e8fb92a2799 Mon Sep 17 00:00:00 2001 From: Yulia Hermak Date: Wed, 10 Jan 2024 01:38:08 +0000 Subject: [PATCH 6/9] fix: rewritten on TS and corrected inaccuracies in functionality --- src/components/AChat/AChatForm.vue | 5 +- src/components/Chat/Chat.vue | 13 ++-- src/store/modules/draft-message/index.js | 66 ------------------- src/store/modules/draft-message/index.ts | 83 ++++++++++++++++++++++++ src/store/types.ts | 2 + 5 files changed, 98 insertions(+), 71 deletions(-) delete mode 100644 src/store/modules/draft-message/index.js create mode 100644 src/store/modules/draft-message/index.ts diff --git a/src/components/AChat/AChatForm.vue b/src/components/AChat/AChatForm.vue index fd61f3c1a..36eb30a4d 100644 --- a/src/components/AChat/AChatForm.vue +++ b/src/components/AChat/AChatForm.vue @@ -140,7 +140,10 @@ export default { if (error === false) { this.$emit('message', this.message) this.message = '' - this.$store.commit('draftMessage/deleteMessage', this.partnerId) + this.$store.commit('draftMessage/deleteMessage', { + message: this.message, + partnerId: this.partnerId + }) } else { this.$emit('error', error) } diff --git a/src/components/Chat/Chat.vue b/src/components/Chat/Chat.vue index a735d638c..80d4ebd76 100644 --- a/src/components/Chat/Chat.vue +++ b/src/components/Chat/Chat.vue @@ -226,7 +226,7 @@ @@ -488,8 +488,6 @@ export default { if (this.$store.getters['draftMessage/draftReplyTold'](this.partnerId)) { this.replyMessageId = this.$store.getters['draftMessage/draftReplyTold'](this.partnerId) - } else if (this.$route.query.replyToId) { - this.replyMessageId = this.$route.query.replyToId } }, methods: { @@ -514,8 +512,15 @@ export default { return } }, + cancelReplyMessage() { + this.replyMessageId = -1 + this.$store.commit('draftMessage/deleteReplyTold', { + replyToId: this.replyMessageId, + partnerId: this.partnerId + }) + }, sendMessage(message) { - this.$store.commit('draftMessage/deleteMessage', this.partnerId) + this.$store.dispatch('draftMessage/deleteWhenSend', { partnerId: this.partnerId }) const replyToId = this.replyMessageId > -1 ? this.replyMessageId : undefined return this.$store diff --git a/src/store/modules/draft-message/index.js b/src/store/modules/draft-message/index.js deleted file mode 100644 index 83f3018df..000000000 --- a/src/store/modules/draft-message/index.js +++ /dev/null @@ -1,66 +0,0 @@ -const state = () => ({ - drafts: {} -}) - -const mutations = { - saveReplyToId(state, payload) { - if (state.drafts[payload.partnerId]) { - state.drafts[payload.partnerId].replyToId = payload.replyToId - } else { - state.drafts[payload.partnerId] = { - replyToId: payload.replyToId - } - } - }, - - saveMessage(state, payload) { - if (state.drafts[payload.partnerId]) { - state.drafts[payload.partnerId].message = payload.message - } else { - state.drafts[payload.partnerId] = { - message: payload.message - } - } - }, - - deleteMessage(state, partnerId) { - state.drafts[partnerId] = '' - }, - reset(state) { - state.drafts = {} - } -} - -const getters = { - draftMessage: (state) => (partnerId) => { - const objMessage = state.drafts[partnerId] - if (objMessage) { - return objMessage.message - } else { - return '' - } - }, - - draftReplyTold: (state) => (partnerId) => { - const objMessage = state.drafts[partnerId] - if (objMessage) { - return objMessage.replyToId - } else { - return '' - } - } -} - -const actions = { - resetState(context) { - context.commit('reset') - } -} - -export default { - state, - mutations, - getters, - actions, - namespaced: true -} diff --git a/src/store/modules/draft-message/index.ts b/src/store/modules/draft-message/index.ts new file mode 100644 index 000000000..7525a070f --- /dev/null +++ b/src/store/modules/draft-message/index.ts @@ -0,0 +1,83 @@ +import { MutationTree, GetterTree, ActionTree } from 'vuex' +import { RootState } from '@/store/types' + +export interface DraftState { + drafts: { [key: string]: { replyToId?: string; message?: string } } +} + +const state = (): DraftState => ({ + drafts: {} +}) + +const mutations: MutationTree = { + saveReplyToId(state, payload: { partnerId: string; replyToId: string }) { + if (state.drafts[payload.partnerId]) { + state.drafts[payload.partnerId].replyToId = payload.replyToId + } else { + state.drafts[payload.partnerId] = { + replyToId: payload.replyToId + } + } + }, + + saveMessage(state, payload: { partnerId: string; message: string }) { + if (state.drafts[payload.partnerId]) { + state.drafts[payload.partnerId].message = payload.message + } else { + state.drafts[payload.partnerId] = { + message: payload.message + } + } + }, + + deleteReplyTold(state, payload: { partnerId: string; replyToId: string }) { + delete state.drafts[payload.partnerId].replyToId + }, + + deleteMessage(state, payload: { partnerId: string; message: string }) { + delete state.drafts[payload.partnerId].message + }, + + reset(state) { + state.drafts = {} + } +} + +const getters: GetterTree = { + draftMessage: (state) => (partnerId: string) => { + const objMessage = state.drafts[partnerId] + if (objMessage) { + return objMessage.message + } else { + return '' + } + }, + + draftReplyTold: (state) => (partnerId: string) => { + const objMessage = state.drafts[partnerId] + if (objMessage) { + return objMessage.replyToId + } else { + return '' + } + } +} + +const actions: ActionTree = { + resetState(context) { + context.commit('reset') + }, + + deleteWhenSend(context, payload: { partnerId: string }) { + context.commit('deleteReplyTold', payload) + context.commit('deleteMessage', payload) + } +} + +export default { + state, + mutations, + getters, + actions, + namespaced: true +} diff --git a/src/store/types.ts b/src/store/types.ts index 30d59aaa5..1083303cc 100644 --- a/src/store/types.ts +++ b/src/store/types.ts @@ -1,3 +1,4 @@ +import { DraftState } from '@/store/modules/draft-message' export interface RootState { address: string balance: number @@ -25,4 +26,5 @@ export interface RootState { identicon: any notification: any rate: any + draftMessage: DraftState } From 1c7f0ba024348750765b36f0856fef613132180a Mon Sep 17 00:00:00 2001 From: juliahermak <122323015+juliahermak@users.noreply.github.com> Date: Wed, 10 Jan 2024 02:13:35 +0000 Subject: [PATCH 7/9] Update src/components/Chat/Chat.vue Co-authored-by: bludnic --- src/components/Chat/Chat.vue | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/Chat/Chat.vue b/src/components/Chat/Chat.vue index 80d4ebd76..2a157c335 100644 --- a/src/components/Chat/Chat.vue +++ b/src/components/Chat/Chat.vue @@ -486,8 +486,9 @@ export default { 'Windows 10': this.$t('chats.message_windows_10') }[detect().os] || this.$t('chats.message') - if (this.$store.getters['draftMessage/draftReplyTold'](this.partnerId)) { - this.replyMessageId = this.$store.getters['draftMessage/draftReplyTold'](this.partnerId) + const draftMessage = this.$store.getters['draftMessage/draftReplyTold'](this.partnerId) + if (draftMessage) { + this.replyMessageId = draftMessage } }, methods: { From b87f658fd6f55757f1ac08e57a06333b5d3e3f71 Mon Sep 17 00:00:00 2001 From: Yulia Hermak Date: Wed, 10 Jan 2024 02:19:34 +0000 Subject: [PATCH 8/9] fix: refactor --- src/components/Chat/Chat.vue | 2 +- src/store/index.js | 1 - src/store/modules/draft-message/index.ts | 6 +----- src/store/types.ts | 1 + 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/components/Chat/Chat.vue b/src/components/Chat/Chat.vue index 80d4ebd76..27231bad5 100644 --- a/src/components/Chat/Chat.vue +++ b/src/components/Chat/Chat.vue @@ -520,7 +520,7 @@ export default { }) }, sendMessage(message) { - this.$store.dispatch('draftMessage/deleteWhenSend', { partnerId: this.partnerId }) + this.$store.dispatch('draftMessage/deleteDraft', { partnerId: this.partnerId }) const replyToId = this.replyMessageId > -1 ? this.replyMessageId : undefined return this.$store diff --git a/src/store/index.js b/src/store/index.js index 0edd934fc..da7f47127 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -134,7 +134,6 @@ const store = { }, logout({ dispatch }) { dispatch('reset') - dispatch('draftMessage/resetState', null, { root: true }) }, unlock({ state, dispatch }) { // user updated an app, F5 or something diff --git a/src/store/modules/draft-message/index.ts b/src/store/modules/draft-message/index.ts index 7525a070f..4f3165e07 100644 --- a/src/store/modules/draft-message/index.ts +++ b/src/store/modules/draft-message/index.ts @@ -64,11 +64,7 @@ const getters: GetterTree = { } const actions: ActionTree = { - resetState(context) { - context.commit('reset') - }, - - deleteWhenSend(context, payload: { partnerId: string }) { + deleteDraft(context, payload: { partnerId: string }) { context.commit('deleteReplyTold', payload) context.commit('deleteMessage', payload) } diff --git a/src/store/types.ts b/src/store/types.ts index 1083303cc..172d6783d 100644 --- a/src/store/types.ts +++ b/src/store/types.ts @@ -1,4 +1,5 @@ import { DraftState } from '@/store/modules/draft-message' + export interface RootState { address: string balance: number From 6b9c6442e38bef42f7b888d6eb71e9c814211664 Mon Sep 17 00:00:00 2001 From: Yulia Hermak Date: Thu, 11 Jan 2024 19:50:01 +0000 Subject: [PATCH 9/9] fix: draftMessage - resetState --- src/store/index.js | 1 + src/store/modules/draft-message/index.ts | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/store/index.js b/src/store/index.js index da7f47127..0edd934fc 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -134,6 +134,7 @@ const store = { }, logout({ dispatch }) { dispatch('reset') + dispatch('draftMessage/resetState', null, { root: true }) }, unlock({ state, dispatch }) { // user updated an app, F5 or something diff --git a/src/store/modules/draft-message/index.ts b/src/store/modules/draft-message/index.ts index 4f3165e07..f6699450a 100644 --- a/src/store/modules/draft-message/index.ts +++ b/src/store/modules/draft-message/index.ts @@ -64,6 +64,10 @@ const getters: GetterTree = { } const actions: ActionTree = { + resetState(context) { + context.commit('reset') + }, + deleteDraft(context, payload: { partnerId: string }) { context.commit('deleteReplyTold', payload) context.commit('deleteMessage', payload)