This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate fetching to Svelte-Query (#291)
- Loading branch information
1 parent
62ce625
commit 9f6dc4d
Showing
10 changed files
with
171 additions
and
101 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { SearchResponse } from '../global'; | ||
|
||
const url = '/api/get-issues'; | ||
|
||
export async function fetchIssuesLoad(query: { query: string }, loadFetch: typeof window.fetch) { | ||
const response = await loadFetch(url, { | ||
method: 'POST', | ||
body: JSON.stringify(query), | ||
}); | ||
const data = await response.json(); | ||
return data as SearchResponse; | ||
} | ||
|
||
export async function fetchIssues(query: string, endCursor: string) { | ||
const response = await fetch(url, { | ||
method: 'POST', | ||
body: JSON.stringify({ query, after: endCursor }), | ||
}); | ||
const data = await response.json(); | ||
return data as SearchResponse; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
import type { Load } from '@sveltejs/kit'; | ||
import { browser } from '$app/environment'; | ||
import { QueryClient } from '@tanstack/svelte-query'; | ||
import type { LayoutLoad } from './$types'; | ||
|
||
export const load: LayoutLoad = async ({ fetch, data }) => { | ||
const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
enabled: browser, | ||
}, | ||
}, | ||
}); | ||
|
||
export const load: Load = async ({ fetch, data }) => { | ||
const res = await fetch('/api/version'); | ||
if (res.ok) { | ||
const resData = (await res.json()) as { version: string }; | ||
return { | ||
...data, | ||
version: resData.version, | ||
queryClient, | ||
}; | ||
} | ||
}; |
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
Oops, something went wrong.