diff --git a/components/app-layout.tsx b/components/app-layout.tsx index 991c27d..9f3071c 100644 --- a/components/app-layout.tsx +++ b/components/app-layout.tsx @@ -31,6 +31,7 @@ interface TasksContextType { installDependencies: boolean maxDuration: number }) => { id: string; optimisticTask: Task } + removeTaskOptimistically: (taskId: string) => void } const TasksContext = createContext(undefined) @@ -253,6 +254,10 @@ export function AppLayout({ children, initialSidebarWidth, initialSidebarOpen, i return { id, optimisticTask } } + const removeTaskOptimistically = (taskId: string) => { + setTasks((prevTasks) => prevTasks.filter((task) => task.id !== taskId)) + } + const closeSidebar = () => { updateSidebarOpen(false, false) // Don't save to cookie for mobile backdrop clicks } @@ -302,6 +307,7 @@ export function AppLayout({ children, initialSidebarWidth, initialSidebarOpen, i isSidebarOpen, isSidebarResizing: isResizing, addTaskOptimistically, + removeTaskOptimistically, }} > diff --git a/components/home-page-content.tsx b/components/home-page-content.tsx index 72843b2..001557c 100644 --- a/components/home-page-content.tsx +++ b/components/home-page-content.tsx @@ -47,7 +47,7 @@ export function HomePageContent({ const [loadingGitHub, setLoadingGitHub] = useState(false) const router = useRouter() const searchParams = useSearchParams() - const { refreshTasks, addTaskOptimistically } = useTasks() + const { refreshTasks, addTaskOptimistically, removeTaskOptimistically } = useTasks() const setTaskPrompt = useSetAtom(taskPromptAtom) // Multi-repo mode state @@ -320,14 +320,12 @@ export function HomePageContent({ const error = await response.json() // Show detailed message for rate limits, or generic error message toast.error(error.message || error.error || 'Failed to create task') - // TODO: Remove the optimistic task on error - await refreshTasks() // For now, just refresh to remove the optimistic task + removeTaskOptimistically(id) } } catch (error) { console.error('Error creating task:', error) toast.error('Failed to create task') - // TODO: Remove the optimistic task on error - await refreshTasks() // For now, just refresh to remove the optimistic task + removeTaskOptimistically(id) } finally { setIsSubmitting(false) }