mirror of
https://github.com/immich-app/immich.git
synced 2025-06-02 21:24:28 -04:00
fix(web): update search results when searching from info panel (#16729)
* fix(web): update search results when searching from info panel * Prevent double search when using search bar * Format/lint * Fix infinite loading on intersect * Remove redundant function
This commit is contained in:
parent
d72d715f6b
commit
a75718ce99
@ -19,10 +19,9 @@
|
|||||||
value?: string;
|
value?: string;
|
||||||
grayTheme: boolean;
|
grayTheme: boolean;
|
||||||
searchQuery?: MetadataSearchDto | SmartSearchDto;
|
searchQuery?: MetadataSearchDto | SmartSearchDto;
|
||||||
onSearch?: () => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let { value = $bindable(''), grayTheme, searchQuery = {}, onSearch }: Props = $props();
|
let { value = $bindable(''), grayTheme, searchQuery = {} }: Props = $props();
|
||||||
|
|
||||||
let showClearIcon = $derived(value.length > 0);
|
let showClearIcon = $derived(value.length > 0);
|
||||||
|
|
||||||
@ -43,7 +42,6 @@
|
|||||||
showFilter = false;
|
showFilter = false;
|
||||||
$isSearchEnabled = false;
|
$isSearchEnabled = false;
|
||||||
await goto(`${AppRoute.SEARCH}?${params}`);
|
await goto(`${AppRoute.SEARCH}?${params}`);
|
||||||
onSearch?.();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const clearSearchTerm = (searchTerm: string) => {
|
const clearSearchTerm = (searchTerm: string) => {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { afterNavigate, goto } from '$app/navigation';
|
import { afterNavigate, goto } from '$app/navigation';
|
||||||
import { page } from '$app/stores';
|
import { page } from '$app/state';
|
||||||
import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte';
|
import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte';
|
||||||
import Icon from '$lib/components/elements/icon.svelte';
|
import Icon from '$lib/components/elements/icon.svelte';
|
||||||
import AddToAlbum from '$lib/components/photos-page/actions/add-to-album.svelte';
|
import AddToAlbum from '$lib/components/photos-page/actions/add-to-album.svelte';
|
||||||
@ -22,14 +22,14 @@
|
|||||||
import { preventRaceConditionSearchBar } from '$lib/stores/search.store';
|
import { preventRaceConditionSearchBar } from '$lib/stores/search.store';
|
||||||
import { shortcut } from '$lib/actions/shortcut';
|
import { shortcut } from '$lib/actions/shortcut';
|
||||||
import {
|
import {
|
||||||
|
type AlbumResponseDto,
|
||||||
type AssetResponseDto,
|
type AssetResponseDto,
|
||||||
|
getPerson,
|
||||||
|
getTagById,
|
||||||
|
type MetadataSearchDto,
|
||||||
searchAssets,
|
searchAssets,
|
||||||
searchSmart,
|
searchSmart,
|
||||||
getPerson,
|
|
||||||
type SmartSearchDto,
|
type SmartSearchDto,
|
||||||
type MetadataSearchDto,
|
|
||||||
type AlbumResponseDto,
|
|
||||||
getTagById,
|
|
||||||
} from '@immich/sdk';
|
} from '@immich/sdk';
|
||||||
import { mdiArrowLeft, mdiDotsVertical, mdiImageOffOutline, mdiPlus, mdiSelectAll } from '@mdi/js';
|
import { mdiArrowLeft, mdiDotsVertical, mdiImageOffOutline, mdiPlus, mdiSelectAll } from '@mdi/js';
|
||||||
import type { Viewport } from '$lib/stores/assets-store.svelte';
|
import type { Viewport } from '$lib/stores/assets-store.svelte';
|
||||||
@ -42,7 +42,7 @@
|
|||||||
import AlbumCardGroup from '$lib/components/album-page/album-card-group.svelte';
|
import AlbumCardGroup from '$lib/components/album-page/album-card-group.svelte';
|
||||||
import { isAlbumsRoute, isPeopleRoute } from '$lib/utils/navigation';
|
import { isAlbumsRoute, isPeopleRoute } from '$lib/utils/navigation';
|
||||||
import { t } from 'svelte-i18n';
|
import { t } from 'svelte-i18n';
|
||||||
import { onMount, tick } from 'svelte';
|
import { tick } from 'svelte';
|
||||||
import AssetJobActions from '$lib/components/photos-page/actions/asset-job-actions.svelte';
|
import AssetJobActions from '$lib/components/photos-page/actions/asset-job-actions.svelte';
|
||||||
import { preferences } from '$lib/stores/user.store';
|
import { preferences } from '$lib/stores/user.store';
|
||||||
import TagAction from '$lib/components/photos-page/actions/tag-action.svelte';
|
import TagAction from '$lib/components/photos-page/actions/tag-action.svelte';
|
||||||
@ -57,7 +57,7 @@
|
|||||||
// manually and navigate back to that.
|
// manually and navigate back to that.
|
||||||
let previousRoute = $state(AppRoute.EXPLORE as string);
|
let previousRoute = $state(AppRoute.EXPLORE as string);
|
||||||
|
|
||||||
let nextPage: number | null = 1;
|
let nextPage = $state(1);
|
||||||
let searchResultAlbums: AlbumResponseDto[] = $state([]);
|
let searchResultAlbums: AlbumResponseDto[] = $state([]);
|
||||||
let searchResultAssets: AssetResponseDto[] = $state([]);
|
let searchResultAssets: AssetResponseDto[] = $state([]);
|
||||||
let isLoading = $state(true);
|
let isLoading = $state(true);
|
||||||
@ -67,16 +67,18 @@
|
|||||||
const assetInteraction = new AssetInteraction();
|
const assetInteraction = new AssetInteraction();
|
||||||
|
|
||||||
type SearchTerms = MetadataSearchDto & Pick<SmartSearchDto, 'query'>;
|
type SearchTerms = MetadataSearchDto & Pick<SmartSearchDto, 'query'>;
|
||||||
let searchQuery = $derived($page.url.searchParams.get(QueryParameter.QUERY));
|
let searchQuery = $derived(page.url.searchParams.get(QueryParameter.QUERY));
|
||||||
|
let smartSearchEnabled = $derived($featureFlags.loaded && $featureFlags.smartSearch);
|
||||||
onMount(() => {
|
|
||||||
if (terms && $featureFlags.loaded) {
|
|
||||||
handlePromiseError(onSearchQueryUpdate());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let terms = $derived(searchQuery ? JSON.parse(searchQuery) : {});
|
let terms = $derived(searchQuery ? JSON.parse(searchQuery) : {});
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
||||||
|
terms;
|
||||||
|
setTimeout(() => {
|
||||||
|
handlePromiseError(onSearchQueryUpdate());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const onEscape = () => {
|
const onEscape = () => {
|
||||||
if ($showAssetViewer) {
|
if ($showAssetViewer) {
|
||||||
return;
|
return;
|
||||||
@ -100,7 +102,7 @@
|
|||||||
|
|
||||||
afterNavigate(({ from }) => {
|
afterNavigate(({ from }) => {
|
||||||
// Prevent setting previousRoute to the current page.
|
// Prevent setting previousRoute to the current page.
|
||||||
if (from?.url && from.route.id !== $page.route.id) {
|
if (from?.url && from.route.id !== page.route.id) {
|
||||||
previousRoute = from.url.href;
|
previousRoute = from.url.href;
|
||||||
}
|
}
|
||||||
const route = from?.route?.id;
|
const route = from?.route?.id;
|
||||||
@ -152,14 +154,14 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const { albums, assets } =
|
const { albums, assets } =
|
||||||
'query' in searchDto && $featureFlags.smartSearch
|
'query' in searchDto && smartSearchEnabled
|
||||||
? await searchSmart({ smartSearchDto: searchDto })
|
? await searchSmart({ smartSearchDto: searchDto })
|
||||||
: await searchAssets({ metadataSearchDto: searchDto });
|
: await searchAssets({ metadataSearchDto: searchDto });
|
||||||
|
|
||||||
searchResultAlbums.push(...albums.items);
|
searchResultAlbums.push(...albums.items);
|
||||||
searchResultAssets.push(...assets.items);
|
searchResultAssets.push(...assets.items);
|
||||||
|
|
||||||
nextPage = assets.nextPage ? Number(assets.nextPage) : null;
|
nextPage = Number(assets.nextPage) || 0;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error, $t('loading_search_results_failed'));
|
handleError(error, $t('loading_search_results_failed'));
|
||||||
} finally {
|
} finally {
|
||||||
@ -280,12 +282,7 @@
|
|||||||
<div class="fixed z-[100] top-0 left-0 w-full">
|
<div class="fixed z-[100] top-0 left-0 w-full">
|
||||||
<ControlAppBar onClose={() => goto(previousRoute)} backIcon={mdiArrowLeft}>
|
<ControlAppBar onClose={() => goto(previousRoute)} backIcon={mdiArrowLeft}>
|
||||||
<div class="w-full flex-1 pl-4">
|
<div class="w-full flex-1 pl-4">
|
||||||
<SearchBar
|
<SearchBar grayTheme={false} value={terms?.query ?? ''} searchQuery={terms} />
|
||||||
grayTheme={false}
|
|
||||||
value={terms?.query ?? ''}
|
|
||||||
searchQuery={terms}
|
|
||||||
onSearch={() => handlePromiseError(onSearchQueryUpdate())}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</ControlAppBar>
|
</ControlAppBar>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user