Skip to content

feat: auto-regenerate preview on settings change#3

Merged
esmcelroy merged 3 commits intomainfrom
copilot/auto-generate-preview-on-settings-change
May 6, 2026
Merged

feat: auto-regenerate preview on settings change#3
esmcelroy merged 3 commits intomainfrom
copilot/auto-generate-preview-on-settings-change

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 22, 2026

Previously, changing any padding setting required a manual "Process Images" click to see the result. A stale "Settings changed — re-process to apply" warning was the only feedback.

Changes

src/App.tsx

  • Replaces the settingsChangedSinceProcess state + amber warning with a debounced auto-process on every settings change
  • Two new refs drive this safely:
    • handleProcessRef — updated after every render via a no-dep useEffect, so the debounce timer always invokes the closure with the freshest photos/settings
    • autoProcessTimerRef — cancels the previous timer on rapid changes (e.g. dragging a slider), firing only 400 ms after the last change
// syncs ref to freshest handleProcess after every render
useEffect(() => { handleProcessRef.current = handleProcess; });

// debounced auto-process; only fires when photos are already loaded
useEffect(() => {
  if (isInitialMountRef.current) { isInitialMountRef.current = false; return; }
  if (photos.length === 0) return;
  clearTimeout(autoProcessTimerRef.current);
  autoProcessTimerRef.current = setTimeout(() => handleProcessRef.current(), 400);
  return () => clearTimeout(autoProcessTimerRef.current);
}, [settings]); // eslint-disable-line react-hooks/exhaustive-deps
  • onChange handler simplified — setIsProcessed(false) hides the Download button during the debounce window; it reappears once auto-processing completes
  • "Process Images" button retained for the initial manual trigger and as a fallback

src/__tests__/App.test.tsx

  • Asserts the removed warning never appears after a settings change
  • Asserts Download All as ZIP disappears on settings change then reappears once the debounced auto-process completes

- Add debounced (400 ms) useEffect that triggers handleProcess whenever
  settings change and photos are already loaded.
- Use a handleProcessRef + per-render useEffect to always call the freshest
  handleProcess, avoiding stale closures in the debounce timer.
- Remove settingsChangedSinceProcess state and the "Settings changed —
  re-process to apply" warning message (auto-process replaces that UX).
- Add two new unit tests: one verifying the warning is absent, one
  verifying auto-process fires after a settings change.

Agent-Logs-Url: https://github.com/esmcelroy/squarify/sessions/9b00372e-735c-4c91-bf66-2eef355fb148

Co-authored-by: esmcelroy <3530006+esmcelroy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add automatic preview generation on settings change feat: auto-regenerate preview on settings change Apr 22, 2026
Copilot AI requested a review from esmcelroy April 22, 2026 00:48
@github-actions
Copy link
Copy Markdown

🎭 Playwright UI Test Results

✅ All UI tests passed

View full report →

@esmcelroy esmcelroy marked this pull request as ready for review April 22, 2026 16:39
Copy link
Copy Markdown
Owner

@esmcelroy esmcelroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Can we ensure linting passes

- e2e/settings.spec.ts: remove unused createLandscapePng/uploadTestImage imports
- App.test.tsx: replace `as any` with `as unknown as <T>` for matchMedia and FileReader mocks
- PhotoGrid.test.tsx: remove unused beforeEach import; replace `as any` with `as unknown as <T>` for anchor/ClipboardItem/fetch mocks
- heicUtils.test.ts: replace `as any` with `as unknown as HTMLCanvasElement` in createElement mocks
- useDarkMode.test.ts: replace `as any` with `as unknown as typeof window.matchMedia`
- imageUtils.test.ts: remove unused WatermarkPosition import; drop unused _quality param; fix no-this-alias by using arrow function in property setter; remove unused result variables

Agent-Logs-Url: https://github.com/esmcelroy/squarify/sessions/10d4fd08-d586-4419-a6d9-aeb5da278869

Co-authored-by: esmcelroy <3530006+esmcelroy@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 6, 2026

@copilot Can we ensure linting passes

Fixed in bff56dc. The 21 pre-existing ESLint errors were spread across 6 files:

  • e2e/settings.spec.ts — removed unused createLandscapePng/uploadTestImage imports
  • App.test.tsx — replaced as any with as unknown as <T> for the matchMedia and FileReader mocks
  • PhotoGrid.test.tsx — removed unused beforeEach import; replaced as any with typed casts for anchor/ClipboardItem/fetch mocks
  • heicUtils.test.ts — replaced as any with as unknown as HTMLCanvasElement in the createElement spy
  • useDarkMode.test.ts — replaced as any with as unknown as typeof window.matchMedia
  • imageUtils.test.ts — removed unused WatermarkPosition import, unused _quality param, unused result variables; fixed no-this-alias by converting the set accessor to an arrow function

npm run lint now exits cleanly with zero errors.

Copilot AI requested a review from esmcelroy May 6, 2026 19:36
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

🎭 Playwright UI Test Results

✅ All UI tests passed

View full report →

@esmcelroy esmcelroy merged commit 29bb849 into main May 6, 2026
4 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.

The preview should automatically be generated on settings change

2 participants