From f6437c81da73b7e3406c28b9bd7b201e376f15c3 Mon Sep 17 00:00:00 2001 From: Dominik Pschenitschni Date: Fri, 2 Sep 2022 15:13:32 +0000 Subject: [PATCH] feat: list settings edit script setup (#1988) Co-authored-by: Dominik Pschenitschni Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/1988 Reviewed-by: konrad Co-authored-by: Dominik Pschenitschni Co-committed-by: Dominik Pschenitschni --- src/composables/useList.ts | 37 ++++++++++++++ src/router/index.ts | 3 ++ src/views/list/settings/edit.vue | 82 +++++++++++++++----------------- 3 files changed, 78 insertions(+), 44 deletions(-) create mode 100644 src/composables/useList.ts diff --git a/src/composables/useList.ts b/src/composables/useList.ts new file mode 100644 index 00000000..6db3ad1d --- /dev/null +++ b/src/composables/useList.ts @@ -0,0 +1,37 @@ +import {watch, reactive, shallowReactive, unref, toRefs, readonly} from 'vue' +import type {MaybeRef} from '@vueuse/core' +import {useStore} from 'vuex' + +import ListService from '@/services/list' +import ListModel from '@/models/list' +import { success } from '@/message' +import {useI18n} from 'vue-i18n' + +export function useList(listId: MaybeRef) { + const listService = shallowReactive(new ListService()) + const {loading: isLoading} = toRefs(listService) + const list : ListModel = reactive(new ListModel({})) + const {t} = useI18n() + + watch( + () => unref(listId), + async (listId) => { + const loadedList = await listService.get(new ListModel({id: listId})) + Object.assign(list, loadedList) + }, + {immediate: true}, + ) + + + const store = useStore() + async function save() { + await store.dispatch('lists/updateList', list) + success({message: t('list.edit.success')}) + } + + return { + isLoading: readonly(isLoading), + list, + save, + } +} \ No newline at end of file diff --git a/src/router/index.ts b/src/router/index.ts index 01f9c6ca..25c6b9a6 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -3,6 +3,8 @@ import type { RouteLocation } from 'vue-router' import {saveLastVisited} from '@/helpers/saveLastVisited' import {store} from '@/store' +import type ListModel from '@/models/list' + import {saveListView, getListView} from '@/helpers/saveListView' import {parseDateOrString} from '@/helpers/time/parseDateOrString' import {getNextWeekDate} from '@/helpers/time/getNextWeekDate' @@ -273,6 +275,7 @@ const router = createRouter({ path: '/lists/:listId/settings/edit', name: 'list.settings.edit', component: ListSettingEdit, + props: route => ({ listId: parseInt(route.params.listId as ListModel['id']) }), meta: { showAsModal: true, }, diff --git a/src/views/list/settings/edit.vue b/src/views/list/settings/edit.vue index d516702c..67055e44 100644 --- a/src/views/list/settings/edit.vue +++ b/src/views/list/settings/edit.vue @@ -5,14 +5,14 @@ :primary-label="$t('misc.save')" @primary="save" :tertiary="$t('misc.delete')" - @tertiary="$router.push({ name: 'list.list.settings.delete', params: { id: $route.params.listId } })" + @tertiary="$router.push({ name: 'list.settings.delete', params: { id: listId } })" >
{{ $t('list.edit.description') }}
-import AsyncEditor from '@/components/input/AsyncEditor' +