vibe-kanban icon indicating copy to clipboard operation
vibe-kanban copied to clipboard

feat: persist task creation drafts using scratch storage (Vibe Kanban)

Open stunningpixels opened this issue 4 months ago • 6 comments

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 DraftTaskData struct 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::DraftTask variant to use DraftTaskData instead of a plain String

Type Generation (crates/server/src/bin/generate_types.rs)

  • Added DraftTaskData to the list of exported TypeScript types

Frontend (frontend/src/components/dialogs/tasks/TaskFormDialog.tsx)

  • Integrated useScratch hook 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 repoBranches loading asynchronously

Implementation Details

  • Draft ID Strategy: Uses the project ID as the scratch key, allowing one draft per project
  • Debounced Saves: Uses useDebouncedCallback with 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 useEffect to sync repoBranches field 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

stunningpixels avatar Dec 18 '25 12:12 stunningpixels

Vibe Kanban Review Complete

Your code review is ready!

View Review

vibe-kanban-cloud[bot] avatar Dec 18 '25 12:12 vibe-kanban-cloud[bot]

!reviewfast

stunningpixels avatar Dec 18 '25 14:12 stunningpixels

Review Complete

Your review story is ready!

View Story

            Comment `!reviewfast` on this PR to re-generate the story.

vibe-kanban-cloud[bot] avatar Dec 18 '25 14:12 vibe-kanban-cloud[bot]

Finally jfc

stunningpixels avatar Dec 18 '25 14:12 stunningpixels

How is this triggered? When you close the task creation dialog you are forced to confirm that you want to discard unsaved changes.

ggordonhall avatar Dec 19 '25 11:12 ggordonhall

It's from our user in Japan who said sometimes their browser crashes and they lose their work

stunningpixels avatar Dec 19 '25 16:12 stunningpixels