From 27e36dbc2ef9664d0acccb47dee36fe94a9dd4b8 Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 5 Apr 2023 13:01:37 -0600 Subject: [PATCH] Move postStatus module to store --- .../mobile_post_status_button.js | 3 ++- .../post_status_modal/post_status_modal.js | 7 +++--- src/components/user_card/user_card.js | 3 ++- src/main.js | 2 -- src/modules/postStatus.js | 25 ------------------- src/stores/postStatus.js | 17 +++++++++++++ 6 files changed, 25 insertions(+), 32 deletions(-) delete mode 100644 src/modules/postStatus.js create mode 100644 src/stores/postStatus.js diff --git a/src/components/mobile_post_status_button/mobile_post_status_button.js b/src/components/mobile_post_status_button/mobile_post_status_button.js index f7f96cd6..9a8af455 100644 --- a/src/components/mobile_post_status_button/mobile_post_status_button.js +++ b/src/components/mobile_post_status_button/mobile_post_status_button.js @@ -3,6 +3,7 @@ import { library } from '@fortawesome/fontawesome-svg-core' import { faPen } from '@fortawesome/free-solid-svg-icons' +import { usePostStatusStore } from '../../stores/postStatus' library.add( faPen @@ -71,7 +72,7 @@ const MobilePostStatusButton = { window.removeEventListener('scroll', this.handleScrollEnd) }, openPostForm () { - this.$store.dispatch('openPostStatusModal') + usePostStatusStore().openPostStatusModal() }, handleOSK () { // This is a big hack: we're guessing from changed window sizes if the diff --git a/src/components/post_status_modal/post_status_modal.js b/src/components/post_status_modal/post_status_modal.js index b44354db..fb7436ab 100644 --- a/src/components/post_status_modal/post_status_modal.js +++ b/src/components/post_status_modal/post_status_modal.js @@ -1,6 +1,7 @@ import PostStatusForm from '../post_status_form/post_status_form.vue' import Modal from '../modal/modal.vue' import get from 'lodash/get' +import { usePostStatusStore } from '../../stores/postStatus' const PostStatusModal = { components: { @@ -17,13 +18,13 @@ const PostStatusModal = { return !!this.$store.state.users.currentUser }, modalActivated () { - return this.$store.state.postStatus.modalActivated + return usePostStatusStore().modalActivated }, isFormVisible () { return this.isLoggedIn && !this.resettingForm && this.modalActivated }, params () { - return this.$store.state.postStatus.params || {} + return usePostStatusStore().params || {} } }, watch: { @@ -43,7 +44,7 @@ const PostStatusModal = { }, methods: { closeModal () { - this.$store.dispatch('closePostStatusModal') + usePostStatusStore().closePostStatusModal() } } } diff --git a/src/components/user_card/user_card.js b/src/components/user_card/user_card.js index e17bf8eb..ccbe9ce7 100644 --- a/src/components/user_card/user_card.js +++ b/src/components/user_card/user_card.js @@ -12,6 +12,7 @@ import RichContent from 'src/components/rich_content/rich_content.jsx' import ConfirmModal from '../confirm_modal/confirm_modal.vue' import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator' import { mapGetters } from 'vuex' +import { usePostStatusStore } from '../../stores/postStatus' import { library } from '@fortawesome/fontawesome-svg-core' import { faBell, @@ -225,7 +226,7 @@ export default { this.$store.dispatch('setCurrentMedia', attachment) }, mentionUser () { - this.$store.dispatch('openPostStatusModal', { replyTo: true, repliedUser: this.user }) + usePostStatusStore().openPostStatusModal({ replyTo: true, repliedUser: this.user }) }, onAvatarClickHandler (e) { if (this.onAvatarClick) { diff --git a/src/main.js b/src/main.js index ee0adcb6..4ba68929 100644 --- a/src/main.js +++ b/src/main.js @@ -19,7 +19,6 @@ import mediaViewerModule from './modules/media_viewer.js' import oauthTokensModule from './modules/oauth_tokens.js' import reportsModule from './modules/reports.js' import pollsModule from './modules/polls.js' -import postStatusModule from './modules/postStatus.js' import editStatusModule from './modules/editStatus.js' import statusHistoryModule from './modules/statusHistory.js' @@ -84,7 +83,6 @@ const persistedStateOptions = { oauthTokens: oauthTokensModule, reports: reportsModule, polls: pollsModule, - postStatus: postStatusModule, editStatus: editStatusModule, statusHistory: statusHistoryModule, chats: chatsModule, diff --git a/src/modules/postStatus.js b/src/modules/postStatus.js deleted file mode 100644 index 638c1fb2..00000000 --- a/src/modules/postStatus.js +++ /dev/null @@ -1,25 +0,0 @@ -const postStatus = { - state: { - params: null, - modalActivated: false - }, - mutations: { - openPostStatusModal (state, params) { - state.params = params - state.modalActivated = true - }, - closePostStatusModal (state) { - state.modalActivated = false - } - }, - actions: { - openPostStatusModal ({ commit }, params) { - commit('openPostStatusModal', params) - }, - closePostStatusModal ({ commit }) { - commit('closePostStatusModal') - } - } -} - -export default postStatus diff --git a/src/stores/postStatus.js b/src/stores/postStatus.js new file mode 100644 index 00000000..b9fe96d3 --- /dev/null +++ b/src/stores/postStatus.js @@ -0,0 +1,17 @@ +import { defineStore } from 'pinia' + +export const usePostStatusStore = defineStore('postStatus', { + state: () => ({ + params: null, + modalActivated: false + }), + actions: { + openPostStatusModal (params) { + this.params = params + this.modalActivated = true + }, + closePostStatusModal () { + this.modalActivated = false + } + } +})