fix: introduce a ListView type to properly type all available list views
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
kolaente 2022-09-08 14:11:19 +02:00
parent d91d1fecf1
commit 23598dd2ee
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 20 additions and 13 deletions

View File

@ -201,13 +201,16 @@ import {useStore} from '@/store'
import {useI18n} from 'vue-i18n'
import {RIGHTS} from '@/constants/rights'
import LinkShareModel, {type ILinkShare} from '@/models/linkShare'
import LinkShareModel from '@/models/linkShare'
import type {ILinkShare} from '@/modelTypes/ILinkShare'
import LinkShareService from '@/services/linkShare'
import {useCopyToClipboard} from '@/composables/useCopyToClipboard'
import {success} from '@/message'
import type {IList} from '@/models/list'
import type {IList} from '@/modelTypes/IList'
import type {ListView} from '@/types/ListView'
import {LIST_VIEWS} from '@/types/ListView'
const props = defineProps({
listId: {
@ -227,9 +230,7 @@ const showDeleteModal = ref(false)
const linkIdToDelete = ref(0)
const showNewForm = ref(false)
interface SelectedViewMapper {
[listId: number]: string,
}
type SelectedViewMapper = Record<IList['id'], ListView>
const selectedView = ref<SelectedViewMapper>({})
@ -285,7 +286,7 @@ async function remove(listId: IList['id']) {
}
}
function getShareLink(hash: string, view: string = 'list') {
function getShareLink(hash: string, view: ListView = LIST_VIEWS.LIST) {
return frontendUrl.value + 'share/' + hash + '/auth?view=' + view
}
</script>

8
src/types/ListView.ts Normal file
View File

@ -0,0 +1,8 @@
export const LIST_VIEWS = {
LIST: 'list',
GANTT: 'gantt',
TABLE: 'table',
KANBAN: 'kanban',
} as const
export type ListView = typeof LIST_VIEWS[keyof typeof LIST_VIEWS]

View File

@ -41,6 +41,7 @@ import {useTitle} from '@vueuse/core'
import Message from '@/components/misc/message.vue'
import {LOGO_VISIBLE} from '@/store/mutation-types'
import {LIST_VIEWS, type ListView} from '@/types/ListView'
const {t} = useI18n({useScope: 'global'})
useTitle(t('sharing.authenticating'))
@ -80,13 +81,10 @@ function useAuth() {
: true
store.commit(LOGO_VISIBLE, logoVisible)
let view = 'list'
if (route.query.view &&
(route.query.view === 'gantt' ||
route.query.view === 'kanban' ||
route.query.view === 'table')) {
view = route.query.view
}
const view = route.query.view && Object.values(LIST_VIEWS).includes(route.query.view as ListView)
? route.query.view
: 'list'
router.push({name: `list.${view}`, params: {listId}})
} catch (e: any) {
if (e.response?.data?.code === 13001) {