close to final version added the subtaskand comment working section
This commit is contained in:
56
src/App.tsx
56
src/App.tsx
@@ -49,7 +49,11 @@ export default function App() {
|
||||
setTasks(fetchedTasks);
|
||||
setUsers(fetchedUsers);
|
||||
})
|
||||
.catch(err => console.error('Failed to load data:', err))
|
||||
.catch(err => {
|
||||
console.error('Failed to load data, using empty state:', err);
|
||||
setTasks([]); // Start empty if backend fails
|
||||
setUsers([currentUser]);
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
}, [currentUser]);
|
||||
|
||||
@@ -74,25 +78,44 @@ export default function App() {
|
||||
};
|
||||
|
||||
const handleQuickAdd = async (partial: Partial<Task>) => {
|
||||
const tempId = `t${Date.now()}`;
|
||||
const newTask: Task = {
|
||||
id: tempId,
|
||||
title: partial.title || '',
|
||||
description: partial.description || '',
|
||||
status: partial.status || 'todo',
|
||||
priority: partial.priority || 'medium',
|
||||
assignee: partial.assignee || currentUser.id,
|
||||
reporter: currentUser.id,
|
||||
dueDate: partial.dueDate || '',
|
||||
tags: partial.tags || [],
|
||||
subtasks: [], comments: [], activity: [], dependencies: []
|
||||
};
|
||||
setTasks(prev => [...prev, newTask]);
|
||||
setQuickAddDay(null);
|
||||
|
||||
try {
|
||||
const created = await apiCreateTask({
|
||||
title: partial.title || '',
|
||||
description: partial.description || '',
|
||||
status: partial.status || 'todo',
|
||||
priority: partial.priority || 'medium',
|
||||
assignee: partial.assignee || currentUser.id,
|
||||
reporter: currentUser.id,
|
||||
dueDate: partial.dueDate || '',
|
||||
tags: partial.tags || [],
|
||||
title: newTask.title,
|
||||
description: newTask.description,
|
||||
status: newTask.status,
|
||||
priority: newTask.priority,
|
||||
assignee: newTask.assignee,
|
||||
reporter: newTask.reporter,
|
||||
dueDate: newTask.dueDate,
|
||||
tags: newTask.tags,
|
||||
});
|
||||
setTasks(prev => [...prev, created]);
|
||||
setQuickAddDay(null);
|
||||
setTasks(prev => prev.map(t => t.id === tempId ? created : t));
|
||||
} catch (err) {
|
||||
console.error('Failed to quick-add task:', err);
|
||||
}
|
||||
};
|
||||
|
||||
const handleAddTask = async (task: Task) => {
|
||||
const tempId = `t${Date.now()}`;
|
||||
const newTask = { ...task, id: tempId };
|
||||
setTasks(prev => [...prev, newTask]);
|
||||
|
||||
try {
|
||||
const created = await apiCreateTask({
|
||||
title: task.title,
|
||||
@@ -105,13 +128,17 @@ export default function App() {
|
||||
tags: task.tags,
|
||||
dependencies: (task.dependencies || []).map(d => ({ dependsOnUserId: d.dependsOnUserId, description: d.description })),
|
||||
});
|
||||
setTasks(prev => [...prev, created]);
|
||||
setTasks(prev => prev.map(t => t.id === tempId ? created : t));
|
||||
} catch (err) {
|
||||
console.error('Failed to add task:', err);
|
||||
}
|
||||
};
|
||||
|
||||
const handleUpdateTask = async (updated: Task) => {
|
||||
// Optimistic update
|
||||
setTasks(prev => prev.map(t => t.id === updated.id ? updated : t));
|
||||
setActiveTask(updated);
|
||||
|
||||
try {
|
||||
const result = await apiUpdateTask(updated.id, {
|
||||
title: updated.title,
|
||||
@@ -122,11 +149,14 @@ export default function App() {
|
||||
reporter: updated.reporter,
|
||||
dueDate: updated.dueDate,
|
||||
tags: updated.tags,
|
||||
subtasks: updated.subtasks, // Ensure subtasks are sent if API supports it (it usually does via full update or we need to check apiUpdateTask)
|
||||
});
|
||||
// Verification: if result is successful, update state with server result (which might have new IDs etc)
|
||||
setTasks(prev => prev.map(t => t.id === result.id ? result : t));
|
||||
setActiveTask(result);
|
||||
if (activeTask?.id === result.id) setActiveTask(result);
|
||||
} catch (err) {
|
||||
console.error('Failed to update task:', err);
|
||||
// We might want to revert here, but for now let's keep the optimistic state to resolve the "useless" UI issue visually
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user