From e4620291a72f29afe43efb25eb35d3652d115525 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 4 Oct 2023 17:46:57 +0530 Subject: [PATCH] feat: setup inReplyTo store --- .../dashboard/constants/localStorage.js | 1 + .../dashboard/store/modules/draftMessages.js | 19 +++++++++++++++++++ .../dashboard/store/mutation-types.js | 2 ++ 3 files changed, 22 insertions(+) diff --git a/app/javascript/dashboard/constants/localStorage.js b/app/javascript/dashboard/constants/localStorage.js index 21360e178..c864b925b 100644 --- a/app/javascript/dashboard/constants/localStorage.js +++ b/app/javascript/dashboard/constants/localStorage.js @@ -2,6 +2,7 @@ export const LOCAL_STORAGE_KEYS = { DISMISSED_UPDATES: 'dismissedUpdates', WIDGET_BUILDER: 'widgetBubble_', DRAFT_MESSAGES: 'draftMessages', + MESSAGE_IN_REPLY_TO: 'messageInReplyTo', COLOR_SCHEME: 'color_scheme', DISMISSED_LABEL_SUGGESTIONS: 'labelSuggestionsDismissed', }; diff --git a/app/javascript/dashboard/store/modules/draftMessages.js b/app/javascript/dashboard/store/modules/draftMessages.js index 28a4fb3e0..89494839a 100644 --- a/app/javascript/dashboard/store/modules/draftMessages.js +++ b/app/javascript/dashboard/store/modules/draftMessages.js @@ -7,6 +7,7 @@ import { LOCAL_STORAGE_KEYS } from 'dashboard/constants/localStorage'; const state = { records: LocalStorage.get(LOCAL_STORAGE_KEYS.DRAFT_MESSAGES) || {}, + inReplyTo: LocalStorage.get(LOCAL_STORAGE_KEYS.MESSAGE_IN_REPLY_TO) || {}, replyEditorMode: REPLY_EDITOR_MODES.REPLY, }; @@ -14,6 +15,9 @@ export const getters = { get: _state => key => { return _state.records[key] || ''; }, + getInReplyTo: _state => key => { + return _state.inReplyTo[key]; + }, getReplyEditorMode: _state => _state.replyEditorMode, }; @@ -24,6 +28,12 @@ export const actions = { delete: ({ commit }, { key }) => { commit(types.SET_DRAFT_MESSAGES, { key }); }, + setInReplyTo({ commit }, { key, inReplyTo }) { + commit(types.SET_IN_REPLY_TO, { key, inReplyTo }); + }, + deleteInReplyTo({ commit }, { key }) { + commit(types.REMOVE_IN_REPLY_TO, { key }); + }, setReplyEditorMode: ({ commit }, { mode }) => { commit(types.SET_REPLY_EDITOR_MODE, { mode }); }, @@ -39,6 +49,15 @@ export const mutations = { Vue.set($state, 'records', updatedRecords); LocalStorage.set(LOCAL_STORAGE_KEYS.DRAFT_MESSAGES, $state.records); }, + [types.SET_IN_REPLY_TO]($state, { key, inReplyTo }) { + Vue.set($state.inReplyTo, key, inReplyTo); + LocalStorage.set(LOCAL_STORAGE_KEYS.MESSAGE_IN_REPLY_TO, $state.inReplyTo); + }, + [types.REMOVE_IN_REPLY_TO]($state, { key }) { + const { [key]: draftToBeRemoved, ...newRecords } = $state.inReplyTo; + Vue.set($state, 'inReplyTo', newRecords); + LocalStorage.set(LOCAL_STORAGE_KEYS.DRAFT_MESSAGES, $state.inReplyTo); + }, [types.SET_REPLY_EDITOR_MODE]($state, { mode }) { Vue.set($state, 'replyEditorMode', mode); }, diff --git a/app/javascript/dashboard/store/mutation-types.js b/app/javascript/dashboard/store/mutation-types.js index 9ba841342..9c13cd1d5 100644 --- a/app/javascript/dashboard/store/mutation-types.js +++ b/app/javascript/dashboard/store/mutation-types.js @@ -28,6 +28,8 @@ export default { SET_DRAFT_MESSAGES: 'SET_DRAFT_MESSAGES', REMOVE_DRAFT_MESSAGES: 'REMOVE_DRAFT_MESSAGES', SET_REPLY_EDITOR_MODE: 'SET_REPLY_EDITOR_MODE', + SET_IN_REPLY_TO: 'SET_IN_REPLY_TO', + REMOVE_IN_REPLY_TO: 'REMOVE_IN_REPLY_TO', SET_CURRENT_CHAT_WINDOW: 'SET_CURRENT_CHAT_WINDOW', CLEAR_CURRENT_CHAT_WINDOW: 'CLEAR_CURRENT_CHAT_WINDOW',