feat: port tasks store to pinia
This commit is contained in:
@ -73,6 +73,7 @@ import {PREFIXES} from '@/modules/parseTaskText'
|
||||
import {useListStore} from '@/stores/lists'
|
||||
import {useNamespaceStore} from '@/stores/namespaces'
|
||||
import {useLabelStore} from '@/stores/labels'
|
||||
import {useTaskStore} from '@/stores/tasks'
|
||||
|
||||
const TYPE_LIST = 'list'
|
||||
const TYPE_TASK = 'task'
|
||||
@ -412,7 +413,8 @@ export default defineComponent({
|
||||
return
|
||||
}
|
||||
|
||||
const task = await this.$store.dispatch('tasks/createNewTask', {
|
||||
const taskStore = useTaskStore()
|
||||
const task = await taskStore.createNewTask({
|
||||
title: this.query,
|
||||
listId: this.currentList.id,
|
||||
})
|
||||
|
@ -43,12 +43,11 @@
|
||||
<script setup lang="ts">
|
||||
import {ref, watch, unref, computed} from 'vue'
|
||||
import {useI18n} from 'vue-i18n'
|
||||
import {useStore} from '@/store'
|
||||
import {tryOnMounted, debouncedWatch, useWindowSize, type MaybeRef} from '@vueuse/core'
|
||||
|
||||
import QuickAddMagic from '@/components/tasks/partials/quick-add-magic.vue'
|
||||
import {LOADING, LOADING_MODULE} from '@/store/mutation-types'
|
||||
import {useAuthStore} from '@/stores/auth'
|
||||
import {useTaskStore} from '@/stores/tasks'
|
||||
|
||||
function cleanupTitle(title: string) {
|
||||
return title.replace(/^((\* |\+ |- )(\[ \] )?)/g, '')
|
||||
@ -135,8 +134,8 @@ const newTaskTitle = ref('')
|
||||
const newTaskInput = useAutoHeightTextarea(newTaskTitle)
|
||||
|
||||
const {t} = useI18n({useScope: 'global'})
|
||||
const store = useStore()
|
||||
const authStore = useAuthStore()
|
||||
const taskStore = useTaskStore()
|
||||
|
||||
const errorMessage = ref('')
|
||||
|
||||
@ -149,7 +148,7 @@ function resetEmptyTitleError(e) {
|
||||
}
|
||||
}
|
||||
|
||||
const loading = computed(() => store.state[LOADING] && store.state[LOADING_MODULE] === 'tasks')
|
||||
const loading = computed(() => taskStore.isLoading)
|
||||
async function addTask() {
|
||||
if (newTaskTitle.value === '') {
|
||||
errorMessage.value = t('list.create.addTitleRequired')
|
||||
@ -168,7 +167,7 @@ async function addTask() {
|
||||
return
|
||||
}
|
||||
|
||||
const task = await store.dispatch('tasks/createNewTask', {
|
||||
const task = await taskStore.createNewTask({
|
||||
title,
|
||||
listId: authStore.settings.defaultListId,
|
||||
position: props.defaultPosition,
|
||||
|
@ -32,11 +32,12 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import {ref,computed, watch, type PropType} from 'vue'
|
||||
import {useStore} from '@/store'
|
||||
|
||||
import Editor from '@/components/input/AsyncEditor'
|
||||
|
||||
import type {ITask} from '@/modelTypes/ITask'
|
||||
import {useTaskStore} from '@/stores/tasks'
|
||||
import TaskModel from '@/models/task'
|
||||
|
||||
|
||||
const props = defineProps({
|
||||
@ -55,14 +56,14 @@ const props = defineProps({
|
||||
|
||||
const emit = defineEmits(['update:modelValue'])
|
||||
|
||||
const task = ref<ITask>({description: ''})
|
||||
const task = ref<ITask>(new TaskModel())
|
||||
const saved = ref(false)
|
||||
|
||||
// Since loading is global state, this variable ensures we're only showing the saving icon when saving the description.
|
||||
const saving = ref(false)
|
||||
|
||||
const store = useStore()
|
||||
const loading = computed(() => store.state.loading)
|
||||
const taskStore = useTaskStore()
|
||||
const loading = computed(() => taskStore.isLoading)
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
@ -77,7 +78,7 @@ async function save() {
|
||||
|
||||
try {
|
||||
// FIXME: don't update state from internal.
|
||||
task.value = await store.dispatch('tasks/update', task.value)
|
||||
task.value = await taskStore.update(task.value)
|
||||
emit('update:modelValue', task.value)
|
||||
|
||||
saved.value = true
|
||||
|
@ -29,7 +29,6 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import {ref, shallowReactive, watch, type PropType} from 'vue'
|
||||
import {useStore} from '@/store'
|
||||
import {useI18n} from 'vue-i18n'
|
||||
|
||||
import User from '@/components/misc/user.vue'
|
||||
@ -39,7 +38,9 @@ import BaseButton from '@/components/base/BaseButton.vue'
|
||||
import {includesById} from '@/helpers/utils'
|
||||
import ListUserService from '@/services/listUsers'
|
||||
import {success} from '@/message'
|
||||
import type { IUser } from '@/modelTypes/IUser'
|
||||
import {useTaskStore} from '@/stores/tasks'
|
||||
|
||||
import type {IUser} from '@/modelTypes/IUser'
|
||||
|
||||
const props = defineProps({
|
||||
taskId: {
|
||||
@ -60,7 +61,7 @@ const props = defineProps({
|
||||
})
|
||||
const emit = defineEmits(['update:modelValue'])
|
||||
|
||||
const store = useStore()
|
||||
const taskStore = useTaskStore()
|
||||
const {t} = useI18n({useScope: 'global'})
|
||||
|
||||
const listUserService = shallowReactive(new ListUserService())
|
||||
@ -79,13 +80,13 @@ watch(
|
||||
)
|
||||
|
||||
async function addAssignee(user: IUser) {
|
||||
await store.dispatch('tasks/addAssignee', {user: user, taskId: props.taskId})
|
||||
await taskStore.addAssignee({user: user, taskId: props.taskId})
|
||||
emit('update:modelValue', assignees.value)
|
||||
success({message: t('task.assignee.assignSuccess')})
|
||||
}
|
||||
|
||||
async function removeAssignee(user: IUser) {
|
||||
await store.dispatch('tasks/removeAssignee', {user: user, taskId: props.taskId})
|
||||
await taskStore.removeAssignee({user: user, taskId: props.taskId})
|
||||
|
||||
// Remove the assignee from the list
|
||||
for (const a in assignees.value) {
|
||||
|
@ -40,7 +40,6 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import {type PropType, ref, computed, shallowReactive, watch} from 'vue'
|
||||
import {useStore} from '@/store'
|
||||
import {useI18n} from 'vue-i18n'
|
||||
|
||||
import LabelModel from '@/models/label'
|
||||
@ -49,8 +48,9 @@ import {success} from '@/message'
|
||||
|
||||
import BaseButton from '@/components/base/BaseButton.vue'
|
||||
import Multiselect from '@/components/input/multiselect.vue'
|
||||
import type { ILabel } from '@/modelTypes/ILabel'
|
||||
import { useLabelStore } from '@/stores/labels'
|
||||
import type {ILabel} from '@/modelTypes/ILabel'
|
||||
import {useLabelStore} from '@/stores/labels'
|
||||
import {useTaskStore} from '@/stores/tasks'
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: {
|
||||
@ -69,7 +69,6 @@ const props = defineProps({
|
||||
|
||||
const emit = defineEmits(['update:modelValue'])
|
||||
|
||||
const store = useStore()
|
||||
const {t} = useI18n({useScope: 'global'})
|
||||
|
||||
const labelTaskService = shallowReactive(new LabelTaskService())
|
||||
@ -87,6 +86,7 @@ watch(
|
||||
},
|
||||
)
|
||||
|
||||
const taskStore = useTaskStore()
|
||||
const labelStore = useLabelStore()
|
||||
|
||||
const foundLabels = computed(() => labelStore.filterLabelsByQuery(labels.value, query.value))
|
||||
@ -97,17 +97,13 @@ function findLabel(newQuery: string) {
|
||||
}
|
||||
|
||||
async function addLabel(label: ILabel, showNotification = true) {
|
||||
const bubble = () => {
|
||||
emit('update:modelValue', labels.value)
|
||||
}
|
||||
|
||||
if (props.taskId === 0) {
|
||||
bubble()
|
||||
emit('update:modelValue', labels.value)
|
||||
return
|
||||
}
|
||||
|
||||
await store.dispatch('tasks/addLabel', {label, taskId: props.taskId})
|
||||
bubble()
|
||||
await taskStore.addLabel({label, taskId: props.taskId})
|
||||
emit('update:modelValue', labels.value)
|
||||
if (showNotification) {
|
||||
success({message: t('task.label.addSuccess')})
|
||||
}
|
||||
@ -115,7 +111,7 @@ async function addLabel(label: ILabel, showNotification = true) {
|
||||
|
||||
async function removeLabel(label: ILabel) {
|
||||
if (props.taskId !== 0) {
|
||||
await store.dispatch('tasks/removeLabel', {label, taskId: props.taskId})
|
||||
await taskStore.removeLabel({label, taskId: props.taskId})
|
||||
}
|
||||
|
||||
for (const l in labels.value) {
|
||||
|
@ -38,7 +38,6 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import {ref, computed, type PropType} from 'vue'
|
||||
import {useStore} from '@/store'
|
||||
import {useRouter} from 'vue-router'
|
||||
|
||||
import BaseButton from '@/components/base/BaseButton.vue'
|
||||
@ -48,6 +47,7 @@ import {useCopyToClipboard} from '@/composables/useCopyToClipboard'
|
||||
|
||||
import type {ITask} from '@/modelTypes/ITask'
|
||||
import ColorBubble from '@/components/misc/colorBubble.vue'
|
||||
import {useTaskStore} from '@/stores/tasks'
|
||||
|
||||
const props = defineProps({
|
||||
task: {
|
||||
@ -72,8 +72,8 @@ async function copyUrl() {
|
||||
await copy(absoluteURL)
|
||||
}
|
||||
|
||||
const store = useStore()
|
||||
const loading = computed(() => store.state.loading)
|
||||
const taskStore = useTaskStore()
|
||||
const loading = computed(() => taskStore.isLoading)
|
||||
|
||||
const textIdentifier = computed(() => props.task?.getTextIdentifier() || '')
|
||||
|
||||
@ -93,7 +93,7 @@ async function save(title: string) {
|
||||
|
||||
try {
|
||||
saving.value = true
|
||||
const newTask = await store.dispatch('tasks/update', {
|
||||
const newTask = await taskStore.update({
|
||||
...props.task,
|
||||
title,
|
||||
})
|
||||
|
@ -78,6 +78,7 @@ import type {ITask} from '@/modelTypes/ITask'
|
||||
|
||||
import {formatDateLong, formatISO, formatDateSince} from '@/helpers/time/formatDate'
|
||||
import {colorIsDark} from '@/helpers/color/colorIsDark'
|
||||
import {useTaskStore} from '@/stores/tasks'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'kanban-card',
|
||||
@ -121,7 +122,7 @@ export default defineComponent({
|
||||
this.loadingInternal = true
|
||||
try {
|
||||
const done = !task.done
|
||||
await this.$store.dispatch('tasks/update', {
|
||||
await useTaskStore().update({
|
||||
...task,
|
||||
done,
|
||||
})
|
||||
|
@ -149,7 +149,6 @@
|
||||
import {ref, reactive, shallowReactive, watch, computed, type PropType} from 'vue'
|
||||
import {useI18n} from 'vue-i18n'
|
||||
import {useRoute} from 'vue-router'
|
||||
import {useStore} from '@/store'
|
||||
|
||||
import TaskService from '@/services/task'
|
||||
import TaskModel from '@/models/task'
|
||||
@ -167,6 +166,7 @@ import Fancycheckbox from '@/components/input/fancycheckbox.vue'
|
||||
import {useNamespaceStore} from '@/stores/namespaces'
|
||||
|
||||
import {error, success} from '@/message'
|
||||
import {useTaskStore} from '@/stores/tasks'
|
||||
|
||||
const props = defineProps({
|
||||
taskId: {
|
||||
@ -190,7 +190,7 @@ const props = defineProps({
|
||||
},
|
||||
})
|
||||
|
||||
const store = useStore()
|
||||
const taskStore = useTaskStore()
|
||||
const namespaceStore = useNamespaceStore()
|
||||
const route = useRoute()
|
||||
const {t} = useI18n({useScope: 'global'})
|
||||
@ -344,7 +344,7 @@ async function createAndRelateTask(title: string) {
|
||||
}
|
||||
|
||||
async function toggleTaskDone(task: ITask) {
|
||||
await store.dispatch('tasks/update', task)
|
||||
await taskStore.update(task)
|
||||
|
||||
// Find the task in the list and update it so that it is correctly strike through
|
||||
Object.entries(relatedTasks.value).some(([kind, tasks]) => {
|
||||
|
@ -119,6 +119,7 @@ import {formatDateSince, formatISO, formatDateLong} from '@/helpers/time/formatD
|
||||
import ColorBubble from '@/components/misc/colorBubble.vue'
|
||||
import {useListStore} from '@/stores/lists'
|
||||
import {useNamespaceStore} from '@/stores/namespaces'
|
||||
import {useTaskStore} from '@/stores/tasks'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'singleTaskInList',
|
||||
@ -208,7 +209,7 @@ export default defineComponent({
|
||||
|
||||
async markAsDone(checked: boolean) {
|
||||
const updateFunc = async () => {
|
||||
const task = await this.$store.dispatch('tasks/update', this.task)
|
||||
const task = await useTaskStore().update(this.task)
|
||||
this.task = task
|
||||
this.$emit('task-updated', task)
|
||||
this.$message.success({
|
||||
|
Reference in New Issue
Block a user