Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: snapshot the preview, removed snapshoting query since it's in url #241

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}
Loading