Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
},
"type": "module",
"dependencies": {
"@sveltejs/svelte-virtual-list": "^3.0.1",
"@tailwindcss/vite": "4.0.0-alpha.30",
"tailwindcss": "4.0.0-alpha.30"
},
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions src/lib/pizza.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
export const calculatePizzas = (people: number): number => {
return Math.ceil((3 * people) / 8);
};
export const PIZZA = '🍕';

export const pizza = `
export const PIZZA_ART = `
88
""

Expand Down
46 changes: 35 additions & 11 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import PizzaFall from '$lib/PizzaFall.svelte';
import { calculatePizzas, pizza } from '$lib/pizza';
import { PIZZA, PIZZA_ART } from '$lib/pizza';
import VirtualList from '@sveltejs/svelte-virtual-list/VirtualList.svelte';

const COUNT_PARAM = 'count';

Expand All @@ -27,7 +28,28 @@
/**
* Console log the pizza ascii art
*/
console.log(pizza);
console.log(PIZZA_ART);
});

let pizzaWidth = 24;
let start = $state();
let end = $state();
let containerWidth = $state<number>(0);

const partition = (items: Array<string>, size: number) => {
const result = [];
for (let i = 0; i < items.length; i += size) {
result.push(items.slice(i, i + size));
}
return result;
};

let items = $derived.by(() => {
const emojis = Array.from({ length: count })
.fill(null)
.map(() => PIZZA);
const pizzasPerRow = Math.floor(containerWidth / pizzaWidth);
return partition(emojis, pizzasPerRow);
});
</script>

Expand Down Expand Up @@ -57,15 +79,17 @@
placeholder="Antall personer"
/>

<div class="text-2xl">
{#if count && count > 0}
{@const pizzas = calculatePizzas(count)}
<p>
{#each Array.from({ length: pizzas }) as _, i}
<span>🍕</span>
{/each}
<span>=</span> <span>{pizzas}</span>
</p>
<div bind:clientWidth={containerWidth} class="h-[400px]">
{#if count > 0}
<VirtualList {items} bind:start bind:end>
{#snippet children({ item }: { item: Array<string> })}
<div class="w-ful h-fit gap-2 flex">
{#each item as emoji}
<span style="width: {pizzaWidth}px;">{emoji}</span>
{/each}
</div>
{/snippet}
</VirtualList>
{:else}
<p class="text-muted text-xl">Fyll inn antall personer</p>
{/if}
Expand Down