feat: port label store to pinia | pinia 1/9 (#2391)
Co-authored-by: Dominik Pschenitschni <mail@celement.de> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/2391 Reviewed-by: konrad <k@knt.li> Co-authored-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de> Co-committed-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de>
This commit is contained in:

committed by
konrad

parent
e91b5fde02
commit
d67e5e386d
@ -111,11 +111,12 @@
|
||||
|
||||
<script lang="ts">
|
||||
import {defineComponent} from 'vue'
|
||||
import {mapState} from 'vuex'
|
||||
import {mapState as mapVuexState} from 'vuex'
|
||||
import {mapState} from 'pinia'
|
||||
|
||||
import LabelModel from '@/models/label'
|
||||
import LabelModel from '../../models/label'
|
||||
import type {ILabel} from '@/modelTypes/ILabel'
|
||||
import {LOADING, LOADING_MODULE} from '@/store/mutation-types'
|
||||
import {useLabelStore} from '@/stores/labels'
|
||||
|
||||
import BaseButton from '@/components/base/BaseButton.vue'
|
||||
import AsyncEditor from '@/components/input/AsyncEditor'
|
||||
@ -139,25 +140,32 @@ export default defineComponent({
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.$store.dispatch('labels/loadAllLabels')
|
||||
const labelStore = useLabelStore()
|
||||
labelStore.loadAllLabels()
|
||||
},
|
||||
mounted() {
|
||||
setTitle(this.$t('label.title'))
|
||||
},
|
||||
computed: mapState({
|
||||
userInfo: state => state.auth.info,
|
||||
// Alphabetically sort the labels
|
||||
labels: state => Object.values(state.labels.labels).sort((f, s) => f.title > s.title ? 1 : -1),
|
||||
loading: state => state[LOADING] && state[LOADING_MODULE] === 'labels',
|
||||
}),
|
||||
computed: {
|
||||
...mapVuexState({
|
||||
userInfo: state => state.auth.info,
|
||||
}),
|
||||
...mapState(useLabelStore, {
|
||||
// Alphabetically sort the labels
|
||||
labels: state => Object.values(state.labels).sort((f, s) => f.title > s.title ? 1 : -1),
|
||||
loading: state => state.isLoading,
|
||||
}),
|
||||
},
|
||||
methods: {
|
||||
deleteLabel(label: ILabel) {
|
||||
this.showDeleteModal = false
|
||||
this.isLabelEdit = false
|
||||
return this.$store.dispatch('labels/deleteLabel', label)
|
||||
const labelStore = useLabelStore()
|
||||
return labelStore.deleteLabel(label)
|
||||
},
|
||||
editLabelSubmit() {
|
||||
return this.$store.dispatch('labels/updateLabel', this.labelEditLabel)
|
||||
const labelStore = useLabelStore()
|
||||
return labelStore.updateLabel(this.labelEditLabel)
|
||||
},
|
||||
editLabel(label: ILabel) {
|
||||
if (label.createdBy.id !== this.userInfo.id) {
|
||||
|
@ -36,12 +36,13 @@
|
||||
|
||||
<script lang="ts">
|
||||
import {defineComponent} from 'vue'
|
||||
import {mapState} from 'pinia'
|
||||
|
||||
import LabelModel from '../../models/label'
|
||||
import CreateEdit from '@/components/misc/create-edit.vue'
|
||||
import ColorPicker from '../../components/input/colorPicker.vue'
|
||||
import {mapState} from 'vuex'
|
||||
import {LOADING, LOADING_MODULE} from '@/store/mutation-types'
|
||||
import { setTitle } from '@/helpers/setTitle'
|
||||
import { useLabelStore } from '@/stores/labels'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'NewLabel',
|
||||
@ -58,9 +59,11 @@ export default defineComponent({
|
||||
mounted() {
|
||||
setTitle(this.$t('label.create.title'))
|
||||
},
|
||||
computed: mapState({
|
||||
loading: state => state[LOADING] && state[LOADING_MODULE] === 'labels',
|
||||
}),
|
||||
computed: {
|
||||
...mapState(useLabelStore, {
|
||||
loading: state => state.isLoading,
|
||||
}),
|
||||
},
|
||||
methods: {
|
||||
async newLabel() {
|
||||
if (this.label.title === '') {
|
||||
@ -69,7 +72,8 @@ export default defineComponent({
|
||||
}
|
||||
this.showError = false
|
||||
|
||||
const label = this.$store.dispatch('labels/createLabel', this.label)
|
||||
const labelStore = useLabelStore()
|
||||
const label = labelStore.createLabel(this.label)
|
||||
this.$router.push({
|
||||
name: 'labels.index',
|
||||
params: {id: label.id},
|
||||
|
Reference in New Issue
Block a user