ADR-0057: Guard unsaved category drafts on Back
- Status: Accepted
- Date: 2026-10-17
Context
Toolbar and system Back on the category editor returned to Budgets and dropped name, icon, and monthly-limit edits (issue #155). The transaction and Settings editors already guard their dirty exits, so the category flow was inconsistent.
Decision
Compare the editable draft — name, icon, and budget text — against a baseline published after the asynchronous load or a successful save. Toolbar and system Back share one guard: a changed draft offers Save, Discard, and Keep editing; a pristine or fully reverted draft leaves directly. The IME and the icon picker consume Back first.
Save validates and persists before leaving; validation or persistence errors keep the editor open with the draft and error visible. Discard leaves without writing anything, so cancelling never clears or re-scopes an effective limit — blanking the field clears it only once the user saves, per ADR-0036. The navigation-scoped ViewModel retains the draft and the confirmation uses saved Compose state, so configuration changes do not lose a draft or raise a false prompt. No process-death recovery is provided.
Consequences
Ordinary Back requires an explicit choice before dropping edits. No schema or money-semantics change is introduced; selected month, currency, inheritance, and carry-forward stay per ADR-0036.
Verification
CategoryEditViewModelTest covers pristine, changed, reverted, create, and successfully saved baselines. CategoryEditContentTest covers toolbar and system Back, Keep editing, Discard, guarded Save, and failed Save.