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

View file

@ -1,12 +1,16 @@
import { authenticate } from '$lib/utils/auth'; import { authenticate } from '$lib/utils/auth';
import { api } from '@api'; import { SearchResponseDto, api } from '@api';
import type { PageLoad } from './$types'; import type { PageLoad } from './$types';
export const load = (async (data) => { export const load = (async (data) => {
await authenticate(); await authenticate();
const url = new URL(data.url.href); const url = new URL(data.url.href);
const term = url.searchParams.get('q') || url.searchParams.get('query') || undefined; 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 { return {
term, term,