Skip to content

Commit

Permalink
feat: la pagination fonctionne
Browse files Browse the repository at this point in the history
il ne reste plus qu'à styliser un peu tout
  • Loading branch information
bachrc committed Nov 14, 2024
1 parent 77920ac commit 41a6782
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RUN unzip /tmp/pb.zip -d /pb/
# download deno
RUN mkdir -p /home/wizou/.local/bin
ENV PATH=$PATH:/home/wizou/.local/bin
COPY --from=denoland/deno:bin-2.0.2 --chown=wizou:wizou /deno /home/wizou/.local/bin
COPY --from=denoland/deno:bin-2.0.6 --chown=wizou:wizou /deno /home/wizou/.local/bin


FROM base AS build
Expand Down
35 changes: 25 additions & 10 deletions src/components/ListeExtractions.svelte
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
<script lang="ts">
import { pb } from '$lib/database';
import { getExtractions, type Extraction } from '$lib/extractions';
import Loader from './Loader.svelte';
import { onMount } from 'svelte';
import { page } from '$app/stores';
import Pagination from './Pagination.svelte';
import ResumeExtraction from './ResumeExtraction.svelte';
let data = getExtractions(1, 20);
let extractions: Extraction[] = $state([]);
let pageEnCours = $derived(parseInt($page.url.searchParams.get('page') ?? '1'));
let elementsParPage = $derived(parseInt($page.url.searchParams.get('elementsParPage') ?? '3'));
let totalPages = $state(0);
$effect(() => {
getExtractions(pageEnCours, elementsParPage).then((data) => {
extractions = data.items as Extraction[];
totalPages = data.totalPages;
});
});
</script>

<div class="w-full flex flex-col">
{#await data}
<Loader />
{:then extractions}
{#each extractions.items as extraction}
<ResumeExtraction extraction={extraction as Extraction} />
{/each}
{/await}
<div class="flex flex-row items-center h-12 rounded-3xl bg-white border">
<input type="text" class="grow h-full rounded-l-3xl px-4 border-r" />
<span class="px-2">🔍</span>
</div>
{#each extractions as extraction}
<ResumeExtraction extraction={extraction as Extraction} />
{/each}

<div>
<Pagination page={pageEnCours} {totalPages} />
</div>
</div>
28 changes: 28 additions & 0 deletions src/components/Pagination.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script lang="ts">
import { page } from '$app/stores';
let props: {
page: number;
totalPages: number;
} = $props();
function currentUrlWithPage(pageNumber: number): string {
let params = new URLSearchParams($page.url.searchParams.toString());
params.set('page', pageNumber.toString());
return `?${params.toString()}`;
}
let pagePrecedente = $derived(props.page - 1);
let pageSuivante = $derived(props.page + 1);
</script>

<div class="flex flex-row">
{#if props.page > 1}
<a href={currentUrlWithPage(pagePrecedente)}><span>⬅️ Page précédente</span></a>
{/if}

{#if props.page < props.totalPages}
<a href={currentUrlWithPage(pageSuivante)}><span>Page suivante ➡️</span></a>
{/if}
</div>
Empty file added src/components/Recherche.svelte
Empty file.
2 changes: 1 addition & 1 deletion src/lib/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const loginSchema = z.object({
});

export const creationExtractionSchema = z.object({
nom: z.string().min(5).max(50),
nom: z.string().min(5).max(100),
poids_cafe: z.number().positive(),
poids_boisson: z.number().positive(),
utilisateur: z.string(),
Expand Down
5 changes: 3 additions & 2 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import { currentUser } from '$lib/login.svelte';
import GrosBouton from '../components/GrosBouton.svelte';
import ListeExtractions from '../components/ListeExtractions.svelte';
import Recherche from '../components/Recherche.svelte';
</script>

<div class="p-2 flex flex-col">
<div class="p-2 flex flex-col gap-2">
{#if currentUser.value != null}
<GrosBouton customClass="bg-green-300 disabled:bg-green-100" onclick={() => goto('/new')}>
➕ Nouvelle extraction
</GrosBouton>

<Recherche />
<ListeExtractions />
{:else}
<span>Salut ! Ici on fait du café !</span>
Expand Down

0 comments on commit 41a6782

Please sign in to comment.