Skip to content

Commit

Permalink
Merge pull request #952 from MuckRock/allanlasser/issue934
Browse files Browse the repository at this point in the history
Add results count to search mode
  • Loading branch information
allanlasser authored Dec 5, 2024
2 parents 977b8bb + 02ba438 commit fc687b6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/langs/json/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"search": {
"loading": "Searching…",
"matchingResults": "{n, plural, one {# matching result} other {# matching results}}",
"viewerResults": "{results, plural, one {# matching result} other {# matching results}} found across {pages, plural, one {# page} other {# pages}}",
"reset": "Clear Search",
"help": "Use filters like <code>user:</code>, <code>project:</code> or <code>organization:</code> to refine searches. Use <code>sort:</code> to order results.",
"more": "Learn more",
Expand Down
24 changes: 24 additions & 0 deletions src/lib/components/viewer/Search.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ Assumes it's a child of a ViewerContext
$: query = getQuery($page.url, "q");
$: search = searchWithin($document.id, query).then(formatResults);
function countResults(results: [number, string[]][]) {
return results.reduce((acc, [, segments]) => acc + segments.length, 0);
}
</script>

<div class="pages">
Expand All @@ -45,6 +49,18 @@ Assumes it's a child of a ViewerContext
{$_("search.loading")}
</Empty>
{:then resultsPages}
{#if resultsPages.length > 0}
<header>
<h2>
{$_("search.viewerResults", {
values: {
results: countResults(resultsPages),
pages: resultsPages.length,
},
})}
</h2>
</header>
{/if}
{#each resultsPages as [pageNumber, resultsList]}
{@const href = getViewerHref({
document: $document,
Expand Down Expand Up @@ -93,4 +109,12 @@ Assumes it's a child of a ViewerContext
border-color: var(--blue-2);
background-color: var(--blue-1);
}
header {
margin-bottom: 1rem;
}
h2 {
font-size: var(--font-lg);
font-weight: var(--font-semibold);
color: var(--gray-5);
}
</style>

0 comments on commit fc687b6

Please sign in to comment.