Skip to content

feat(web): one save model for settings (#4074, #3991) - #4248

Merged
vavallee merged 11 commits into
mainfrom
feat/4074-unified-settings-save
Dec 2, 2026
Merged

vavallee merged 11 commits into
mainfrom
feat/4074-unified-settings-save

Conversation

@vavallee

@vavallee vavallee commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

Closes #4074
Closes #3991

Part of #3995.

Maintainer decision to confirm

This PR picks the save model. It is a deliberate choice for the maintainer to confirm or overrule:

  • Discrete controls (toggle, select, radio, checkbox) save immediately on change, with the toast and a revert on failure. This is what feat(web): toast on every Settings save that happens on change (#3991) #4070 already did.
  • Text fields commit on blur or Enter, never per keystroke and not on a debounce. They save only when the value changed and passes the field's validation, with the same toast and the same revert on failure. Esc restores the saved value. There is no per field Save button.

Why not debounced autosave for text: a half typed root folder, naming template, API key or URL must not be persisted mid typing. A debounce would still save "/data/li" on a pause.

What changed

One shared hook and component, then the tabs migrated onto it:

  • useCommitField (new) holds the model: commit on blur or Enter (Ctrl or Cmd + Enter in a textarea), skip when unchanged or invalid, claim the value up front so Enter then blur saves once, Esc undo, revert on failure, status for a dirty, saving, saved or error line. It calls the existing useAutoSave, so the toast text, live region and revert bookkeeping from feat(web): toast on every Settings save that happens on change (#3991) #4070 are reused. The toast names the setting and never the value.
  • CommitInput and CommitTextarea (new, CommitField.tsx) wrap it with the status line under the field. The status joins aria-describedby only while it has something to say, so the existing "Current:" descriptions are unchanged when idle.
  • NamingTemplateField uses the hook directly. Token chips now keep focus in the input on mouse down, so picking a token is not a blur and does not commit a half built template.
  • SaveButton is removed, it has no caller left. useSaveResult stays, the hook uses it.
  • Settings deep links and search results used to focus the first focusable thing in the anchor, which on the naming templates was a token chip. They now prefer the input, select or textarea, since the field is the whole point of the link now that there is no Save button next to it (SettingsPage.tsx).

Secrets (Google Books key, Hardcover token, Calibre plugin key, Advanced secret rows): commit on blur or Enter, an empty or whitespace value is never sent, the box empties after a save (the value is write only), masking and autofill opt outs unchanged, value never in a toast or log.

Inventory of per field Save buttons

Tab Field Result
General / File Naming Drop folder migrated (CommitInput, inline server error kept)
Audiobook drop folder migrated
Import source folders migrated (CommitTextarea)
Book naming template migrated (NamingTemplateField, validation blocks the commit)
Audiobook naming template migrated
Audiobook per track file template migrated
General / Schedules Preferred language became a select that saves on change (discrete)
Reject title words migrated (CommitTextarea)
API Keys Google Books key migrated (secret)
Hardcover API token migrated (secret). Clear and Test stay, they are actions, not saves
Logs Log retention days migrated, validated 1 to 365
Calibre Library path migrated
calibredb binary path migrated (warning from the save response kept)
Plugin URL migrated
Plugin API key migrated (secret)
Push path remap migrated
CWA ingest path migrated
Metadata Latest book count migrated (its hand rolled saved, in flight and Escape code is removed)
Advanced string, duration, int rows migrated, compared with the stored value
secret rows migrated
bool and enum rows now save on change with the toast (the Save button is gone, they had no toast)

Deliberately left as explicit Save forms, because their fields are only valid together or live in a modal:

  • Indexers: add and edit modal, Prowlarr connection form
  • Download clients: add and edit modal (host, port, credentials, category)
  • Notifications: add and edit modal
  • Quality and Metadata profile editors (modal)
  • Audiobookshelf, BookOrbit and Grimmory connection forms (URL, key and target belong together, Test connection depends on the saved set)
  • OIDC provider add and edit form
  • Import tab per list Hardcover token override: one secret inside a list row with its own Clear and open or close state, it is an action on that list rather than a settings field

Review round 2 (added after the independent review)

  • validate (frontend) fixed: mobilePolish.test.ts now checks the Commit field wrapper classes. The whole web/src vitest set (3121 tests) and tsc and eslint pass locally.
  • A commit asked for while a save is in flight (type a, Enter, type ab, blur) is queued and runs after it. A test fails without the queue.
  • A failed secret save keeps the typed text and leaves the field unsaved with an error toast and a retry hint.
  • An edit left in a field when it unmounts (tab or route change) is flushed when it is valid. Deliberately not flushed: secrets (a half pasted key should not be sent on the way out) and invalid values (nothing valid to send).
  • "Unsaved" and "not valid" are announced once per state change in a polite status region, not per keystroke. Saving, Saved and failures stay with the toast.
  • Latest book count migrated to CommitInput. RanobeDB toggle now toasts and reverts.
  • Tests that fail when the Hardcover token or log retention validation is removed.
  • nb and sv now say "unsaved" and "not saved" differently. Orphaned saveKey and hardcoverSaveToken keys removed from all locales.
  • Hardcover Test and Clear are no longer disabled during the token save, they wait for it, so a click that blurs the box is not lost.
  • A late loaded value is the saved one from its first render (baseline set during render), so no "Unsaved" flash.
  • User guide and changelog fragment updated.

The model itself (commit on blur or Enter for text, instant for discrete controls) is still a maintainer decision to confirm.

Review order

  1. useCommitField.ts, CommitField.tsx and useCommitField.test.tsx. This is the whole model, review it first.
  2. General and File Naming (GeneralTab.tsx, NamingTemplateField.tsx) and their tests.
  3. API Keys and Logs.
  4. Calibre.
  5. Advanced, and the SaveButton removal.
  6. SettingsPage.tsx focus tweak, the deep link test, docs and the changelog fragment.

Each step is its own commit and builds on its own.

Tests

  • useCommitField.test.tsx: no save while typing, commit on blur, commit on Enter, Enter then blur saves once, Esc reverts without a request, unchanged value not saved, invalid value not saved and flagged, failure toasts an alert and restores the value, dirty state shown, textarea Enter vs Ctrl+Enter, the toast never contains the value.
  • At least one migrated field per tab type through the real tab: General (drop folders, templates, reject words), API Keys, Logs, Calibre, Advanced.
  • Deep link: /settings?tab=naming#naming.bookTemplate lands the cursor in the template input, Esc undoes, Enter saves once (SettingsPage.test.tsx).
  • Fail before: with the old GeneralTab, NamingTemplateField and SettingsPage checked out from main, the new tests fail. The deep link test also failed on its own against the unchanged focus logic (focus landed on a token chip).
  • Ran locally: src/pages/settings, src/pages/SettingsPage* and src/i18n (854 tests), tsc --noEmit, eslint on the touched folders. CI runs the rest.

i18n

Three new strings under settings.commit in en, nb and sv (real translations, no filler). fr has no settings.toast, so it is left to fall back.

Docs

docs/User-Guide-Wiki.md "How Settings save" is rewritten, and the "Current:" paragraph no longer says fields with a Save button are left out. README does not mention Save buttons. Fragment: changelog.d/4074-unified-settings-save.md.

🤖 Generated with Claude Code

… fields (#4074)

Text fields save on blur or Enter when the value changed and validates, with
the useAutoSave toast and a revert on failure. Escape undoes. Dirty, saving,
saved and error are shown under the field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Signed-off-by: vavallee <vavallee@protonmail.com>
#4074)

Drop folders, import source folders, the three naming templates and reject
words lose their Save buttons and use CommitInput, CommitTextarea or the
naming template field. The preferred language select saves on change.
Token chips keep focus in the template so picking one is not a commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Signed-off-by: vavallee <vavallee@protonmail.com>
…or Enter (#4074)

The Google Books key and Hardcover token never send an empty value and empty
their box after a save, since the saved secret is write only. Log retention
is validated to 1 to 365 before it is sent. The status line only joins the
accessible description while it has something to say.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Signed-off-by: vavallee <vavallee@protonmail.com>
…blur or Enter (#4074)

Six per field Save buttons go. The server's reason for a rejected value stays
under the field and the saved value comes back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Signed-off-by: vavallee <vavallee@protonmail.com>
…ums on change (#4074)

Text, number and secret rows commit on blur or Enter against the stored
value. Toggles and enums save at once with the toast. The shared SaveButton
has no caller left and is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Signed-off-by: vavallee <vavallee@protonmail.com>
…ield (#4074)

User guide section rewritten for commit on blur or Enter, changelog fragment,
and a Settings deep link or search result now focuses the field control
before any button in the anchor, with a test through the real naming tab.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Signed-off-by: vavallee <vavallee@protonmail.com>
@vavallee vavallee added this to the v1.54.0 milestone Dec 2, 2026
@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

vavallee and others added 5 commits December 1, 2026 21:00
…e old input class (#4074)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

Signed-off-by: vavallee <vavallee@protonmail.com>
… secret, flush on unmount and announce state (#4074)

Blur or Enter during a save runs after it. A failed secret keeps its text and
stays unsaved. A valid plain edit is flushed when the field unmounts, never a
secret. Unsaved and invalid are announced in a polite status region. A late
loaded value is the saved one from its first render. nb and sv get distinct
real translations, and the orphaned saveKey and hardcoverSaveToken keys go.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

Signed-off-by: vavallee <vavallee@protonmail.com>
…er Test and Clear wait for the token save (#4074)

Tests fail without the Hardcover and retention validation.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

Signed-off-by: vavallee <vavallee@protonmail.com>
…r Clear waiting and the RanobeDB failure path (#4074)

The kept state now covers any failed save where the revert was skipped, not
only secrets. Clear is proven to wait for a pending token save.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

Signed-off-by: vavallee <vavallee@protonmail.com>
const dropEdit = useCallback((key: string) => {
setEdits(e => {
const next = { ...e }
delete next[key]
const saveSetting = async (key: string, onSaved?: (res: SettingSaveResult | undefined) => void, value?: string): Promise<string | null> => {
try {
const res = await api.setSetting(key, settings[key] ?? '')
const res = await api.setSetting(key, value ?? settings[key] ?? '')
useTranslation: () => ({
t: (key: string, fallback?: unknown, opts?: Record<string, string>) => {
if (typeof fallback !== 'string') return key
return fallback.replace(/\{\{(\w+)\}\}/g, (_, k) => opts?.[k] ?? '')
@vavallee
vavallee marked this pull request as ready for review December 2, 2026 03:18
@vavallee
vavallee merged commit f2b5c03 into main Dec 2, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Settings: unify the per field Save buttons into one save model feat(web): one save model for settings with a toast on every save

2 participants