feat(web): search improvements and refactor (#7291)

This commit is contained in:
Michel Heusschen
2024-02-21 16:50:50 +01:00
committed by GitHub
parent 06c134950a
commit d3e14fd662
6 changed files with 151 additions and 211 deletions
+1 -26
View File
@@ -1,34 +1,9 @@
import { QueryParameter } from '$lib/constants';
import { searchQuery } from '$lib/stores/search.store';
import { authenticate } from '$lib/utils/auth';
import {
searchMetadata,
searchSmart,
type MetadataSearchDto,
type SearchResponseDto,
type SmartSearchDto,
} from '@immich/sdk';
import type { PageLoad } from './$types';
export const load = (async (data) => {
export const load = (async () => {
await authenticate();
const url = new URL(data.url.href);
const term =
url.searchParams.get(QueryParameter.SEARCH_TERM) || url.searchParams.get(QueryParameter.QUERY) || undefined;
let results: SearchResponseDto | null = null;
if (term) {
const payload = JSON.parse(term) as SmartSearchDto | MetadataSearchDto;
searchQuery.set(payload);
results =
payload && 'query' in payload
? await searchSmart({ smartSearchDto: { ...payload, withExif: true, isVisible: true } })
: await searchMetadata({ metadataSearchDto: { ...payload, withExif: true, isVisible: true } });
}
return {
term,
results,
meta: {
title: 'Search',
},