refactor(search): remove smart mode from SearchFilterBar

Removes SmartModeToggle component import and all smart-mode conditional logic from SearchFilterBar, including mode-specific input handling, max-length constraints, and CSS class toggling. Removes associated smart-mode tests that verified chip lifecycle callbacks (onModeToggle, onSmartSearch).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-06-07 18:55:42 +02:00
committed by marcel
parent b790a6f823
commit 2bb1433822
2 changed files with 2 additions and 61 deletions

View File

@@ -3,7 +3,6 @@ import PersonTypeahead from '$lib/person/PersonTypeahead.svelte';
import TagInput from '$lib/tag/TagInput.svelte';
import DateInput from '$lib/shared/primitives/DateInput.svelte';
import SortDropdown from '$lib/shared/primitives/SortDropdown.svelte';
import SmartModeToggle from './search/SmartModeToggle.svelte';
import { slide } from 'svelte/transition';
import { m } from '$lib/paraglide/messages.js';
@@ -21,15 +20,12 @@ let {
sort = $bindable('DATE'),
dir = $bindable('desc'),
showAdvanced = $bindable(false),
smartMode = $bindable(false),
initialSenderName = '',
initialReceiverName = '',
navKey = 0,
isLoading = false,
onSearch,
onSearchImmediate,
onSmartSearch,
onModeToggle,
onfocus,
onblur
}: {
@@ -46,28 +42,16 @@ let {
sort?: string;
dir?: string;
showAdvanced?: boolean;
smartMode?: boolean;
initialSenderName?: string;
initialReceiverName?: string;
navKey?: number;
isLoading?: boolean;
onSearch: () => void;
onSearchImmediate?: () => void;
onSmartSearch?: () => void;
onModeToggle?: () => void;
onfocus?: () => void;
onblur?: () => void;
} = $props();
// In smart mode the keyword search must not fire on every keystroke — the NL
// query is submitted only on Enter (or an explicit button click).
function onSearchKeydown(event: KeyboardEvent) {
if (smartMode && event.key === 'Enter') {
event.preventDefault();
onSmartSearch?.();
}
}
// Plain (non-reactive) flag — not $state, so no reactive assignment inside $effect
let sortDirMounted = false;
@@ -92,19 +76,13 @@ $effect(() => {
<input
type="text"
bind:value={q}
oninput={smartMode ? undefined : onSearch}
onkeydown={onSearchKeydown}
oninput={onSearch}
onfocus={onfocus}
onblur={onblur}
maxlength={smartMode ? 500 : undefined}
aria-label={m.docs_search_placeholder()}
placeholder={m.docs_search_placeholder()}
class="block w-full border-line py-2.5 pl-10 placeholder-ink-3 shadow-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring {smartMode
? 'pr-28'
: 'pr-20'}"
class="block w-full border-line py-2.5 pr-20 pl-10 placeholder-ink-3 shadow-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring"
/>
<!-- Decorative search icon / loading spinner — left slot keeps the right
slot free for the always-visible smart-mode toggle pill. -->
<div class="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">
{#if isLoading}
<svg
@@ -132,7 +110,6 @@ $effect(() => {
/>
{/if}
</div>
<SmartModeToggle bind:smartMode={smartMode} onToggle={onModeToggle} />
</div>
<!-- Sort Dropdown -->

View File

@@ -195,39 +195,3 @@ describe('SearchFilterBar tagQ live filter', () => {
vi.unstubAllGlobals();
});
});
describe('SearchFilterBar smart-mode chip lifecycle hooks', () => {
// The interpretation chips live in the result area (parent page). SearchFilterBar
// drives chip-clearing through callbacks: onModeToggle (mode switch) and
// onSmartSearch (new query). These tests pin that contract.
it('invokes onModeToggle when toggling back to keyword mode (parent clears chips)', async () => {
const onModeToggle = vi.fn();
render(SearchFilterBar, {
...defaultProps,
sort: 'DATE',
dir: 'desc',
smartMode: true,
onModeToggle
});
await page.getByRole('button', { name: /Smart/ }).click();
expect(onModeToggle).toHaveBeenCalledOnce();
});
it('invokes onSmartSearch when a new query is submitted in smart mode (parent resets chips)', async () => {
const onSmartSearch = vi.fn();
render(SearchFilterBar, {
...defaultProps,
sort: 'DATE',
dir: 'desc',
smartMode: true,
onSmartSearch
});
const input = page.getByPlaceholder('Titel, Personen, Tags durchsuchen…');
await input.fill('Walter im Krieg');
await input.click();
(document.activeElement as HTMLElement).dispatchEvent(
new KeyboardEvent('keydown', { key: 'Enter', bubbles: true })
);
await vi.waitFor(() => expect(onSmartSearch).toHaveBeenCalled());
});
});