Skip to content

Commit

Permalink
generalize GalleryDisplay
Browse files Browse the repository at this point in the history
  • Loading branch information
MaHaWo committed Aug 23, 2024
1 parent c4195ca commit 2f0ad91
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
33 changes: 6 additions & 27 deletions src/lib/components/DataDisplay/GalleryDisplay.svelte
Original file line number Diff line number Diff line change
@@ -1,36 +1,15 @@
<script context="module">
// this will go into the backend at the end?
export function splitDataIntoPages(datasize, pagesize) {
let start = 0;
let stop = pagesize;
let indices = [];
while (stop < datasize - pagesize) {
stop = start + pagesize;
indices.push([start, stop]);
start = stop;
}
// add last element
indices.push([start, datasize]);
return indices;
}
</script>

<script>
import CardDisplay from '$lib/components/DataDisplay/CardDisplay.svelte';
import { Gallery } from 'flowbite-svelte';
export let data;
export let n = 3;
export let m = 2;
export let header = 'Currently monitored children';
let pageindices = splitDataIntoPages(Object.keys(data).length, n * m);
export let itemComponent;
export let componentProps;
</script>

<h1 class="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white">{header}</h1>
<Gallery class="grid-cols-2 gap-4 md:grid-cols-2">
{#each data.slice(pageindices[0][0], pageindices[0][1]) as item}
<CardDisplay header={item.name} link={item.link} image={item.image} summary={item.summary} />

<Gallery class="grid-cols-3 gap-4 md:grid-cols-2">
{#each data as item}
<svelte:component this={itemComponent} {data} {...componentProps} />
{/each}
</Gallery>
24 changes: 24 additions & 0 deletions src/lib/components/DataDisplay/PaginatedDisplay.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script context="module">
// this will go into the backend at the end?
export function splitDataIntoPages(datasize, pagesize) {
let start = 0;
let stop = pagesize;
let indices = [];
while (stop < datasize - pagesize) {
stop = start + pagesize;
indices.push([start, stop]);
start = stop;
}
// add last element
indices.push([start, datasize]);
return indices;
}
</script>

<script>
import GalleryDisplay from "./GalleryDisplay.svelte";
import {Pagination, PaginationItem} from "flowbite-svelte";
</script>

0 comments on commit 2f0ad91

Please sign in to comment.