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