From 3d6e29d2c0e2d0df2a66f3b781041d74120ee7db Mon Sep 17 00:00:00 2001 From: Timothy Cardoza Date: Tue, 17 Feb 2026 15:59:49 -0600 Subject: [PATCH] Fixed handoff staying on original user temporarily --- src/store/index.ts | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/store/index.ts b/src/store/index.ts index 8000d7f..880db46 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -25,7 +25,7 @@ export interface Task { priority: number; // 1-10 completed: boolean; tags: string[]; - ownerId: string; // Add ownerId to interface + ownerId: string | null; // Add ownerId to interface content?: string; // HTML content from Tiptap deletedAt?: number; // Timestamp of soft delete created: string; // ISO string from PB @@ -389,7 +389,7 @@ const mapRecordToTask = (r: any): Task => { priority: r.priority, completed: r.completed, tags: tags, - ownerId: r.user, + ownerId: r.user || null, content: r.content, deletedAt: r.deletedAt ? new Date(r.deletedAt).getTime() : undefined, created: r.created, @@ -1097,6 +1097,19 @@ const checkForHandoffs = (task: Task, updates: Partial): Partial => if (rule) { console.log(`Handoff triggered by tag "${tag}" -> Transferring to ${rule.targetUserId}`); + + // Check if it's a bucket tag (target is self, but tag is a bucket) + const isBucketRule = rule.targetUserId === currentUserId && store.tagDefinitions.find(t => t.name === tag)?.isBucket; + + if (isBucketRule) { + return { + ...updates, + ownerId: null, // Unassign from current user (null is better for PB relations) + // Remove current user from sharedWith to ensure it disappears from their view + sharedWith: (task.sharedWith || []).filter(s => s.userId !== currentUserId) + }; + } + return { ...updates, ownerId: rule.targetUserId, @@ -1132,8 +1145,8 @@ export const updateTask = async (id: string, updates: Partial) => { // Check for specific fields being updated const pbUpdates: any = { ...finalUpdates }; - if (finalUpdates.ownerId) { - pbUpdates.user = finalUpdates.ownerId; // Map ownerId to 'user' field in PB + if (finalUpdates.ownerId !== undefined) { + pbUpdates.user = finalUpdates.ownerId || null; // Map ownerId to 'user' field in PB delete pbUpdates.ownerId; } @@ -1335,6 +1348,7 @@ export const syncSystemTagsAndRules = async () => { const normalizedRules = pbRules.map(r => ({ id: r.id, + ownerId: r.ownerId, targetUserId: r.targetUserId, type: r.type, tagName: r.tagName @@ -1364,6 +1378,13 @@ export const syncSystemTagsAndRules = async () => { } catch (e) { console.error(`Failed to create bucket tag ${bucket.name}`, e); } + } else if (!tagExists.isBucket) { + try { + await pb.collection(TAGS_COLLECTION).update(tagExists.id, { isBucket: true }); + setStore("tagDefinitions", d => d.id === tagExists.id, { isBucket: true }); + } catch (e) { + console.error(`Failed to flag tag ${bucket.name} as bucket`, e); + } } // --- Sync Bucket System Rule --- // Ensure a ShareRule exists for this bucket so it appears in "System Rules"