From 3766b5e51ba9c40a6affa91ce5cc11519e2da5c3 Mon Sep 17 00:00:00 2001 From: Dominik Pschenitschni Date: Thu, 21 Jul 2022 00:42:36 +0200 Subject: [PATCH] feat: improve store and model typing --- src/components/home/navigation.vue | 18 +-- .../list/list-settings-dropdown.vue | 10 +- src/components/list/partials/list-card.vue | 6 +- src/components/misc/subscription.vue | 4 +- .../namespace/namespace-settings-dropdown.vue | 5 +- .../notifications/notifications.vue | 4 +- src/components/sharing/linkSharing.vue | 12 +- src/components/sharing/userTeam.vue | 24 ++-- src/components/tasks/edit-task.vue | 14 ++- src/components/tasks/partials/attachments.vue | 10 +- .../tasks/partials/checklist-summary.vue | 6 +- src/components/tasks/partials/comments.vue | 18 +-- .../tasks/partials/createdUpdated.vue | 6 +- src/components/tasks/partials/defer-task.vue | 8 +- src/components/tasks/partials/description.vue | 8 +- .../tasks/partials/editAssignees.vue | 10 +- src/components/tasks/partials/editLabels.vue | 10 +- src/components/tasks/partials/heading.vue | 6 +- src/components/tasks/partials/kanban-card.vue | 6 +- src/components/tasks/partials/labels.vue | 4 +- src/components/tasks/partials/listSearch.vue | 11 +- src/components/tasks/partials/repeatAfter.vue | 10 +- .../tasks/partials/singleTaskInList.vue | 4 +- src/helpers/attachments.ts | 15 ++- src/helpers/getListTitle.ts | 5 +- src/helpers/getNamespaceTitle.ts | 4 +- src/helpers/labels.ts | 18 +-- src/helpers/saveCollapsedBucketState.ts | 9 +- src/helpers/savedFilter.ts | 4 +- src/helpers/utils.ts | 4 +- src/models/abstractModel.ts | 6 +- src/models/attachment.ts | 19 ++- src/models/avatar.ts | 12 +- src/models/backgroundImage.ts | 15 ++- src/models/bucket.ts | 26 +++- src/models/caldavToken.ts | 13 +- src/models/emailUpdate.ts | 7 +- src/models/file.ts | 10 +- src/models/label.ts | 20 ++- src/models/labelTask.ts | 8 +- src/models/linkShare.ts | 21 +++- src/models/list.ts | 43 +++++-- src/models/listDuplicateModel.ts | 16 ++- src/models/namespace.ts | 30 +++-- src/models/notification.ts | 38 +++--- src/models/passwordReset.ts | 8 +- src/models/passwordUpdate.ts | 9 +- src/models/savedFilter.ts | 25 +++- src/models/subscription.ts | 15 ++- src/models/task.ts | 75 ++++++++--- src/models/taskAssignee.ts | 16 ++- src/models/taskComment.ts | 20 ++- src/models/taskRelation.ts | 22 +++- src/models/team.ts | 24 +++- src/models/teamList.ts | 10 +- src/models/teamMember.ts | 11 +- src/models/teamNamespace.ts | 10 +- src/models/teamShareBase.ts | 16 ++- src/models/totp.ts | 8 +- src/models/user.ts | 18 ++- src/models/userList.ts | 11 +- src/models/userNamespace.ts | 10 +- src/models/userSettings.ts | 17 ++- src/models/userShareBase.ts | 14 ++- src/modules/parseTaskText.test.ts | 2 +- src/services/abstractService.ts | 17 +-- src/services/attachment.ts | 12 +- src/services/avatar.ts | 4 +- src/services/backgroundUnsplash.ts | 6 +- src/services/backgroundUpload.ts | 6 +- src/services/bucket.ts | 4 +- src/services/caldavToken.ts | 6 +- src/services/label.ts | 4 +- src/services/list.ts | 4 +- src/services/namespace.ts | 4 +- src/services/task.ts | 4 +- src/services/taskComment.ts | 4 +- src/store/helper.ts | 8 +- src/store/index.ts | 8 +- src/store/modules/attachments.ts | 13 +- src/store/modules/auth.ts | 57 ++++----- src/store/modules/config.ts | 13 +- src/store/modules/kanban.ts | 95 +++++++++----- src/store/modules/labels.ts | 41 ++++--- src/store/modules/lists.ts | 25 ++-- src/store/modules/namespaces.ts | 37 +++--- src/store/modules/tasks.ts | 83 +++++++++---- src/store/types.ts | 116 ++++++++++++++++++ src/views/filters/FilterEdit.vue | 4 +- src/views/labels/ListLabels.vue | 8 +- src/views/list/ListList.vue | 10 +- src/views/list/ListTable.vue | 4 +- src/views/list/settings/duplicate.vue | 6 +- src/views/list/settings/edit.vue | 4 +- src/views/tasks/ShowTasks.vue | 6 +- src/views/tasks/TaskDetailView.vue | 8 +- src/views/teams/EditTeam.vue | 26 ++-- src/views/user/settings/Caldav.vue | 12 +- 98 files changed, 1050 insertions(+), 507 deletions(-) create mode 100644 src/store/types.ts diff --git a/src/components/home/navigation.vue b/src/components/home/navigation.vue index 76a0fb23..53f2a9f7 100644 --- a/src/components/home/navigation.vue +++ b/src/components/home/navigation.vue @@ -156,8 +156,8 @@ import {calculateItemPosition} from '@/helpers/calculateItemPosition' import {getNamespaceTitle} from '@/helpers/getNamespaceTitle' import {getListTitle} from '@/helpers/getListTitle' import {useEventListener} from '@vueuse/core' -import type NamespaceModel from '@/models/namespace' -import type ListModel from '@/models/list' +import type { IList } from '@/models/list' +import type { INamespace } from '@/models/namespace' const drag = ref(false) const dragOptions = { @@ -172,7 +172,7 @@ const loading = computed(() => store.state.loading && store.state.loadingModule const namespaces = computed(() => { - return (store.state.namespaces.namespaces as NamespaceModel[]).filter(n => !n.isArchived) + return (store.state.namespaces.namespaces as INamespace[]).filter(n => !n.isArchived) }) const activeLists = computed(() => { return namespaces.value.map(({lists}) => { @@ -195,7 +195,7 @@ useEventListener('resize', resize) onMounted(() => resize()) -function toggleFavoriteList(list: ListModel) { +function toggleFavoriteList(list: IList) { // The favorites pseudo list is always favorite // Archived lists cannot be marked favorite if (list.id === -1 || list.isArchived) { @@ -209,14 +209,14 @@ function resize() { store.commit(MENU_ACTIVE, window.innerWidth >= 770) } -function toggleLists(namespaceId: NamespaceModel['id']) { +function toggleLists(namespaceId: INamespace['id']) { listsVisible.value[namespaceId] = !listsVisible.value[namespaceId] } -const listsVisible = ref<{ [id: NamespaceModel['id']]: boolean }>({}) +const listsVisible = ref<{ [id: INamespace['id']]: boolean }>({}) // FIXME: async action will be unfinished when component mounts onBeforeMount(async () => { - const namespaces = await store.dispatch('namespaces/loadNamespaces') as NamespaceModel[] + const namespaces = await store.dispatch('namespaces/loadNamespaces') as INamespace[] namespaces.forEach(n => { if (typeof listsVisible.value[n.id] === 'undefined') { listsVisible.value[n.id] = true @@ -224,7 +224,7 @@ onBeforeMount(async () => { }) }) -function updateActiveLists(namespace: NamespaceModel, activeLists: ListModel[]) { +function updateActiveLists(namespace: INamespace, activeLists: IList[]) { // This is a bit hacky: since we do have to filter out the archived items from the list // for vue draggable updating it is not as simple as replacing it. // To work around this, we merge the active lists with the archived ones. Doing so breaks the order @@ -241,7 +241,7 @@ function updateActiveLists(namespace: NamespaceModel, activeLists: ListModel[]) }) } -const listUpdating = ref<{ [id: NamespaceModel['id']]: boolean }>({}) +const listUpdating = ref<{ [id: INamespace['id']]: boolean }>({}) async function saveListPosition(e: SortableEvent) { if (!e.newIndex && e.newIndex !== 0) return diff --git a/src/components/list/list-settings-dropdown.vue b/src/components/list/list-settings-dropdown.vue index 74cafb88..180596b2 100644 --- a/src/components/list/list-settings-dropdown.vue +++ b/src/components/list/list-settings-dropdown.vue @@ -76,24 +76,24 @@ diff --git a/src/views/user/settings/Caldav.vue b/src/views/user/settings/Caldav.vue index ad63f8d3..5d8cec38 100644 --- a/src/views/user/settings/Caldav.vue +++ b/src/views/user/settings/Caldav.vue @@ -77,8 +77,8 @@ import {success} from '@/message' import BaseButton from '@/components/base/BaseButton.vue' import Message from '@/components/misc/message.vue' import CaldavTokenService from '@/services/caldavToken' -import type CaldavTokenModel from '@/models/caldavToken' import { formatDateShort } from '@/helpers/time/formatDate' +import type { ICaldavToken } from '@/models/caldavToken' const copy = useCopyToClipboard() @@ -86,19 +86,19 @@ const {t} = useI18n({useScope: 'global'}) useTitle(() => `${t('user.settings.caldav.title')} - ${t('user.settings.title')}`) const service = shallowReactive(new CaldavTokenService()) -const tokens = ref([]) +const tokens = ref([]) -service.getAll().then((result: CaldavTokenModel[]) => { +service.getAll().then((result: ICaldavToken[]) => { tokens.value = result }) -const newToken = ref() +const newToken = ref() async function createToken() { - newToken.value = await service.create({}) as CaldavTokenModel + newToken.value = await service.create({}) as ICaldavToken tokens.value.push(newToken.value) } -async function deleteToken(token: CaldavTokenModel) { +async function deleteToken(token: ICaldavToken) { const r = await service.delete(token) tokens.value = tokens.value.filter(({id}) => id !== token.id) success(r)