Skip to content

Commit

Permalink
Fix storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
eyeseast committed Nov 20, 2024
1 parent 39ae6c2 commit 98d11a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
23 changes: 20 additions & 3 deletions src/lib/components/viewer/stories/PDFPage.stories.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<script context="module" lang="ts">
import type { Document, Section } from "$lib/api/types";
import type { Document } from "$lib/api/types";
import { page } from "$app/stores";
import { writable } from "svelte/store";
import { Story } from "@storybook/addon-svelte-csf";
import PdfPage from "../PDFPage.svelte";
Expand Down Expand Up @@ -58,9 +61,23 @@
</ViewerContext>
</Story>

<Story name="search results">
<ViewerContext {document} pdf={writable(load(url))} {query}>
<Story
name="search results"
parameters={{
sveltekit_experimental: {
stores: {
page: {
url: new URL(
`https://www.dev.documentcloud.org/documents/20000040-the-santa-anas/?q=${query}`,
),
},
},
},
}}
>
<ViewerContext {document} pdf={writable(load(url))}>
<p>Query: {query}</p>
<p>URL: {$page.url}</p>
<PdfPage page_number={1} scale={1.5} {width} {height} />
</ViewerContext>
</Story>
Expand Down
5 changes: 4 additions & 1 deletion src/lib/utils/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,8 @@ export function pageNumber(page: string): number {
}

export function getQuery(url: URL, param: string = "q"): string {
return url.searchParams.get(param) ?? "";
if (!url) {
console.error("Missing URL");
}
return url?.searchParams?.get(param) ?? "";
}

0 comments on commit 98d11a5

Please sign in to comment.