Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

PWA share target implementation #129

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {LINK_SHARE_HASH_PREFIX} from '@/constants/linkShareHash'
import {useProjectStore} from '@/stores/projects'
import {useAuthStore} from '@/stores/auth'
import {useBaseStore} from '@/stores/base'
import {useTaskStore} from '@/stores/tasks'

import HomeComponent from '@/views/Home.vue'
import NotFoundComponent from '@/views/404.vue'
Expand Down Expand Up @@ -207,6 +208,40 @@ const router = createRouter({
component: TaskDetailView,
props: route => ({ taskId: Number(route.params.id as string) }),
},
{
path: '/tasks/create',
name: 'task.create',
beforeEnter: async (to, from, next) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put this logic in a new component.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how that would work, as there is no view for this. The intention is to show the newly created task (resulting in a TaskDetailView) and thus the logic is implemented in the beforeEnter handling instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you create a new view which does nothing but contains the logic you have here and then redirects (maybe show a loading spinner etc. while we're at it)? This kind of logic should not go into a beforeEnter handler.

const taskStore = useTaskStore()
const authStore = useAuthStore()
// Need to get settings populated first!
await authStore.checkAuth()

const defaultProjectId = authStore.settings.defaultProjectId
if(!defaultProjectId) {
return false
}

const title = to.query.title || 'Share'
const description = to.query.description as string

const task = await taskStore.createNewTask({
title,
projectId: defaultProjectId,
})

if (description) {
task.description = description
await taskStore.update(task)
RoboMagus marked this conversation as resolved.
Show resolved Hide resolved
}

console.log('Created task: ', task)
RoboMagus marked this conversation as resolved.
Show resolved Hide resolved

// After Task creation succeeds, redirect to show the task.
return next({name: 'task.detail', params: {id: task.id}})
},
component: TaskDetailView,
},
{
path: '/tasks/by/upcoming',
name: 'tasks.range',
Expand Down
9 changes: 9 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ export default defineConfig(({mode}) => {
url: '/teams',
},
],
share_target: {
action: '/tasks/create',
enctype: 'application/x-www-form-urlencoded',
RoboMagus marked this conversation as resolved.
Show resolved Hide resolved
method: 'GET',
params: {
title: 'title',
text: 'description',
},
},
},
}),
viteSentry(getSentryConfig(env)),
Expand Down