after the fact handoff and clear search
CI / build (push) Has been skipped
CI / deploy (push) Successful in 1m9s

This commit is contained in:
2026-03-25 10:40:35 -05:00
parent e4f274034e
commit 9400a04fe2
3 changed files with 71 additions and 7 deletions
+44 -1
View File
@@ -1229,6 +1229,17 @@ export const isTaskCollaborativelyShared = (task: Task) =>
return ref.kind === "user" && policy === "collaborative" && !!targetUserId && targetUserId !== currentUserId;
});
export const canHandoffCollaborativelySharedTask = (task: Pick<Task, "shareRefs" | "ownerId">) => {
const currentUserId = pb.authStore.model?.id;
if (!currentUserId || !taskHasPersonalContextAccess(task, currentUserId)) return false;
return task.shareRefs.some(ref => {
if (ref.kind !== "user" || getTaskSharePolicy(ref) !== "collaborative") return false;
const targetUserId = getPersonalContextUserIdFromRef(ref);
return !!targetUserId && targetUserId !== currentUserId;
});
};
export const isTaskCollapsedUntilUpdated = (task: Task) =>
store.collapsedUntilUpdatedTasks[task.id] === task.updated;
@@ -1242,6 +1253,36 @@ export const expandCollapsedTask = (taskId: string) => {
void syncPreferences();
};
export const handoffCollaborativelySharedTask = async (taskId: string) => {
const task = store.tasks.find(existing => existing.id === taskId);
const currentUserId = pb.authStore.model?.id;
const senderPersonalContext = currentUserId ? getPersonalContext(currentUserId) : null;
if (!task || !currentUserId || !senderPersonalContext) return false;
if (!canHandoffCollaborativelySharedTask(task)) {
toast.info("This task needs another collaborative @user before you can hand it off.");
return false;
}
const nextShareRefs = task.shareRefs.filter(ref => !(
ref.kind === "user" &&
(ref.contextId === senderPersonalContext.id || ref.key === senderPersonalContext.key)
));
const didUpdate = await updateTask(taskId, {
shareRefs: nextShareRefs,
labelTags: task.labelTags,
noteRefs: task.noteRefs,
tags: buildTaskTags(task.labelTags, nextShareRefs, task.noteRefs, getFavoriteTag())
});
if (didUpdate) {
toast.success("Task handed off successfully.");
}
return didUpdate;
};
// Auto-persist changes to localStorage (wrapped in root to avoid console warning)
createRoot(() => {
createEffect(() => {
@@ -2929,7 +2970,7 @@ const checkForHandoffs = (task: Task, updates: Partial<Task>): Partial<Task> =>
};
export const updateTask = async (id: string, updates: Partial<Task>) => {
if (!pb.authStore.isValid) return;
if (!pb.authStore.isValid) return false;
// 0. Check for Hand-off Logic (Tag-based ownership transfer)
const currentTask = store.tasks.find(t => t.id === id);
@@ -3025,9 +3066,11 @@ export const updateTask = async (id: string, updates: Partial<Task>) => {
// Disable auto-cancellation for updates to prevent aborted errors during rapid typing
await pb.collection(TASGRID_COLLECTION).update(id, pbUpdates, { requestKey: null });
return true;
} catch (err) {
console.error("update failed", err);
toast.error("Failed to update task.");
return false;
}
};