Move editStatus module to store

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

View File

@ -2,6 +2,7 @@ import PostStatusForm from '../post_status_form/post_status_form.vue'
import Modal from '../modal/modal.vue' import Modal from '../modal/modal.vue'
import statusPosterService from '../../services/status_poster/status_poster.service.js' import statusPosterService from '../../services/status_poster/status_poster.service.js'
import get from 'lodash/get' import get from 'lodash/get'
import { useEditStatusStore } from '../../stores/editStatus'
const EditStatusModal = { const EditStatusModal = {
components: { components: {
@ -18,13 +19,13 @@ const EditStatusModal = {
return !!this.$store.state.users.currentUser return !!this.$store.state.users.currentUser
}, },
modalActivated () { modalActivated () {
return this.$store.state.editStatus.modalActivated return useEditStatusStore().modalActivated
}, },
isFormVisible () { isFormVisible () {
return this.isLoggedIn && !this.resettingForm && this.modalActivated return this.isLoggedIn && !this.resettingForm && this.modalActivated
}, },
params () { params () {
return this.$store.state.editStatus.params || {} return useEditStatusStore().params || {}
} }
}, },
watch: { watch: {
@ -46,7 +47,7 @@ const EditStatusModal = {
doEditStatus ({ status, spoilerText, sensitive, media, contentType, poll }) { doEditStatus ({ status, spoilerText, sensitive, media, contentType, poll }) {
const params = { const params = {
store: this.$store, store: this.$store,
statusId: this.$store.state.editStatus.params.statusId, statusId: useEditStatusStore().params.statusId,
status, status,
spoilerText, spoilerText,
sensitive, sensitive,
@ -67,7 +68,7 @@ const EditStatusModal = {
}) })
}, },
closeModal () { closeModal () {
this.$store.dispatch('closeEditStatusModal') useEditStatusStore().closeEditStatusModal()
} }
} }
} }

View File

@ -16,6 +16,7 @@ import {
faBookmark as faBookmarkReg, faBookmark as faBookmarkReg,
faFlag faFlag
} from '@fortawesome/free-regular-svg-icons' } from '@fortawesome/free-regular-svg-icons'
import { useEditStatusStore } from '../../stores/editStatus'
library.add( library.add(
faEllipsisH, faEllipsisH,
@ -107,7 +108,7 @@ const ExtraButtons = {
}, },
editStatus () { editStatus () {
this.$store.dispatch('fetchStatusSource', { id: this.status.id }) this.$store.dispatch('fetchStatusSource', { id: this.status.id })
.then(data => this.$store.dispatch('openEditStatusModal', { .then(data => useEditStatusStore().openEditStatusModal({
statusId: this.status.id, statusId: this.status.id,
subject: data.spoiler_text, subject: data.spoiler_text,
statusText: data.text, statusText: data.text,

View File

@ -19,7 +19,6 @@ import mediaViewerModule from './modules/media_viewer.js'
import oauthTokensModule from './modules/oauth_tokens.js' import oauthTokensModule from './modules/oauth_tokens.js'
import reportsModule from './modules/reports.js' import reportsModule from './modules/reports.js'
import pollsModule from './modules/polls.js' import pollsModule from './modules/polls.js'
import editStatusModule from './modules/editStatus.js'
import statusHistoryModule from './modules/statusHistory.js' import statusHistoryModule from './modules/statusHistory.js'
import chatsModule from './modules/chats.js' import chatsModule from './modules/chats.js'
@ -83,7 +82,6 @@ const persistedStateOptions = {
oauthTokens: oauthTokensModule, oauthTokens: oauthTokensModule,
reports: reportsModule, reports: reportsModule,
polls: pollsModule, polls: pollsModule,
editStatus: editStatusModule,
statusHistory: statusHistoryModule, statusHistory: statusHistoryModule,
chats: chatsModule, chats: chatsModule,
announcements: announcementsModule announcements: announcementsModule

View File

@ -1,25 +0,0 @@
const editStatus = {
state: {
params: null,
modalActivated: false
},
mutations: {
openEditStatusModal (state, params) {
state.params = params
state.modalActivated = true
},
closeEditStatusModal (state) {
state.modalActivated = false
}
},
actions: {
openEditStatusModal ({ commit }, params) {
commit('openEditStatusModal', params)
},
closeEditStatusModal ({ commit }) {
commit('closeEditStatusModal')
}
}
}
export default editStatus

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

@ -0,0 +1,17 @@
import { defineStore } from 'pinia'
export const useEditStatusStore = defineStore('editStatus', {
state: () => ({
params: null,
modalActivated: false
}),
actions: {
openEditStatusModal (params) {
this.params = params
this.modalActivated = true
},
closeEditStatusModal () {
this.modalActivated = false
}
}
})