Skip to content

Commit

Permalink
Search improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
myieye committed Jun 18, 2024
1 parent 8ebf4f9 commit 2a7692b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion frontend/viewer/src/ProjectView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
const connected = writable(false);
const search = writable<string>('');
setContext('listSearch', search);
const selectedIndexExemplar = writable<string | undefined>(undefined);
setContext('selectedIndexExamplar', selectedIndexExemplar);
Expand Down
15 changes: 12 additions & 3 deletions frontend/viewer/src/lib/layout/EntryList.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script lang="ts">
import { Button, InfiniteScroll, ListItem, TextField } from "svelte-ux";
import { Button, Icon, InfiniteScroll, ListItem, TextField } from "svelte-ux";
import type { IEntry } from "../mini-lcm";
import { firstDefOrGlossVal, headword } from "../utils";
import { mdiArrowExpandLeft, mdiArrowExpandRight, mdiBookOpenVariantOutline, mdiBookSearchOutline, mdiFormatListText } from "@mdi/js";
import { mdiArrowExpandLeft, mdiArrowExpandRight, mdiBookOpenVariantOutline, mdiBookSearchOutline, mdiClose, mdiFormatListText } from "@mdi/js";
import IndexCharacters from "./IndexCharacters.svelte";
import type { Writable } from "svelte/store";
import { createEventDispatcher, getContext } from "svelte";
Expand Down Expand Up @@ -56,6 +56,7 @@
<TextField
bind:value={search}
placeholder="Filter entries..."
clearable
icon={mdiBookSearchOutline} />
</div>
<Button icon={dictionaryMode ? mdiFormatListText : mdiBookOpenVariantOutline} variant="outline"
Expand All @@ -77,7 +78,15 @@
<div class="p-4 text-center opacity-75">
No entries found
{#if $selectedCharacter}
in '{$selectedCharacter}'
in
<Button
fullWidth
class="border mb-2 w-auto inline ml-0.5"
on:click={() => $selectedCharacter = undefined}
size="sm">
{$selectedCharacter}
<Icon data={mdiClose} />
</Button>
{/if}
</div>
{:else}
Expand Down
29 changes: 22 additions & 7 deletions frontend/viewer/src/lib/search-bar/SearchBar.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script lang="ts">
import { mdiBookSearchOutline, mdiMagnifyRemoveOutline } from '@mdi/js';
import { Dialog, Field, Icon, ListItem, TextField, cls } from 'svelte-ux';
import { Button, Dialog, Field, Icon, ListItem, TextField, cls } from 'svelte-ux';
import { firstDefOrGlossVal, headword } from '../utils';
import { useLexboxApi } from '../services/service-provider';
import { derived, writable } from 'svelte/store';
import { derived, writable, type Writable } from 'svelte/store';
import { deriveAsync } from '../utils/time';
import { createEventDispatcher, onDestroy } from 'svelte';
import { createEventDispatcher, getContext, onDestroy } from 'svelte';
import type { IEntry } from '../mini-lcm';
const dispatch = createEventDispatcher<{
Expand Down Expand Up @@ -50,6 +50,9 @@
const displayedEntries = derived(result, (result) => {
return result?.entries.slice(0, 5) ?? [];
});
const listSearch = getContext<Writable<string | undefined>>('listSearch');
const selectedIndexExamplar = getContext<Writable<string | undefined>>('selectedIndexExamplar');
</script>

<Field
Expand All @@ -64,7 +67,7 @@
</div>
</Field>

<Dialog bind:open={showSearchDialog} class="w-[700px]" classes={{root: 'items-start', title: 'p-2'}}>
<Dialog bind:open={showSearchDialog} on:close={() => $search = undefined} class="w-[700px]" classes={{root: 'items-start', title: 'p-2'}}>
<div slot="title">
<TextField
autofocus
Expand All @@ -86,7 +89,6 @@
on:click={() => {
dispatch('entrySelected', entry);
showSearchDialog = false;
$search = undefined;
}}
/>
{/each}
Expand All @@ -100,10 +102,23 @@
</div>
{/if}
{#if $result.entries.length > $displayedEntries.length}
<div class="p-4 text-center opacity-75 flex">
<div class="p-4 text-center opacity-75 flex items-center">
<span>{$result.entries.length - $displayedEntries.length}</span>
{#if $result.entries.length === fetchCount}<span>+</span>{/if}
<span class="ml-1">more matching entries...</span>
<div class="ml-1 flex justify-between items-center gap-2">
<span>more matching entries...</span>
<Button
fullWidth
icon={mdiBookSearchOutline}
on:click={() => {
$listSearch = $search;
$selectedIndexExamplar = undefined;
showSearchDialog = false;
}}
class="border w-auto inline ml-0.5">
Filter list
</Button>
</div>
</div>
{/if}
</div>
Expand Down

0 comments on commit 2a7692b

Please sign in to comment.