From 6195e2875ed0b678e8f4cd17aba71ba68a33994c Mon Sep 17 00:00:00 2001 From: Timothy Cardoza Date: Tue, 17 Feb 2026 19:12:55 -0600 Subject: [PATCH] Share mode works on new tasks --- src/store/index.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/store/index.ts b/src/store/index.ts index b8daa48..81099f9 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -1017,7 +1017,7 @@ export const addTask = async (title: string, options?: { dueDate?: Date | string const size = options?.size ?? 5; const tempId = "temp-" + Date.now(); - const newTask: Task = { + const initialTask: Task = { id: tempId, title, startDate, @@ -1033,12 +1033,17 @@ export const addTask = async (title: string, options?: { dueDate?: Date | string updated: new Date().toISOString() }; + // Apply Handoff Logic (e.g. transfer ownership if tagging for another user) + // We treat the entire new task as "updates" to check against itself + const handoffUpdates = checkForHandoffs(initialTask, initialTask); + const newTask = { ...initialTask, ...handoffUpdates }; + // Optimistic UI update setStore("tasks", (t) => [newTask, ...t]); try { const record = await pb.collection(TASGRID_COLLECTION).create({ - user: pb.authStore.model?.id, + user: newTask.ownerId, // Use the (potentially updated) ownerId title, startDate, dueDate, @@ -1047,7 +1052,19 @@ export const addTask = async (title: string, options?: { dueDate?: Date | string completed: false, tags, content, - size + size, + // If checking for handoffs added specific sharedWith, we might need to handle that, + // but currently checkForHandoffs modifies ownerId/sharedWith. + // PB API expects 'sharedWith' if we want to set it, but our types might be complex? + // Wait, checkForHandoffs returns Partial. + // If it sets ownerId to someone else, we rely on 'user' field in create. + // If it sets sharedWith (e.g. for bucket rule clearing), we need to send that too? + // Standard create doesn't support 'sharedWith' directly in this code block usually? + // Let's check mapRecordToTask. sharedWith comes from record expansion usually. + // But if we are creating, we might need to set standard relation fields if they exist. + // However, the original code didn't set sharedWith. + // The handoff logic usually just changes OWNER. + // If it changes owner, 'user' field covers it. }); // Replace temp task with real record (merging server fields like id, created, updated)