Skip to content

Commit

Permalink
Only one way to get a search query
Browse files Browse the repository at this point in the history
  • Loading branch information
eyeseast committed Nov 21, 2024
1 parent ecef11d commit 014fa79
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
7 changes: 5 additions & 2 deletions src/lib/components/viewer/ReadingToolbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Assumes it's a child of a ViewerContext
<script lang="ts">
import type { ReadMode, WriteMode } from "$lib/api/types";
import { page } from "$app/stores";
import { _ } from "svelte-i18n";
import {
Comment16,
Expand All @@ -29,17 +31,18 @@ Assumes it's a child of a ViewerContext
import { remToPx } from "$lib/utils/layout";
import { getViewerHref } from "$lib/utils/viewer";
import { getQuery } from "$lib/utils/search";
import {
getCurrentMode,
getDocument,
getQuery,
isEmbedded,
} from "$lib/components/viewer/ViewerContext.svelte";
export let query = getQuery($page.url, "q");
let width: number;
const documentStore = getDocument();
const query = getQuery();
const mode = getCurrentMode();
const embed = isEmbedded();
Expand Down
14 changes: 6 additions & 8 deletions src/lib/components/viewer/Text.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@
Assumes it's a child of a ViewerContext
-->
<script lang="ts">
import { page } from "$app/stores";
import { onMount } from "svelte";
import Page from "./Page.svelte";
import {
getText,
getCurrentPage,
getQuery,
getZoom,
} from "./ViewerContext.svelte";
import { getText, getCurrentPage, getZoom } from "./ViewerContext.svelte";
import { scrollToPage } from "$lib/utils/scroll";
import { highlight } from "$lib/utils/search";
import { getQuery } from "$lib/utils/search";
export let query = getQuery($page.url, "q");
const text = getText();
const query = getQuery();
const currentPage = getCurrentPage();
const text = getText();
const zoom = getZoom();
onMount(async () => {
Expand Down
6 changes: 0 additions & 6 deletions src/lib/components/viewer/ViewerContext.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ layouts, stories, and tests.
return getContext("asset_url");
}
export function getQuery(): string {
return getContext("query") ?? "";
}
export function isEmbedded(): boolean {
// are we embedded?
return getContext("embed") ?? false;
Expand Down Expand Up @@ -99,7 +95,6 @@ layouts, stories, and tests.
export let embed: boolean = false;
export let page: number = 1;
export let mode: ViewerMode = "document";
export let query: string = "";
export let zoom: Zoom = 1;
export let errors: Error[] = [];
Expand All @@ -123,7 +118,6 @@ layouts, stories, and tests.
setContext("text", text);
setContext("asset_url", asset_url);
setContext("embed", embed);
setContext("query", query);
setContext("newNote", writable(null));
setContext("currentNote", writable(note));
setContext("currentPage", writable(page));
Expand Down
2 changes: 1 addition & 1 deletion src/routes/(app)/documents/[id]-[slug]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
/>
</svelte:head>

<ViewerContext {document} {mode} {text} {asset_url} {query}>
<ViewerContext {document} {mode} {text} {asset_url}>
<DocumentLayout {action} {addons} />
</ViewerContext>
<GuidedTour />
2 changes: 1 addition & 1 deletion src/routes/embed/documents/[id]-[slug]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function load({ fetch, url, params, depends }) {

let settings: Partial<EmbedSettings> = getEmbedSettings(url.searchParams);

const query = getQuery(url);
const query = getQuery(url, "q");

return {
document,
Expand Down

0 comments on commit 014fa79

Please sign in to comment.