refactor(documents): split triggerSearch by zoom semantics (#385)

triggerSearch(zoomOverride?) made the call site read "depends on
whether the source event happened to include zoomFrom/zoomTo". Splits
into triggerSearchKeepZoom() and triggerSearchWithZoom(from, to) so
the contract is explicit at every call site. Closes Felix's review
nit.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-08 10:02:02 +02:00
parent 52827ccc87
commit 77d282bbeb

View File

@@ -81,10 +81,23 @@ function buildSearchParams(filters: FilterSnapshot, targetPage?: number): Svelte
} }
/** /**
* Rebuilds the URL from the CURRENT local filter state. `page` is intentionally * Rebuilds the URL from the CURRENT local filter state, preserving the zoom
* not carried over — any filter change implicitly resets back to page 0. * range carried in `data.zoom{From,To}`. `page` is intentionally not carried
* over — any filter change implicitly resets back to page 0.
*/ */
function triggerSearch(zoomOverride?: { zoomFrom: string | null; zoomTo: string | null }) { function triggerSearchKeepZoom() {
navigateWithZoom(data.zoomFrom ?? null, data.zoomTo ?? null);
}
/**
* Rebuilds the URL from the CURRENT local filter state and replaces the zoom
* range with the provided values (or clears it if both are null).
*/
function triggerSearchWithZoom(zoomFrom: string | null, zoomTo: string | null) {
navigateWithZoom(zoomFrom, zoomTo);
}
function navigateWithZoom(zoomFrom: string | null, zoomTo: string | null) {
const params = buildSearchParams({ const params = buildSearchParams({
q, q,
from, from,
@@ -96,8 +109,8 @@ function triggerSearch(zoomOverride?: { zoomFrom: string | null; zoomTo: string
dir, dir,
tagQ, tagQ,
tagOp: tagOperator, tagOp: tagOperator,
zoomFrom: zoomOverride ? zoomOverride.zoomFrom : data.zoomFrom, zoomFrom,
zoomTo: zoomOverride ? zoomOverride.zoomTo : data.zoomTo zoomTo
}); });
goto(`/documents?${params.toString()}`, { keepFocus: true, noScroll: true }); goto(`/documents?${params.toString()}`, { keepFocus: true, noScroll: true });
} }
@@ -130,12 +143,12 @@ function buildPageHref(targetPage: number): string {
function handleTextSearch() { function handleTextSearch() {
clearTimeout(searchTimer); clearTimeout(searchTimer);
searchTimer = setTimeout(() => triggerSearch(), 500); searchTimer = setTimeout(() => triggerSearchKeepZoom(), 500);
} }
function handleImmediateSearch() { function handleImmediateSearch() {
clearTimeout(searchTimer); clearTimeout(searchTimer);
triggerSearch(); triggerSearchKeepZoom();
} }
// Trigger search reactively when the tag list changes. // Trigger search reactively when the tag list changes.
@@ -144,7 +157,7 @@ $effect(() => {
const cur = tagNames.map((t) => t.name).join(','); const cur = tagNames.map((t) => t.name).join(',');
if (cur !== prevTagStr) { if (cur !== prevTagStr) {
prevTagStr = cur; prevTagStr = cur;
triggerSearch(); triggerSearchKeepZoom();
} }
}); });
@@ -256,19 +269,13 @@ $effect(() => {
// Drag commits filter + zoom atomically (Graylog-style range selector). // Drag commits filter + zoom atomically (Graylog-style range selector).
// Single click and clear omit zoomFrom/zoomTo so existing zoom is preserved. // Single click and clear omit zoomFrom/zoomTo so existing zoom is preserved.
if ('zoomFrom' in event) { if ('zoomFrom' in event) {
triggerSearch({ triggerSearchWithZoom(event.zoomFrom ?? null, event.zoomTo ?? null);
zoomFrom: event.zoomFrom ?? null,
zoomTo: event.zoomTo ?? null
});
} else { } else {
triggerSearch(); triggerSearchKeepZoom();
} }
}} }}
onzoomchange={(event) => { onzoomchange={(event) => {
triggerSearch({ triggerSearchWithZoom(event?.zoomFrom ?? null, event?.zoomTo ?? null);
zoomFrom: event?.zoomFrom ?? null,
zoomTo: event?.zoomTo ?? null
});
}} }}
/> />
</div> </div>