Skip to content

Commit

Permalink
Make query reactive
Browse files Browse the repository at this point in the history
  • Loading branch information
allanlasser committed Dec 2, 2024
1 parent d392984 commit d6e32ba
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/lib/components/viewer/Search.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Assumes it's a child of a ViewerContext
import Error from "../common/Error.svelte";
const document = getDocument();
let query = getQuery($page.url, "q");
let search: Promise<[number, string[]][]>;
// Format page numbers, highlight search results, and remove invalid pages
function formatResults(results: APIResponse<Highlights>) {
Expand All @@ -34,7 +34,7 @@ Assumes it's a child of a ViewerContext
.filter(([page]) => !isNaN(page));
}
let search: Promise<[number, string[]][]>;
$: query = getQuery($page.url, "q");
$: search = searchWithin($document.id, query).then(formatResults);
</script>

Expand All @@ -46,7 +46,12 @@ Assumes it's a child of a ViewerContext
{:then resultsPages}
{#each resultsPages as [pageNumber, resultsList]}
<a
href={getViewerHref({ page: pageNumber, mode: "document", query })}
href={getViewerHref({
document: $document,
page: pageNumber,
mode: "document",
query,
})}
class="card"
>
<Highlight
Expand Down

0 comments on commit d6e32ba

Please sign in to comment.