Skip to content

Commit

Permalink
Merge pull request #241 from hearchco/as/fix/snapshot-preview
Browse files Browse the repository at this point in the history
fix: snapshot the preview, removed snapshoting query since it's in url
  • Loading branch information
aleksasiriski authored Apr 27, 2024
2 parents 70eaa28 + 3c88d10 commit 5a03e33
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/lib/components/search/display/Display.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
export let currentPage: number;
export let results: ResultType[];
export let paramsString: string;
export let imgResultPreview: ResultType | undefined;
// variables
const category: string = categoryFrom(query);
</script>

<!-- todo: await deep results and offer button to switch to them -->
{#if category === CategoryEnum.IMAGES}
<Images bind:query bind:currentPage bind:results bind:paramsString />
<Images bind:query bind:currentPage bind:results bind:paramsString bind:imgResultPreview />
{:else if category !== undefined}
<Results bind:query bind:currentPage bind:results />
{:else}
Expand Down
20 changes: 11 additions & 9 deletions src/routes/search/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@
// types
import type { PageData, Snapshot } from './$types';
import type { ResultType } from '$lib/types/result';
// parameters
export let data: PageData;
let query: string = data.query;
let currentPage: number = data.currentPage;
let paramsString: string = data.params;
// TODO: implement a option for setting maxPages, allowing user to choose how much results to show
// let maxPages: number = data.maxPages;
// variables
let query = data.query;
let currentPage = data.currentPage;
let paramsString = data.params;
// TODO: implement a option for setting maxPages, allowing user to choose how much results to show
// let maxPages = data.maxPages;
$: title = query === '' ? 'Hearchco Search' : `${query} | Hearchco Search`;
// snapshots
export const snapshot: Snapshot = {
capture: () => query,
restore: (value) => (query = value)
let imgResultPreview: ResultType | undefined;
export const snapshot: Snapshot<ResultType | undefined> = {
capture: () => imgResultPreview,
restore: (value) => (imgResultPreview = value)
};
</script>

Expand All @@ -33,7 +35,7 @@
{#await data.streamed.results}
<Load {query} />
{:then results}
<Display bind:query bind:currentPage bind:paramsString {results} />
<Display bind:query bind:currentPage bind:paramsString bind:imgResultPreview {results} />
{:catch err}
<Error statusCode={'500'} message={'Hearchco API failed.'} {err} />
{/await}

0 comments on commit 5a03e33

Please sign in to comment.