1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-25 10:43:13 +02:00

fix(web): access /search throw error (#5834)

This commit is contained in:
Alex 2023-12-18 14:42:25 -06:00 committed by GitHub
parent 085dc6cd93
commit 9834693fab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -36,7 +36,7 @@
// behavior for history.back(). To prevent that we store the previous page
// manually and navigate back to that.
let previousRoute = AppRoute.EXPLORE as string;
$: albums = data.results.albums.items;
$: albums = data.results?.albums.items;
const onKeyboardPress = (event: KeyboardEvent) => handleKeyboardPress(event);
@ -98,10 +98,10 @@
$: isMultiSelectionMode = selectedAssets.size > 0;
$: isAllArchived = Array.from(selectedAssets).every((asset) => asset.isArchived);
$: isAllFavorite = Array.from(selectedAssets).every((asset) => asset.isFavorite);
$: searchResultAssets = data.results.assets.items;
$: searchResultAssets = data.results?.assets.items;
const onAssetDelete = (assetId: string) => {
searchResultAssets = searchResultAssets.filter((a: AssetResponseDto) => a.id !== assetId);
searchResultAssets = searchResultAssets?.filter((a: AssetResponseDto) => a.id !== assetId);
};
const handleSelectAll = () => {
selectedAssets = new Set(searchResultAssets);
@ -140,7 +140,7 @@
<section class="relative mb-12 bg-immich-bg pt-32 dark:bg-immich-dark-bg">
<section class="immich-scrollbar relative overflow-y-auto">
{#if albums.length}
{#if albums && albums.length}
<section>
<div class="ml-6 text-4xl font-medium text-black/70 dark:text-white/80">ALBUMS</div>
<div class="grid grid-cols-[repeat(auto-fill,minmax(14rem,1fr))]">
@ -161,7 +161,7 @@
</section>
{/if}
<section id="search-content" class="relative bg-immich-bg dark:bg-immich-dark-bg">
{#if searchResultAssets.length > 0}
{#if searchResultAssets && searchResultAssets.length > 0}
<div class="pl-4">
<GalleryViewer assets={searchResultAssets} bind:selectedAssets showArchiveIcon={true} />
</div>

View File

@ -1,12 +1,16 @@
import { authenticate } from '$lib/utils/auth';
import { api } from '@api';
import { SearchResponseDto, api } from '@api';
import type { PageLoad } from './$types';
export const load = (async (data) => {
await authenticate();
const url = new URL(data.url.href);
const term = url.searchParams.get('q') || url.searchParams.get('query') || undefined;
const { data: results } = await api.searchApi.search({}, { params: url.searchParams });
let results: SearchResponseDto | null = null;
if (term) {
const { data } = await api.searchApi.search({}, { params: url.searchParams });
results = data;
}
return {
term,