From f075cfe32d872781dea3bf6ae312f6a6f4f625f9 Mon Sep 17 00:00:00 2001 From: Wayne <5291640+ringoinca@users.noreply.github.com> Date: Mon, 21 Jul 2025 17:47:25 +0300 Subject: [PATCH] Search options --- .../backend/src/services/SearchService.ts | 1 - .../routes/dashboard/search/+page.server.ts | 27 +---------- .../src/routes/dashboard/search/+page.svelte | 45 ++++++++++++------- 3 files changed, 29 insertions(+), 44 deletions(-) diff --git a/packages/backend/src/services/SearchService.ts b/packages/backend/src/services/SearchService.ts index 3d3b48b..91dfc89 100644 --- a/packages/backend/src/services/SearchService.ts +++ b/packages/backend/src/services/SearchService.ts @@ -35,7 +35,6 @@ export class SearchService { public async searchEmails(dto: SearchQuery): Promise { const { query, filters, page = 1, limit = 10, matchingStrategy = 'last' } = dto; - console.log('matchingStrategy ', matchingStrategy); const index = await this.getIndex('emails'); const searchParams: SearchParams = { diff --git a/packages/frontend/src/routes/dashboard/search/+page.server.ts b/packages/frontend/src/routes/dashboard/search/+page.server.ts index 63a3ba5..cda6ac1 100644 --- a/packages/frontend/src/routes/dashboard/search/+page.server.ts +++ b/packages/frontend/src/routes/dashboard/search/+page.server.ts @@ -1,7 +1,6 @@ -import type { PageServerLoad, Actions, RequestEvent } from './$types'; +import type { PageServerLoad, RequestEvent } from './$types'; import { api } from '$lib/server/api'; import type { SearchResult } from '@open-archiver/types'; -import { redirect } from '@sveltejs/kit'; import type { MatchingStrategy } from '@open-archiver/types'; @@ -49,27 +48,3 @@ export const load: PageServerLoad = async (event) => { 'last') as MatchingStrategy; return performSearch(keywords, page, matchingStrategy, event); }; - -export const actions: Actions = { - default: async (event) => { - const formData = await event.request.formData(); - const keywords = formData.get('keywords') as string; - const matchingStrategy = formData.get('matchingStrategy') as MatchingStrategy; - - if (keywords) { - throw redirect( - 303, - `/dashboard/search?keywords=${encodeURIComponent( - keywords - )}&page=1&matchingStrategy=${matchingStrategy}` - ); - } - - return { - searchResult: null, - keywords: '', - page: 1, - matchingStrategy: 'last' - }; - } -}; diff --git a/packages/frontend/src/routes/dashboard/search/+page.svelte b/packages/frontend/src/routes/dashboard/search/+page.svelte index fb87360..67c80e0 100644 --- a/packages/frontend/src/routes/dashboard/search/+page.svelte +++ b/packages/frontend/src/routes/dashboard/search/+page.svelte @@ -11,15 +11,16 @@ CardDescription } from '$lib/components/ui/card'; import { onMount } from 'svelte'; + import { goto } from '$app/navigation'; import { Skeleton } from '$lib/components/ui/skeleton'; import type { MatchingStrategy } from '@open-archiver/types'; let { data }: { data: PageData } = $props(); let searchResult = $derived(data.searchResult); - let keywords = $derived(data.keywords); + let keywords = $state(data.keywords || ''); let page = $derived(data.page); let error = $derived(data.error); - let matchingStrategy: MatchingStrategy = $derived( + let matchingStrategy: MatchingStrategy = $state( (data.matchingStrategy as MatchingStrategy) || 'last' ); @@ -57,6 +58,14 @@ }; } + function handleSearch() { + const params = new URLSearchParams(); + params.set('keywords', keywords); + params.set('page', '1'); + params.set('matchingStrategy', matchingStrategy); + goto(`/dashboard/search?${params.toString()}`, { keepFocus: true }); + } + function getHighlightedSnippets(text: string | undefined, snippetLength = 80): string[] { if (!text || !text.includes('')) { return []; @@ -163,30 +172,32 @@

Email Search

-
+
-
- - - {triggerContent} - - - {#each strategies as strategy (strategy.value)} - - {strategy.label} - - {/each} - - +
Search options
+
+ + + {triggerContent} + + + {#each strategies as strategy (strategy.value)} + + {strategy.label} + + {/each} + + +
{#if error}