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
202 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,93 @@ | ||
<script lang="ts"> | ||
import { WebsiteName } from "../../../config" | ||
import { useQueryClient } from "@tanstack/svelte-query" | ||
const client = useQueryClient() | ||
const cachedData = client.getQueryData(["ads"]) | ||
console.log(cachedData) | ||
import { createQuery } from "@tanstack/svelte-query" | ||
const rentQuery = createQuery({ | ||
queryKey: ["ads_combined"], | ||
queryFn: async () => (await fetch("api")).json(), | ||
select: (data) => data.rent, | ||
}) | ||
</script> | ||
|
||
<svelte:head> | ||
<title>Rental</title> | ||
<meta name="description" content="Rental ads for {WebsiteName}" /> | ||
</svelte:head> | ||
{#if cachedData} | ||
{#each cachedData as ad} | ||
<p>{ad.title}</p> | ||
{/each} | ||
{:else} | ||
<p>Dane nie są dostępne w cache.</p> | ||
{/if} | ||
|
||
<div class="min-h-[70vh] pb-8 overflow-x-auto"> | ||
<table class="table"> | ||
<!-- head --> | ||
<thead> | ||
<tr> | ||
<th> | ||
<label> | ||
<input type="checkbox" class="checkbox" /> | ||
</label> | ||
</th> | ||
<th>Tytuł</th> | ||
<th>Dzielnica</th> | ||
<th>Data</th> | ||
<th>Cena</th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{#if $rentQuery.data && Array.isArray($rentQuery.data)} | ||
{#each $rentQuery.data as ad} | ||
<tr> | ||
<th> | ||
<label> | ||
<input type="checkbox" class="checkbox" /> | ||
</label> | ||
</th> | ||
<td> | ||
<div class="flex items-center gap-3"> | ||
<div class="avatar"> | ||
<div class="mask mask-squircle w-12 h-12"> | ||
<img | ||
src={ad.image_url} | ||
alt="Avatar Tailwind CSS Component" | ||
/> | ||
</div> | ||
</div> | ||
<div> | ||
<div class="font-bold">{ad.title}</div> | ||
<div class="text-sm opacity-50">{ad.city}</div> | ||
</div> | ||
</div> | ||
</td> | ||
<td> | ||
<div class="flex items-center gap-3"> | ||
<div> | ||
<div class="font-bold">{ad.district}</div> | ||
<div class="text-sm opacity-50">{ad.region_name}</div> | ||
</div> | ||
</div> | ||
</td> | ||
<td> | ||
{ad.date} | ||
<br /> | ||
<span class="badge badge-ghost badge-sm">{ad.created_at}</span> | ||
</td> | ||
<td>{ad.price}</td> | ||
<th> | ||
<button class="btn btn-ghost btn-xs">details</button> | ||
</th> | ||
</tr> | ||
{/each} | ||
{:else} | ||
<p>Dane nie są dostępne w cache.</p> | ||
{/if} | ||
</tbody> | ||
<!-- foot --> | ||
<tfoot> | ||
<tr> | ||
<th></th> | ||
<th>Name</th> | ||
<th>Job</th> | ||
<th>Favorite Color</th> | ||
<th></th> | ||
</tr> | ||
</tfoot> | ||
</table> | ||
</div> |
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,84 @@ | ||
<script lang="ts"> | ||
import { WebsiteName } from "../../../config" | ||
import { useQueryClient } from "@tanstack/svelte-query" | ||
const client = useQueryClient() | ||
const cachedData = client.getQueryData(["ads"]) | ||
console.log(cachedData) | ||
import { createQuery } from "@tanstack/svelte-query" | ||
const sellQuery = createQuery({ | ||
queryKey: ["ads_combined"], | ||
queryFn: async () => (await fetch("api")).json(), | ||
select: (data) => data.sell, | ||
}) | ||
</script> | ||
|
||
<svelte:head> | ||
<title>Sales</title> | ||
<title>Salling</title> | ||
<meta name="description" content="Rental ads for {WebsiteName}" /> | ||
</svelte:head> | ||
{#if cachedData} | ||
{#each cachedData as ad} | ||
<p>{ad.region_name}</p> | ||
{/each} | ||
{:else} | ||
<p>Dane nie są dostępne w cache.</p> | ||
{/if} | ||
|
||
<div class="min-h-[70vh] pb-8 overflow-x-auto"> | ||
<table class="table"> | ||
<!-- head --> | ||
<thead> | ||
<tr> | ||
<th> | ||
<label> | ||
<input type="checkbox" class="checkbox" /> | ||
</label> | ||
</th> | ||
<th>Name</th> | ||
<th>Job</th> | ||
<th>Favorite Color</th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{#if $sellQuery.data && Array.isArray($sellQuery.data)} | ||
{#each $sellQuery.data as ad} | ||
<tr> | ||
<th> | ||
<label> | ||
<input type="checkbox" class="checkbox" /> | ||
</label> | ||
</th> | ||
<td> | ||
<div class="flex items-center gap-3"> | ||
<div class="avatar"> | ||
<div class="mask mask-squircle w-12 h-12"> | ||
<img | ||
src={ad.image_url} | ||
alt="Avatar Tailwind CSS Component" | ||
/> | ||
</div> | ||
</div> | ||
<div> | ||
<div class="font-bold">{ad.title}</div> | ||
<div class="text-sm opacity-50">{ad.city}</div> | ||
</div> | ||
</div> | ||
</td> | ||
<td> | ||
{ad.city} | ||
<br /> | ||
<span class="badge badge-ghost badge-sm">{ad.date}</span> | ||
</td> | ||
<td>{ad.price}</td> | ||
<th> | ||
<button class="btn btn-ghost btn-xs">details</button> | ||
</th> | ||
</tr> | ||
{/each} | ||
{:else} | ||
<p>Dane nie są dostępne w cache.</p> | ||
{/if} | ||
</tbody> | ||
<!-- foot --> | ||
<tfoot> | ||
<tr> | ||
<th></th> | ||
<th>Name</th> | ||
<th>Job</th> | ||
<th>Favorite Color</th> | ||
<th></th> | ||
</tr> | ||
</tfoot> | ||
</table> | ||
</div> |
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,17 +1,15 @@ | ||
export const prerender = false | ||
export async function load({ parent, fetch }) { | ||
const { queryClient } = await parent(); | ||
|
||
await queryClient.prefetchQuery({ | ||
queryKey: ['ads'], | ||
queryFn: async () => { | ||
const response = await fetch('api'); | ||
const ads = await response.json(); | ||
return ads; | ||
}, | ||
}); | ||
// W pliku +page.ts lub __layout.ts na stronie głównej | ||
export async function load({ fetch, parent }) { | ||
const { queryClient } = await parent(); | ||
|
||
const cachedData = queryClient.getQueryData(["ads"]) | ||
console.log(cachedData) | ||
return {}; | ||
} | ||
await queryClient.prefetchQuery({ | ||
queryKey: ['ads_combined'], | ||
queryFn: async () => { | ||
const response = await fetch('api'); | ||
if (!response.ok) throw new Error('Network response was not ok'); | ||
return response.json(); | ||
}, | ||
}); | ||
return {}; | ||
} |
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