forked from CriticalMoments/CMSaasStarter
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
6 changed files
with
54 additions
and
40 deletions.
There are no files selected for viewing
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export const api = (customFetch = fetch) => ({ | ||
getAllAds: async () => { | ||
const response = await customFetch( | ||
'api', | ||
) | ||
const data = (await response.json()) | ||
return data | ||
}, | ||
getAdsByCategory: async (cat: string) => { | ||
const response = await customFetch( | ||
`api?category=${cat}`, | ||
) | ||
const data = (await response.json()) | ||
return data | ||
}, | ||
}) |
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,19 +1,11 @@ | ||
import { fetchAdsForCategories } from './api/helpers.js'; | ||
import { api } from "$lib/api"; | ||
|
||
export async function load({ fetch, parent }) { | ||
export async function load({ parent, fetch, params, route }) { | ||
const { queryClient } = await parent(); | ||
|
||
// Cachowanie danych dla 'sales' | ||
await queryClient.prefetchQuery({ | ||
queryKey: ['ads', 'sales'], | ||
queryFn: () => fetchAdsForCategories('sales', { fetch }), | ||
queryKey: ['ads', route.id], | ||
queryFn: () => api(fetch).getAdsByCategory('rental') | ||
}); | ||
|
||
// Cachowanie danych dla 'rental' | ||
await queryClient.prefetchQuery({ | ||
queryKey: ['ads', 'rental'], | ||
queryFn: () => fetchAdsForCategories('rental', { fetch }), | ||
}); | ||
} | ||
|
||
|
||
} |
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