Fix autodraft settings panel not reflecting auto-disable after pick #50

Merged
chrisp merged 1 commit from fix/autodraft-settings-stale-state into main 2026-05-24 01:35:13 +00:00
Owner

Summary

  • Reconnect sync: useDraftAuthRecovery now syncs userAutodraft (settings badge/panel) from loader data after revalidation, alongside the existing autodraftStatus sync. Previously the draft grid updated correctly on reconnect but the settings panel showed stale state.
  • Toast logic: Replaced fragile client-side mode inference (prev.mode === "next_pick") with an explicit reason field ("pick_complete" | "queue_empty") added to the server's autodraft-updated emit. This fixes two toast bugs caught in code review: the wrong toast showing when a user manually disables next_queue autodraft, and the wrong toast showing when next_queue's queue empties.
  • Cleanup: Removes the now-unused userAutodraftRef (previously used to read prev.mode for toast logic) from useDraftAuthRecovery, its call site, and useDraftSocketEvents.

Test plan

  • Set autodraft to Next in Queue with queue items → wait for pick to fire → toast "Autodraft turned off — next pick complete" appears, settings badge shows Off
  • Set autodraft to Next in Queue with empty queue → autodraft disables → toast "Autodraft disabled — your queue is empty" appears (not "next pick complete")
  • Manually click Off while in Next in Queue mode → no toast (user-initiated, source: "user" is filtered out by the data.reason check)
  • Set autodraft to All in Queue → let queue drain → toast "Autodraft disabled — your queue is empty" still works
  • Trigger autodraft pick, disconnect socket, reconnect → settings badge still shows Off (revalidation sync fix)
## Summary - **Reconnect sync**: `useDraftAuthRecovery` now syncs `userAutodraft` (settings badge/panel) from loader data after revalidation, alongside the existing `autodraftStatus` sync. Previously the draft grid updated correctly on reconnect but the settings panel showed stale state. - **Toast logic**: Replaced fragile client-side mode inference (`prev.mode === "next_pick"`) with an explicit `reason` field (`"pick_complete"` | `"queue_empty"`) added to the server's `autodraft-updated` emit. This fixes two toast bugs caught in code review: the wrong toast showing when a user manually disables next_queue autodraft, and the wrong toast showing when next_queue's queue empties. - **Cleanup**: Removes the now-unused `userAutodraftRef` (previously used to read `prev.mode` for toast logic) from `useDraftAuthRecovery`, its call site, and `useDraftSocketEvents`. ## Test plan - [ ] Set autodraft to **Next in Queue** with queue items → wait for pick to fire → toast "Autodraft turned off — next pick complete" appears, settings badge shows **Off** - [ ] Set autodraft to **Next in Queue** with empty queue → autodraft disables → toast "Autodraft disabled — your queue is empty" appears (not "next pick complete") - [ ] Manually click **Off** while in Next in Queue mode → no toast (user-initiated, `source: "user"` is filtered out by the `data.reason` check) - [ ] Set autodraft to **All in Queue** → let queue drain → toast "Autodraft disabled — your queue is empty" still works - [ ] Trigger autodraft pick, disconnect socket, reconnect → settings badge still shows **Off** (revalidation sync fix)
chrisp added 1 commit 2026-05-24 01:29:32 +00:00
Fix autodraft settings panel not reflecting auto-disable after pick
All checks were successful
🚀 Deploy / 🧪 Test (pull_request) Successful in 1m24s
🚀 Deploy / ʦ TypeScript (pull_request) Successful in 1m13s
🚀 Deploy / 🔍 Lint (pull_request) Successful in 45s
🚀 Deploy / 🐳 Build (pull_request) Has been skipped
🚀 Deploy / 🚀 Deploy (pull_request) Has been skipped
e3a7a1a9b1
When next_queue autodraft fires and turns itself off, two bugs prevented
the UI from behaving correctly:

1. After reconnect, useDraftAuthRecovery synced autodraftStatus (draft
   grid) but not userAutodraft (settings panel), leaving the settings
   badge stale until the next page load.

2. Toast notifications for autodraft auto-disable were unreliable: the
   condition checked prev.mode rather than why the server disabled it,
   causing the wrong toast for manual disables and queue-empty events.

Fix the reconnect sync by calling setUserAutodraft in the revalidation
effect alongside setAutodraftStatus. Fix the toast logic by adding a
reason field ("pick_complete" | "queue_empty") to the server's
autodraft-updated emit, so the client can show the right message without
guessing from local state. Also removes the now-unused userAutodraftRef.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
chrisp scheduled this pull request to auto merge when all checks succeed 2026-05-24 01:35:10 +00:00
chrisp merged commit 425b4724d2 into main 2026-05-24 01:35:13 +00:00
chrisp deleted branch fix/autodraft-settings-stale-state 2026-05-24 01:35:14 +00:00
Sign in to join this conversation.
No description provided.