-
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.
- Loading branch information
1 parent
a9e4f06
commit 7b4810a
Showing
7 changed files
with
95 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { error } from "@sveltejs/kit"; | ||
import { BASE_API_URL } from "@/config/config.js"; | ||
import { type AddOnListItem } from "@/addons/types"; | ||
import { isErrorCode } from "../utils"; | ||
|
||
export async function getPinnedAddons(): Promise<AddOnListItem[]> { | ||
const endpoint = new URL( | ||
"/api/addons/?active=true&per_page=100", | ||
BASE_API_URL, | ||
); | ||
const resp = await fetch(endpoint, { credentials: "include" }); | ||
if (isErrorCode(resp.status)) { | ||
error(resp.status, resp.statusText); | ||
} | ||
return resp.json(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { isErrorCode } from "./isErrorCode"; |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { NumericRange } from "@sveltejs/kit"; | ||
|
||
export function isErrorCode(status: number): status is NumericRange<400, 599> { | ||
return status >= 400 && status <= 599; | ||
} |
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,12 +1,15 @@ | ||
import { search } from "$lib/api/documents.js"; | ||
import { getPinnedAddons } from "@/lib/api/addons.js"; | ||
|
||
export async function load({ url, fetch }) { | ||
const query = url.searchParams.get("q") || ""; | ||
|
||
const searchResults = search(query, true, fetch); | ||
const pinnedAddons = getPinnedAddons(); | ||
|
||
return { | ||
searchResults, | ||
query, | ||
pinnedAddons, | ||
}; | ||
} |
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