refactor: simplify after self-review

- drop the redundant isLoadingMore boolean from the background-loading
  store; derive from inFlight > 0 in the selector
- pull _active_source_root_paths out of get_library_stats and reuse it
  from get_duplicate_groups (same is_active + admin-scope check, now
  in one place)
- drop p.rstrip('/') in the duplicates folder-scope filter (SourceRoot
  paths are never written with a trailing slash)
- match Timeline's initial-load affordance to the new bottom indicator
  (Loader2 spinner + ellipsis instead of plain "Loading photos...")
- trim narrative comments that explained what the surrounding code does

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
claudio
2026-05-13 20:50:17 +02:00
parent 5e2823ae94
commit 4e1af0f356
4 changed files with 34 additions and 70 deletions

View File

@@ -5,11 +5,8 @@ import { usePhotosBackgroundLoadingStore } from '../store/photosBackgroundLoadin
import api from '../services/api'
import type { Photo } from '../types/photo'
/** Reactive selector for the "more pages still streaming" flag. Used by
* thumbnail views to render a bottom-of-list spinner while
* usePhotosQuery's background cursor loop is still pulling pages. */
export function usePhotosLoadingMore(): boolean {
return usePhotosBackgroundLoadingStore((s) => s.isLoadingMore)
return usePhotosBackgroundLoadingStore((s) => s.inFlight > 0)
}
/**
@@ -108,12 +105,10 @@ export function usePhotosQuery() {
if (nextCursor) {
// Fire-and-forget background loop using cursor chaining.
// The background store is reactive — Timeline et al. subscribe
// to render a "loading more…" indicator at the bottom of the
// grid while pages keep arriving. start/stop is balanced in a
// try/finally so an aborted/erroring loop can't leak the flag.
const bg = usePhotosBackgroundLoadingStore.getState()
bg.start()
// start/stop balanced in try/finally so an aborted or erroring
// loop can't leak the in-flight counter that drives the
// bottom-of-grid spinner.
usePhotosBackgroundLoadingStore.getState().start()
void (async () => {
try {
for (let i = 0; i < MAX_PAGES && nextCursor; i++) {