feat: archive list script setup

This commit is contained in:
Dominik Pschenitschni 2022-05-21 17:27:06 +02:00 committed by Gitea
parent 27f7541b25
commit 93b2482d4c

View file

@ -13,39 +13,41 @@
<script lang="ts"> <script lang="ts">
import {defineComponent} from 'vue' import {defineComponent} from 'vue'
export default defineComponent({name: 'list-setting-archive'})
</script>
<script setup lang="ts">
import {computed, shallowReactive} from 'vue'
import {useStore} from 'vuex'
import {useRouter, useRoute} from 'vue-router'
import {useI18n} from 'vue-i18n'
import ListService from '@/services/list' import ListService from '@/services/list'
export default defineComponent({ import { success } from '@/message'
name: 'list-setting-archive', import { useTitle } from '@/composables/useTitle'
data() {
return {
listService: new ListService(),
}
},
created() {
this.setTitle(this.$t('list.archive.title', {list: this.list.title}))
},
computed: {
list() {
return this.$store.getters['lists/getListById'](this.$route.params.listId)
},
},
methods: {
async archiveList() {
const newList = {
...this.list,
isArchived: !this.list.isArchived,
}
try { const {t} = useI18n()
const list = await this.listService.update(newList) const store = useStore()
this.$store.commit('currentList', list) const router = useRouter()
this.$store.commit('namespaces/setListInNamespaceById', list) const route = useRoute()
this.$message.success({message: this.$t('list.archive.success')})
} finally { const list = computed(() => store.getters['lists/getListById'](route.params.listId))
this.$router.back() useTitle(() => t('list.archive.title', {list: list.value.title}))
}
}, const listService = shallowReactive(new ListService())
},
}) async function archiveList() {
try {
const newList = await listService.update({
...list,
isArchived: !list.value.isArchived,
})
store.commit('currentList', newList)
store.commit('namespaces/setListInNamespaceById', newList)
success({message: t('list.archive.success')})
} finally {
router.back()
}
}
</script> </script>