-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic infinite scroll for search results
- Loading branch information
Showing
8 changed files
with
130 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 6 additions & 12 deletions
18
src/lib/components/documents/stories/ResultsList.stories.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,26 @@ | ||
<script context="module" lang="ts"> | ||
import type { DocumentResults } from "@/lib/api/types"; | ||
import type { Document, DocumentResults } from "@/lib/api/types"; | ||
import { Story } from "@storybook/addon-svelte-csf"; | ||
import ResultsList from "../ResultsList.svelte"; | ||
// typescript complains without the type assertion | ||
import searchResults from "../../../api/fixtures/documents/search-highlight.json"; | ||
const results = searchResults as DocumentResults; | ||
const results = searchResults.results as Document[]; | ||
const count = searchResults.count; | ||
const next = searchResults.next; | ||
export const meta = { | ||
title: "Components / Documents / Results list", | ||
component: ResultsList, | ||
tags: ["autodocs"], | ||
parameters: { layout: "centered" }, | ||
}; | ||
const empty = { | ||
results: [], | ||
count: 0, | ||
next: null, | ||
previous: null, | ||
escaped: false, | ||
}; | ||
</script> | ||
|
||
<Story name="With Results"> | ||
<div style="width: 36rem"><ResultsList {results} /></div> | ||
<div style="width: 36rem"><ResultsList {results} {count} {next} /></div> | ||
</Story> | ||
|
||
<Story name="Empty"> | ||
<div style="width: 36rem"><ResultsList results={empty} /></div> | ||
<div style="width: 36rem"><ResultsList /></div> | ||
</Story> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,30 @@ | ||
import { search } from "$lib/api/documents.js"; | ||
import type { SearchOptions } from "$lib/api/types"; | ||
import { search } from "$lib/api/documents"; | ||
|
||
export async function load({ url, fetch }) { | ||
const query = url.searchParams.get("q") || ""; | ||
const searchResults = search(query, true, fetch); | ||
const per_page = +url.searchParams.get("per_page") || 25; | ||
const cursor = url.searchParams.get("cursor") || ""; | ||
|
||
const options: SearchOptions = { | ||
hl: Boolean(query), | ||
version: "2.0", | ||
}; | ||
|
||
if (per_page) { | ||
options.per_page = per_page; | ||
} | ||
|
||
if (cursor) { | ||
options.cursor = cursor; | ||
} | ||
|
||
const searchResults = search(query, options, fetch); | ||
|
||
return { | ||
searchResults, | ||
query, | ||
per_page, | ||
cursor, | ||
searchResults, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters