feat: persist task creation drafts using scratch storage (Vibe Kanban)
Summary
This PR implements draft persistence for the task creation dialog, allowing users to recover their work if they accidentally close the dialog or navigate away.
Changes Made
Backend (crates/db/src/models/scratch.rs)
- Added new
DraftTaskDatastruct to store task draft information:-
title: The draft task title -
description: The draft task description -
auto_start: Whether to auto-start the task on creation
-
- Updated
ScratchPayload::DraftTaskvariant to useDraftTaskDatainstead of a plainString
Type Generation (crates/server/src/bin/generate_types.rs)
- Added
DraftTaskDatato the list of exported TypeScript types
Frontend (frontend/src/components/dialogs/tasks/TaskFormDialog.tsx)
- Integrated
useScratchhook for draft persistence (only in create mode) - Added debounced auto-save (500ms) for title, description, and auto-start settings
- Load saved drafts when opening the create task dialog
- Clear drafts on successful task creation or when user explicitly discards changes
- Fixed timing issue where form validation failed on page reload due to
repoBranchesloading asynchronously
Implementation Details
- Draft ID Strategy: Uses the project ID as the scratch key, allowing one draft per project
-
Debounced Saves: Uses
useDebouncedCallbackwith 500ms delay to avoid excessive API calls - Graceful Degradation: If the scratch WebSocket fails to connect, the form still works (just without draft persistence)
-
Form Validation Fix: Added
useEffectto syncrepoBranchesfield when branches finish loading, ensuring the Create button enables correctly when loading a saved draft
Why These Changes
Users reported losing their task descriptions when accidentally closing the dialog or navigating away. This feature leverages the existing scratch infrastructure (already used for follow-up message drafts) to provide automatic draft saving without requiring explicit user action.
This PR was written using Vibe Kanban
!reviewfast
Review Complete
Your review story is ready!
Comment `!reviewfast` on this PR to re-generate the story.
Finally jfc
How is this triggered? When you close the task creation dialog you are forced to confirm that you want to discard unsaved changes.
It's from our user in Japan who said sometimes their browser crashes and they lose their work