Skip to content

Commit

Permalink
Merge pull request #935 from MuckRock/allanlasser/reading-toolbar-fix
Browse files Browse the repository at this point in the history
Fix search tab in reading toolbar
  • Loading branch information
allanlasser authored Dec 4, 2024
2 parents 2eb23b2 + 4ead0ce commit fbf37a5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/langs/json/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@
"notes": "Notes",
"annotating": "Annotate",
"redacting": "Redact",
"search": "Search"
"search": "Results"
},
"zoom": {
"zoom": "Zoom",
Expand Down
20 changes: 15 additions & 5 deletions src/lib/components/viewer/ReadingToolbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ Assumes it's a child of a ViewerContext
SEARCH_MENU: width < remToPx(24),
};
const readModes: Map<ReadMode, string> = new Map([
const readModeTabs: Map<ReadMode, string> = new Map([
["document", $_("mode.document")],
["text", $_("mode.text")],
["grid", $_("mode.grid")],
["notes", $_("mode.notes")],
]);
const readModeDropdownItems: Map<ReadMode, string> = new Map([
["document", $_("mode.document")],
["text", $_("mode.text")],
["grid", $_("mode.grid")],
Expand All @@ -74,14 +81,15 @@ Assumes it's a child of a ViewerContext
notes: Note16,
annotating: Comment16,
redacting: EyeClosed16,
search: Search16,
};
</script>

<PageToolbar bind:width>
<svelte:fragment slot="left">
{#if BREAKPOINTS.READ_MENU}
<div class="tabs" role="tablist">
{#each readModes.entries() as [value, name]}
{#each readModeTabs.entries() as [value, name]}
<Tab
active={$mode === value}
href={getViewerHref({ document, mode: value, embed, query })}
Expand All @@ -95,14 +103,16 @@ Assumes it's a child of a ViewerContext
<Dropdown position="bottom-start">
<SidebarItem slot="anchor">
<svelte:component this={icons[$mode]} slot="start" />
{Array.from(readModes ?? []).find(([value]) => value === $mode)?.[1]}
{Array.from(readModeDropdownItems ?? []).find(
([value]) => value === $mode,
)?.[1]}
<ChevronDown12 slot="end" />
</SidebarItem>
<Menu slot="default" let:close>
{#each readModes.entries() as [value, name]}
{#each readModeDropdownItems.entries() as [value, name]}
<MenuItem
selected={$mode === value}
href={getViewerHref({ document, mode: value, embed })}
href={getViewerHref({ document, mode: value, embed, query })}
on:click={close}
>
<svelte:component this={icons[value]} slot="icon" />
Expand Down
5 changes: 3 additions & 2 deletions src/lib/components/viewer/Search.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ Assumes it's a child of a ViewerContext
display: flex;
flex-flow: column;
align-items: center;
gap: 2rem;
gap: 1rem;
margin: 0 auto;
width: 100%;
max-width: 38.0625rem;
padding: 2rem 0;
padding: 1rem 1rem;
min-height: 100%;
}
.card {
Expand Down
2 changes: 0 additions & 2 deletions src/lib/components/viewer/stories/Search.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
import text from "@/test/fixtures/documents/document.txt.json";
import ViewerContext from "../ViewerContext.svelte";
import type { APIResponse, Highlights } from "@/lib/api/types";
const query = "Trump";
const empty: APIResponse<Highlights, null> = { data: {} };
</script>

<Story
Expand Down
26 changes: 25 additions & 1 deletion src/lib/components/viewer/stories/Viewer.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import doc from "@/test/fixtures/documents/document-expanded.json";
import txt from "@/test/fixtures/documents/document.txt.json";
import Note from "../Note.svelte";
import { searchWithin } from "@/test/handlers/documents";
const document = doc as Document;
Expand Down Expand Up @@ -77,6 +77,30 @@
},
}}
/>
<Story
name="Search"
parameters={{
msw: { handlers: [searchWithin.data] },
sveltekit_experimental: {
stores: {
page: {
url: new URL(
`https://www.dev.documentcloud.org/documents/20000040-the-santa-anas/?q=Trump`,
),
},
},
},
}}
args={{
...args,
mode: "search",
document: {
...document,
edit_access: true,
notes: document.notes?.map((note) => ({ ...note, edit_access: true })),
},
}}
/>

<style>
.vh {
Expand Down

0 comments on commit fbf37a5

Please sign in to comment.