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

Check that we're in the browser before calling searchWithin #986

Merged
merged 1 commit into from
Dec 18, 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
2 changes: 1 addition & 1 deletion src/lib/components/viewer/PaginationToolbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
} from "$lib/components/viewer/ViewerContext.svelte";

const documentStore = getDocument();
$: document = $documentStore;
const embed = isEmbedded();
const currentMode = getCurrentMode();
const currentPage = getCurrentPage();
Expand All @@ -43,6 +42,7 @@
TWO_ROWS: width <= remToPx(34),
};

$: document = $documentStore;
$: sections = document.sections ?? [];
$: totalPages = document.page_count;
$: showPDF = ["document", "annotating", "redacting"].includes($currentMode);
Expand Down
7 changes: 4 additions & 3 deletions src/lib/components/viewer/Search.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Assumes it's a child of a ViewerContext
<script lang="ts">
import type { APIResponse, Highlights } from "$lib/api/types";

import { browser } from "$app/environment";
import { page } from "$app/stores";

import { getContext } from "svelte";
import { _ } from "svelte-i18n";
import { Hourglass24, Search24 } from "svelte-octicons";

Expand All @@ -22,12 +22,13 @@ Assumes it's a child of a ViewerContext
import { searchWithin } from "$lib/api/documents";

const document = getDocument();
const embed: boolean = getContext("embed");

let search: Promise<[number, string[]][]>;

$: query = getQuery($page.url, "q");
$: search = searchWithin($document.id, query).then(formatResults);
$: search = browser
? searchWithin($document.id, query).then(formatResults)
: new Promise(() => {});

// Format page numbers, highlight search results, and remove invalid pages
function formatResults(results: APIResponse<Highlights>) {
Expand Down
Loading