feat: port tasks store to pinia
This commit is contained in:
@ -240,6 +240,7 @@ import {calculateItemPosition} from '../../helpers/calculateItemPosition'
|
||||
import KanbanCard from '@/components/tasks/partials/kanban-card.vue'
|
||||
import DropdownItem from '@/components/misc/dropdown-item.vue'
|
||||
import {isSavedFilter} from '@/helpers/savedFilter'
|
||||
import {useTaskStore} from '@/stores/tasks'
|
||||
|
||||
const DRAG_OPTIONS = {
|
||||
// sortable options
|
||||
@ -433,7 +434,8 @@ export default defineComponent({
|
||||
)
|
||||
|
||||
try {
|
||||
await this.$store.dispatch('tasks/update', newTask)
|
||||
const taskStore = useTaskStore()
|
||||
await taskStore.update(newTask)
|
||||
|
||||
// Make sure the first and second task don't both get position 0 assigned
|
||||
if(newTaskIndex === 0 && taskAfter !== null && taskAfter.kanbanPosition === 0) {
|
||||
@ -445,7 +447,7 @@ export default defineComponent({
|
||||
taskAfterAfter !== null ? taskAfterAfter.kanbanPosition : null,
|
||||
)
|
||||
|
||||
await this.$store.dispatch('tasks/update', newTaskAfter)
|
||||
await taskStore.update(newTaskAfter)
|
||||
}
|
||||
} finally {
|
||||
this.taskUpdating[task.id] = false
|
||||
@ -464,7 +466,7 @@ export default defineComponent({
|
||||
}
|
||||
this.newTaskError[bucketId] = false
|
||||
|
||||
const task = await this.$store.dispatch('tasks/createNewTask', {
|
||||
const task = await useTaskStore().createNewTask({
|
||||
title: this.newTaskText,
|
||||
bucketId,
|
||||
listId: this.listId,
|
||||
|
@ -139,7 +139,7 @@ export default { name: 'List' }
|
||||
</script>
|
||||
|
||||
<script setup lang="ts">
|
||||
import {ref, computed, toRef, nextTick, onMounted} from 'vue'
|
||||
import {ref, computed, toRef, nextTick, onMounted, type PropType} from 'vue'
|
||||
import draggable from 'zhyswan-vuedraggable'
|
||||
import {useRoute, useRouter} from 'vue-router'
|
||||
|
||||
@ -161,6 +161,9 @@ import {RIGHTS as Rights} from '@/constants/rights'
|
||||
import {calculateItemPosition} from '@/helpers/calculateItemPosition'
|
||||
import type {ITask} from '@/modelTypes/ITask'
|
||||
import {isSavedFilter} from '@/helpers/savedFilter'
|
||||
import {useTaskStore} from '@/stores/tasks'
|
||||
|
||||
import type {IList} from '@/modelTypes/IList'
|
||||
|
||||
function sortTasks(tasks: ITask[]) {
|
||||
if (tasks === null || Array.isArray(tasks) && tasks.length === 0) {
|
||||
@ -182,7 +185,7 @@ function sortTasks(tasks: ITask[]) {
|
||||
|
||||
const props = defineProps({
|
||||
listId: {
|
||||
type: Number,
|
||||
type: Number as PropType<IList['id']>,
|
||||
required: true,
|
||||
},
|
||||
})
|
||||
@ -224,6 +227,7 @@ const firstNewPosition = computed(() => {
|
||||
return calculateItemPosition(null, tasks.value[0].position)
|
||||
})
|
||||
|
||||
const taskStore = useTaskStore()
|
||||
const store = useStore()
|
||||
const list = computed(() => store.state.currentList)
|
||||
|
||||
@ -238,6 +242,7 @@ onMounted(async () => {
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
function searchTasks() {
|
||||
// Only search if the search term changed
|
||||
if (route.query as unknown as string === searchTerm.value) {
|
||||
@ -309,7 +314,7 @@ async function saveTaskPosition(e) {
|
||||
position: calculateItemPosition(taskBefore !== null ? taskBefore.position : null, taskAfter !== null ? taskAfter.position : null),
|
||||
}
|
||||
|
||||
const updatedTask = await this.$store.dispatch('tasks/update', newTask)
|
||||
const updatedTask = await taskStore.update(newTask)
|
||||
tasks.value[e.newIndex] = updatedTask
|
||||
}
|
||||
</script>
|
||||
|
@ -60,9 +60,11 @@ import {LOADING, LOADING_MODULE} from '@/store/mutation-types'
|
||||
import LlamaCool from '@/assets/llama-cool.svg?component'
|
||||
import type {ITask} from '@/modelTypes/ITask'
|
||||
import {useAuthStore} from '@/stores/auth'
|
||||
import {useTaskStore} from '@/stores/tasks'
|
||||
|
||||
const store = useStore()
|
||||
const authStore = useAuthStore()
|
||||
const taskStore = useTaskStore()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const {t} = useI18n({useScope: 'global'})
|
||||
@ -180,7 +182,7 @@ async function loadPendingTasks(from: string, to: string) {
|
||||
}
|
||||
}
|
||||
|
||||
tasks.value = await store.dispatch('tasks/loadTasks', params)
|
||||
tasks.value = await taskStore.loadTasks(params)
|
||||
}
|
||||
|
||||
// FIXME: this modification should happen in the store
|
||||
|
@ -464,6 +464,7 @@ import type {IList} from '@/modelTypes/IList'
|
||||
import {colorIsDark} from '@/helpers/color/colorIsDark'
|
||||
import {useNamespaceStore} from '@/stores/namespaces'
|
||||
import {useAttachmentStore} from '@/stores/attachments'
|
||||
import {useTaskStore} from '@/stores/tasks'
|
||||
|
||||
function scrollIntoView(el) {
|
||||
if (!el) {
|
||||
@ -696,7 +697,8 @@ export default defineComponent({
|
||||
task.endDate = task.dueDate
|
||||
}
|
||||
|
||||
this.task = await this.$store.dispatch('tasks/update', task)
|
||||
|
||||
this.task = await useTaskStore().update(task)
|
||||
|
||||
if (!showNotification) {
|
||||
return
|
||||
@ -728,7 +730,7 @@ export default defineComponent({
|
||||
},
|
||||
|
||||
async deleteTask() {
|
||||
await this.$store.dispatch('tasks/delete', this.task)
|
||||
await useTaskStore().delete(this.task)
|
||||
this.$message.success({message: this.$t('task.detail.deleteSuccess')})
|
||||
this.$router.push({name: 'list.index', params: {listId: this.task.listId}})
|
||||
},
|
||||
|
Reference in New Issue
Block a user