Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions components/app-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface TasksContextType {
installDependencies: boolean
maxDuration: number
}) => { id: string; optimisticTask: Task }
removeTaskOptimistically: (taskId: string) => void
}

const TasksContext = createContext<TasksContextType | undefined>(undefined)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -302,6 +307,7 @@ export function AppLayout({ children, initialSidebarWidth, initialSidebarOpen, i
isSidebarOpen,
isSidebarResizing: isResizing,
addTaskOptimistically,
removeTaskOptimistically,
}}
>
<ConnectorsProvider>
Expand Down
8 changes: 3 additions & 5 deletions components/home-page-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down