From 11cd2cfff597e481551498986cead0c511f79a7e Mon Sep 17 00:00:00 2001 From: RoboMagus <68224306+RoboMagus@users.noreply.github.com> Date: Tue, 3 Oct 2023 20:44:37 +0200 Subject: [PATCH 1/4] Attempt at implementing PWA share handler --- src/sw.ts | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ vite.config.ts | 9 +++++++++ 2 files changed, 59 insertions(+) diff --git a/src/sw.ts b/src/sw.ts index f1892179e..3ce6f313a 100644 --- a/src/sw.ts +++ b/src/sw.ts @@ -3,11 +3,55 @@ import {getFullBaseUrl} from './helpers/getFullBaseUrl' +import {useTaskStore} from '@/stores/tasks' +import {useAuthStore} from '@/stores/auth' + declare let self: ServiceWorkerGlobalScope const fullBaseUrl = getFullBaseUrl() +const authStore = useAuthStore() +const taskStore = useTaskStore() const workboxVersion = 'v7.0.0' + +const shareTargetHandler = async ({event}) => { + console.log('share-target() ', event) + + // Form extraction works fine... + const formData = await event.request.formData() + console.log('FormData:() ', formData) + const title = formData.get('name') + const description = formData.get('description') + + console.log('shareTargetHandler(), title: ', title) + console.log('shareTargetHandler(), description: ', description) + + const defaultProjectId = authStore?.settings?.defaultProjectId + console.log('shareTargetHandler(), defaultProjectId: ', defaultProjectId) + + if (defaultProjectId) { + const task = await taskStore.createNewTask({ + title, + projectId: defaultProjectId, + }) + + if (description) { + task.description = description + } + + console.log('Created task with ID: ', task.id) + + // After Task creation succeeds, redirect to show the task. + const redirectionUrl = `${fullBaseUrl}tasks/${task.id}` + return Response.redirect(redirectionUrl, 303) + } + else { + // ToDo: improve handling of undefined default projectID + const redirectionUrl = `${fullBaseUrl}unspecified_default_project_id` + return Response.redirect(redirectionUrl, 303) + } +} + importScripts(`${fullBaseUrl}workbox-${workboxVersion}/workbox-sw.js`) workbox.setConfig({ modulePathPrefix: `${fullBaseUrl}workbox-${workboxVersion}`, @@ -30,6 +74,12 @@ workbox.routing.registerRoute( new workbox.strategies.NetworkOnly(), ) +workbox.routing.registerRoute( + '/_share-target', + shareTargetHandler, + 'POST', +) + // This code listens for the user's confirmation to update the app. self.addEventListener('message', (e) => { if (!e.data) { diff --git a/vite.config.ts b/vite.config.ts index d1eaf6771..784037741 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -202,6 +202,15 @@ export default defineConfig(({mode}) => { url: '/teams', }, ], + share_target: { + action: '/_share-target', + enctype: 'multipart/form-data', + method: 'POST', + params: { + title: 'name', + text: 'description', + }, + }, }, }), viteSentry(getSentryConfig(env)), From c17d1bdad0379b1808f1cd46e92f0fc8eeba13eb Mon Sep 17 00:00:00 2001 From: RoboMagus <68224306+RoboMagus@users.noreply.github.com> Date: Fri, 6 Oct 2023 20:30:35 +0200 Subject: [PATCH 2/4] Use 'GET' method for share_target --- src/router/index.ts | 70 +++++++++++++++++++++++++++++++++++++++++++++ src/sw.ts | 50 -------------------------------- vite.config.ts | 8 +++--- 3 files changed, 74 insertions(+), 54 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index d00b6d4c4..0666e26fb 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -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' @@ -207,6 +208,75 @@ 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) => { + const authStore = useAuthStore() + + let defaultProjectId = authStore.settings.defaultProjectId + if(!defaultProjectId) { + defaultProjectId = 5 + } + console.log('shareTargetHandler(), defaultProjectId: ', defaultProjectId) + if(!defaultProjectId) { + return false + } + + let title = to.query.title as string + const description = to.query.description as string + + console.log('Title: ', title) + console.log('Description: ', description) + + if (!title) { + title = 'Share' + } + const taskStore = useTaskStore() + const task = await taskStore.createNewTask({ + title, + projectId: defaultProjectId, + }) + + if (description) { + task.description = description + await taskStore.update(task) + } + + console.log('Created task with ID: ', task.id) + + // After Task creation succeeds, redirect to show the task. + return next({name: 'task.detail', params: {id: task.id}}) + }, + component: TaskDetailView, +// redirect(to) { +// const authStore = useAuthStore() +// const defaultProjectId = authStore.settings.defaultProjectId +// console.log('shareTargetHandler(), defaultProjectId: ', defaultProjectId) +// if(!defaultProjectId) { +// return false +// } +// +// const title = to.query.title as string +// const description = to.query.description as string +// const taskStore = useTaskStore() +// const task = await taskStore.createNewTask({ +// title, +// projectId: defaultProjectId, +// }) +// +// if (description) { +// task.description = description +// } +// +// console.log('Created task with ID: ', task.id) +// +// // After Task creation succeeds, redirect to show the task. +// return { +// path: to.path.replace('create', task.id), +// } +// }, + }, { path: '/tasks/by/upcoming', name: 'tasks.range', diff --git a/src/sw.ts b/src/sw.ts index 3ce6f313a..f1892179e 100644 --- a/src/sw.ts +++ b/src/sw.ts @@ -3,55 +3,11 @@ import {getFullBaseUrl} from './helpers/getFullBaseUrl' -import {useTaskStore} from '@/stores/tasks' -import {useAuthStore} from '@/stores/auth' - declare let self: ServiceWorkerGlobalScope const fullBaseUrl = getFullBaseUrl() -const authStore = useAuthStore() -const taskStore = useTaskStore() const workboxVersion = 'v7.0.0' - -const shareTargetHandler = async ({event}) => { - console.log('share-target() ', event) - - // Form extraction works fine... - const formData = await event.request.formData() - console.log('FormData:() ', formData) - const title = formData.get('name') - const description = formData.get('description') - - console.log('shareTargetHandler(), title: ', title) - console.log('shareTargetHandler(), description: ', description) - - const defaultProjectId = authStore?.settings?.defaultProjectId - console.log('shareTargetHandler(), defaultProjectId: ', defaultProjectId) - - if (defaultProjectId) { - const task = await taskStore.createNewTask({ - title, - projectId: defaultProjectId, - }) - - if (description) { - task.description = description - } - - console.log('Created task with ID: ', task.id) - - // After Task creation succeeds, redirect to show the task. - const redirectionUrl = `${fullBaseUrl}tasks/${task.id}` - return Response.redirect(redirectionUrl, 303) - } - else { - // ToDo: improve handling of undefined default projectID - const redirectionUrl = `${fullBaseUrl}unspecified_default_project_id` - return Response.redirect(redirectionUrl, 303) - } -} - importScripts(`${fullBaseUrl}workbox-${workboxVersion}/workbox-sw.js`) workbox.setConfig({ modulePathPrefix: `${fullBaseUrl}workbox-${workboxVersion}`, @@ -74,12 +30,6 @@ workbox.routing.registerRoute( new workbox.strategies.NetworkOnly(), ) -workbox.routing.registerRoute( - '/_share-target', - shareTargetHandler, - 'POST', -) - // This code listens for the user's confirmation to update the app. self.addEventListener('message', (e) => { if (!e.data) { diff --git a/vite.config.ts b/vite.config.ts index 784037741..b7d3f2032 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -203,11 +203,11 @@ export default defineConfig(({mode}) => { }, ], share_target: { - action: '/_share-target', - enctype: 'multipart/form-data', - method: 'POST', + action: '/tasks/create', + enctype: 'application/x-www-form-urlencoded', + method: 'GET', params: { - title: 'name', + title: 'title', text: 'description', }, }, From 427d336d8a11d41428947dd5a149682e068519ce Mon Sep 17 00:00:00 2001 From: RoboMagus <68224306+RoboMagus@users.noreply.github.com> Date: Fri, 6 Oct 2023 21:05:08 +0200 Subject: [PATCH 3/4] Cleanup + fix empty settings --- src/router/index.ts | 51 +++++++-------------------------------------- 1 file changed, 8 insertions(+), 43 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index 0666e26fb..252c16085 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -212,27 +212,19 @@ const router = createRouter({ path: '/tasks/create', name: 'task.create', beforeEnter: async (to, from, next) => { + const taskStore = useTaskStore() const authStore = useAuthStore() - - let defaultProjectId = authStore.settings.defaultProjectId - if(!defaultProjectId) { - defaultProjectId = 5 - } - console.log('shareTargetHandler(), defaultProjectId: ', defaultProjectId) + // Need to get settings populated first! + await authStore.checkAuth() + + const defaultProjectId = authStore.settings.defaultProjectId if(!defaultProjectId) { return false } - let title = to.query.title as string + const title = to.query.title || 'Share' const description = to.query.description as string - - console.log('Title: ', title) - console.log('Description: ', description) - - if (!title) { - title = 'Share' - } - const taskStore = useTaskStore() + const task = await taskStore.createNewTask({ title, projectId: defaultProjectId, @@ -243,39 +235,12 @@ const router = createRouter({ await taskStore.update(task) } - console.log('Created task with ID: ', task.id) + console.log('Created task: ', task) // After Task creation succeeds, redirect to show the task. return next({name: 'task.detail', params: {id: task.id}}) }, component: TaskDetailView, -// redirect(to) { -// const authStore = useAuthStore() -// const defaultProjectId = authStore.settings.defaultProjectId -// console.log('shareTargetHandler(), defaultProjectId: ', defaultProjectId) -// if(!defaultProjectId) { -// return false -// } -// -// const title = to.query.title as string -// const description = to.query.description as string -// const taskStore = useTaskStore() -// const task = await taskStore.createNewTask({ -// title, -// projectId: defaultProjectId, -// }) -// -// if (description) { -// task.description = description -// } -// -// console.log('Created task with ID: ', task.id) -// -// // After Task creation succeeds, redirect to show the task. -// return { -// path: to.path.replace('create', task.id), -// } -// }, }, { path: '/tasks/by/upcoming', From 4fd4f06d9a6ad477234880b9397cff1b108df559 Mon Sep 17 00:00:00 2001 From: RoboMagus <68224306+RoboMagus@users.noreply.github.com> Date: Tue, 10 Oct 2023 16:39:50 +0200 Subject: [PATCH 4/4] Simplify task creation with description --- src/router/index.ts | 10 ++-------- src/stores/tasks.ts | 2 ++ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index 252c16085..228c13fbf 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -223,19 +223,13 @@ const router = createRouter({ } const title = to.query.title || 'Share' - const description = to.query.description as string + const description = to.query.description || '' const task = await taskStore.createNewTask({ title, + description, projectId: defaultProjectId, }) - - if (description) { - task.description = description - await taskStore.update(task) - } - - console.log('Created task: ', task) // After Task creation succeeds, redirect to show the task. return next({name: 'task.detail', params: {id: task.id}}) diff --git a/src/stores/tasks.ts b/src/stores/tasks.ts index 3ea876dc5..920a9bbb5 100644 --- a/src/stores/tasks.ts +++ b/src/stores/tasks.ts @@ -399,6 +399,7 @@ export const useTaskStore = defineStore('task', () => { async function createNewTask({ title, + description, bucketId, projectId, position, @@ -435,6 +436,7 @@ export const useTaskStore = defineStore('task', () => { const task = new TaskModel({ title: cleanedTitle, + description: description, projectId: foundProjectId, dueDate, priority: parsedTask.priority,