feat(views): load views when navigating with link share

This commit is contained in:
kolaente 2024-03-16 12:31:10 +01:00
parent 4170f5468f
commit a3714c74fd
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
4 changed files with 21 additions and 31 deletions

View File

@ -33,11 +33,15 @@ import {useBaseStore} from '@/stores/base'
import Logo from '@/components/home/Logo.vue' import Logo from '@/components/home/Logo.vue'
import PoweredByLink from './PoweredByLink.vue' import PoweredByLink from './PoweredByLink.vue'
import {useProjectStore} from '@/stores/projects'
const baseStore = useBaseStore() const baseStore = useBaseStore()
const currentProject = computed(() => baseStore.currentProject) const currentProject = computed(() => baseStore.currentProject)
const background = computed(() => baseStore.background) const background = computed(() => baseStore.background)
const logoVisible = computed(() => baseStore.logoVisible) const logoVisible = computed(() => baseStore.logoVisible)
const projectStore = useProjectStore()
projectStore.loadAllProjects()
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -173,11 +173,11 @@
<div class="select"> <div class="select">
<select v-model="selectedView[s.id]"> <select v-model="selectedView[s.id]">
<option <option
v-for="(title, key) in availableViews" v-for="(view) in availableViews"
:key="key" :key="view.id"
:value="key" :value="view.id"
> >
{{ title }} {{ view.title }}
</option> </option>
</select> </select>
</div> </div>
@ -230,9 +230,9 @@ import LinkShareService from '@/services/linkShare'
import {useCopyToClipboard} from '@/composables/useCopyToClipboard' import {useCopyToClipboard} from '@/composables/useCopyToClipboard'
import {success} from '@/message' import {success} from '@/message'
import {getDisplayName} from '@/models/user' import {getDisplayName} from '@/models/user'
import type {ProjectView} from '@/types/ProjectView'
import {PROJECT_VIEWS} from '@/types/ProjectView'
import {useConfigStore} from '@/stores/config' import {useConfigStore} from '@/stores/config'
import {useProjectStore} from '@/stores/projects'
import type {IProjectView} from '@/modelTypes/IProjectView'
const props = defineProps({ const props = defineProps({
projectId: { projectId: {
@ -252,17 +252,13 @@ const showDeleteModal = ref(false)
const linkIdToDelete = ref(0) const linkIdToDelete = ref(0)
const showNewForm = ref(false) const showNewForm = ref(false)
type SelectedViewMapper = Record<IProject['id'], ProjectView> type SelectedViewMapper = Record<IProject['id'], IProjectView['id']>
const selectedView = ref<SelectedViewMapper>({}) const selectedView = ref<SelectedViewMapper>({})
const availableViews = computed<Record<ProjectView, string>>(() => ({ const projectStore = useProjectStore()
list: t('project.list.title'),
gantt: t('project.gantt.title'),
table: t('project.table.title'),
kanban: t('project.kanban.title'),
}))
const availableViews = computed<IProjectView[]>(() => projectStore.projects[props.projectId]?.views || [])
const copy = useCopyToClipboard() const copy = useCopyToClipboard()
watch( watch(
() => props.projectId, () => props.projectId,
@ -281,7 +277,7 @@ async function load(projectId: IProject['id']) {
const links = await linkShareService.getAll({projectId}) const links = await linkShareService.getAll({projectId})
links.forEach((l: ILinkShare) => { links.forEach((l: ILinkShare) => {
selectedView.value[l.id] = 'list' selectedView.value[l.id] = availableViews.value[0].id
}) })
linkShares.value = links linkShares.value = links
} }
@ -315,8 +311,8 @@ async function remove(projectId: IProject['id']) {
} }
} }
function getShareLink(hash: string, view: ProjectView = PROJECT_VIEWS.LIST) { function getShareLink(hash: string, viewId: IProjectView['id']) {
return frontendUrl.value + 'share/' + hash + '/auth?view=' + view return frontendUrl.value + 'share/' + hash + '/auth?view=' + viewId
} }
</script> </script>

View File

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

View File

@ -49,7 +49,6 @@ import {useI18n} from 'vue-i18n'
import {useTitle} from '@vueuse/core' import {useTitle} from '@vueuse/core'
import Message from '@/components/misc/message.vue' import Message from '@/components/misc/message.vue'
import {PROJECT_VIEWS, type ProjectView} from '@/types/ProjectView'
import {LINK_SHARE_HASH_PREFIX} from '@/constants/linkShareHash' import {LINK_SHARE_HASH_PREFIX} from '@/constants/linkShareHash'
import {useBaseStore} from '@/stores/base' import {useBaseStore} from '@/stores/base'
@ -96,10 +95,6 @@ function useAuth() {
: true : true
baseStore.setLogoVisible(logoVisible) baseStore.setLogoVisible(logoVisible)
const view = route.query.view && Object.values(PROJECT_VIEWS).includes(route.query.view as ProjectView)
? route.query.view
: 'list'
const hash = LINK_SHARE_HASH_PREFIX + route.params.share const hash = LINK_SHARE_HASH_PREFIX + route.params.share
const last = getLastVisitedRoute() const last = getLastVisitedRoute()
@ -111,8 +106,11 @@ function useAuth() {
} }
return router.push({ return router.push({
name: `project.${view}`, name: 'project.view',
params: {projectId}, params: {
projectId,
viewId: route.query.view
},
hash, hash,
}) })
} catch (e) { } catch (e) {