From 64af608596dd2dc0bdb6d08f104c58454db96526 Mon Sep 17 00:00:00 2001 From: debont80 Date: Wed, 1 Jul 2026 11:26:36 -0400 Subject: [PATCH] =?UTF-8?q?refactor(renderer):=20L132=20=E2=80=94=20share?= =?UTF-8?q?=20resetForm()=20across=20download=20+=20addPlaylist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extract the post-enqueue reset (URL + probe + one-shot trim/schedule/advanced/ incognito/options) into resetForm(), called by both download() and addPlaylist(). clearProbe() stays the lighter probe-only reset for onUrlChange. Also fixes a latent inconsistency: addPlaylist previously left the trim/schedule/advanced panels open after enqueuing a playlist. typecheck + eslint + prettier green. Co-Authored-By: Claude Opus 4.8 --- CODE-AUDIT.md | 7 +++- .../components/downloadBar/useDownloadBar.ts | 35 +++++++++++-------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/CODE-AUDIT.md b/CODE-AUDIT.md index 67bd0e4..e9cd382 100644 --- a/CODE-AUDIT.md +++ b/CODE-AUDIT.md @@ -770,7 +770,12 @@ token system + shared primitives (UI/SIMP — high value, larger effort) · i18n "interrupted"); user-facing ones are capitalized with periods. Fine when interpolated, jarring if shown raw. - [ ] **L131 — Taskbar `error` state is ephemeral** — it's driven by live `error` items, so "Clear finished" flips the red taskbar bar back to normal even though failures occurred (out of sync with the persisted error log). -- [ ] **L132 — `clearProbe` + form-reset logic is duplicated** in DownloadBar (`onUrlChange`, `download`, `addPlaylist`). +- [x] **L132 — `clearProbe` + form-reset logic is duplicated** in DownloadBar (`onUrlChange`, `download`, `addPlaylist`). + *Fixed: a shared `resetForm()` in [useDownloadBar.ts](src/renderer/src/components/downloadBar/useDownloadBar.ts) + now owns the post-enqueue reset (URL + probe + the one-shot trim/schedule/advanced/incognito/options), + called by both `download()` and `addPlaylist()`. `clearProbe()` stays the lighter probe-only reset for + `onUrlChange`. Also fixes a latent inconsistency — `addPlaylist` previously left the trim/schedule/advanced + panels open after enqueuing.* - [ ] **L133 — `Field` controls mix `aria-label` + visible `label`.** Many `Field label="X"` wrap a `Select aria-label="X"`, so AT announces the name twice (extends M20 across DownloadOptionsForm). - [ ] **L134 — Inconsistent disabled affordance for busy buttons.** Some stay enabled-looking with a diff --git a/src/renderer/src/components/downloadBar/useDownloadBar.ts b/src/renderer/src/components/downloadBar/useDownloadBar.ts index 133940e..cb9bd3e 100644 --- a/src/renderer/src/components/downloadBar/useDownloadBar.ts +++ b/src/renderer/src/components/downloadBar/useDownloadBar.ts @@ -243,6 +243,24 @@ export function useDownloadBar(): DownloadBarController { setItemKinds({}) } + // Reset the whole bar after a download / playlist is enqueued: clear the URL + + // probe and drop the one-shot overrides (trim / schedule / advanced / incognito / + // per-download options) so the next download starts from the global defaults. + // Shared by download() and addPlaylist() so a playlist add resets the same state + // a single download does (L132 — addPlaylist previously left trim/schedule open). + function resetForm(): void { + setUrl('') + setTrim('') + setShowTrim(false) + setScheduleAt('') + setShowSchedule(false) + setShowAdvanced(false) + setCommandPreview(null) + setIncognito(false) + setDownloadOptions(DEFAULT_DOWNLOAD_OPTIONS) + clearProbe() + } + // Fetch (or toggle off) the exact yt-dlp command line for the current form // state. The options mirror what download() sends so the preview matches the // command that will actually run -- including a probe-selected format and any @@ -454,19 +472,7 @@ export function useDownloadBar(): DownloadBarController { }) } - setUrl('') - setTrim('') - setShowTrim(false) - setScheduleAt('') - setShowSchedule(false) - setShowAdvanced(false) - setCommandPreview(null) - // Per-download overrides are one-shot (like trim/schedule): reset so the next - // download starts from the global defaults, and incognito never silently - // carries over to a following download. - setIncognito(false) - setDownloadOptions(DEFAULT_DOWNLOAD_OPTIONS) - clearProbe() + resetForm() } function downloadAnyway(): void { @@ -490,8 +496,7 @@ export function useDownloadBar(): DownloadBarController { } }) ) - setUrl('') - clearProbe() + resetForm() } return {