Move postStatus module to store

This commit is contained in:
Sean King 2023-04-05 13:01:37 -06:00
parent aa6c13f9e6
commit 27e36dbc2e
No known key found for this signature in database
GPG Key ID: 510C52BACD6E7257
6 changed files with 25 additions and 32 deletions

View File

@ -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

View File

@ -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()
}
}
}

View File

@ -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) {

View File

@ -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,

View File

@ -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

17
src/stores/postStatus.js Normal file
View File

@ -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
}
}
})