Fixed handoff staying on original user temporarily

This commit is contained in:
2026-02-17 15:59:49 -06:00
parent 9a3bd4cca3
commit 3d6e29d2c0
+25 -4
View File
@@ -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<Task>): Partial<Task> =>
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<Task>) => {
// 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"