Share mode works on new tasks
This commit is contained in:
+20
-3
@@ -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<Task>.
|
||||
// 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)
|
||||
|
||||
Reference in New Issue
Block a user