Skip to content
Closed
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
152 changes: 75 additions & 77 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,79 +1,77 @@
{
"name": "km-challenge",
"private": true,
"version": "0.0.1",
"type": "module",
"scripts": {
"dev": "bunx --bun vite dev",
"build": "bunx --bun vite build",
"preview": "bunx --bun vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"format": "prettier --write .",
"lint": "prettier --check . && eslint .",
"test:e2e": "playwright test",
"test": "npm run test:e2e",
"push": "drizzle-kit push",
"generate": "drizzle-kit generate",
"studio": "drizzle-kit studio",
"start": "PORT=8080 bun /build"
},
"devDependencies": {
"@eslint/compat": "^1.2.3",
"@eslint/js": "^9.17.0",
"@internationalized/date": "^3.6.0",
"@playwright/test": "^1.45.3",
"@sveltejs/adapter-vercel": "^5.5.0",
"@sveltejs/kit": "^2.52.0",
"@sveltejs/vite-plugin-svelte": "^6.2.4",
"@tailwindcss/vite": "^4.1.7",
"@types/pg": "^8.15.6",
"bits-ui": "1.5.2",
"clsx": "^2.1.1",
"daisyui": "^4.12.23",
"drizzle-kit": "^1.0.0-beta.6-4414a19",
"eslint": "^9.7.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.36.0",
"formsnap": "^2.0.1",
"globals": "^15.0.0",
"layerchart": "2.0.0-next.43",
"mode-watcher": "^0.5.0",
"prettier": "^3.3.2",
"prettier-plugin-svelte": "^3.2.6",
"prettier-plugin-tailwindcss": "^0.6.11",
"svelte": "^5.51.2",
"svelte-adapter-bun": "^1.0.1",
"svelte-check": "^4.4.0",
"svelte-sonner": "^1.0.1",
"sveltekit-superforms": "^2.29.1",
"tailwind-merge": "^3.3.0",
"tailwind-variants": "^1.0.0",
"tailwindcss": "^4.1.7",
"tw-animate-css": "^1.3.0",
"typescript": "^5.0.0",
"typescript-eslint": "^8.0.0",
"vite": "^7.3.1",
"vite-plugin-devtools-json": "^1.0.0"
},
"dependencies": {
"@better-fetch/fetch": "^1.1.12",
"@lucide/svelte": "^0.564.0",
"@nevthereal/random-utils": "^1.0.11",
"@oslojs/crypto": "^1.0.1",
"@oslojs/encoding": "^1.1.0",
"@sveltejs/adapter-node": "^5.4.0",
"@tailwindcss/typography": "^0.5.16",
"@tanstack/table-core": "^8.20.5",
"@upstash/redis": "^1.34.8",
"arctic": "^3.1.2",
"better-auth": "^1.4.9",
"dayjs": "^1.11.19",
"dotenv": "^16.4.7",
"drizzle-orm": "^1.0.0-beta.6-4414a19",
"drizzle-zod": "^0.6.1",
"pg": "^8.16.3",
"zod": "^4.2.1"
},
"packageManager": "bun@1.3.5"
"name": "km-challenge",
"private": true,
"version": "0.0.1",
"type": "module",
"scripts": {
"dev": "bunx --bun vite dev",
"build": "bunx --bun vite build",
"preview": "bunx --bun vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"format": "prettier --write .",
"lint": "prettier --check . && eslint .",
"test:e2e": "playwright test",
"test": "npm run test:e2e",
"push": "drizzle-kit push",
"generate": "drizzle-kit generate",
"studio": "drizzle-kit studio",
"start": "PORT=8080 bun /build"
},
"devDependencies": {
"@eslint/compat": "^1.2.3",
"@eslint/js": "^9.17.0",
"@internationalized/date": "^3.6.0",
"@playwright/test": "^1.45.3",
"@sveltejs/adapter-vercel": "^5.5.0",
"@sveltejs/kit": "^2.52.0",
"@sveltejs/vite-plugin-svelte": "^6.2.4",
"@tailwindcss/vite": "^4.1.7",
"@types/pg": "^8.15.6",
"bits-ui": "1.5.2",
"clsx": "^2.1.1",
"daisyui": "^4.12.23",
"drizzle-kit": "^1.0.0-beta.6-4414a19",
"eslint": "^9.7.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.36.0",
"globals": "^15.0.0",
"layerchart": "2.0.0-next.43",
"mode-watcher": "^0.5.0",
"prettier": "^3.3.2",
"prettier-plugin-svelte": "^3.2.6",
"prettier-plugin-tailwindcss": "^0.6.11",
"svelte": "^5.51.2",
"svelte-adapter-bun": "^1.0.1",
"svelte-check": "^4.4.0",
"svelte-sonner": "^1.0.1",
"tailwind-merge": "^3.3.0",
"tailwind-variants": "^1.0.0",
"tailwindcss": "^4.1.7",
"tw-animate-css": "^1.3.0",
"typescript": "^5.0.0",
"typescript-eslint": "^8.0.0",
"vite": "^7.3.1",
"vite-plugin-devtools-json": "^1.0.0"
},
"dependencies": {
"@better-fetch/fetch": "^1.1.12",
"@lucide/svelte": "^0.564.0",
"@nevthereal/random-utils": "^1.0.11",
"@oslojs/crypto": "^1.0.1",
"@oslojs/encoding": "^1.1.0",
"@sveltejs/adapter-node": "^5.4.0",
"@tailwindcss/typography": "^0.5.16",
"@tanstack/table-core": "^8.20.5",
"@upstash/redis": "^1.34.8",
"arctic": "^3.1.2",
"better-auth": "^1.4.9",
"dayjs": "^1.11.19",
"dotenv": "^16.4.7",
"drizzle-orm": "^1.0.0-beta.6-4414a19",
"drizzle-zod": "^0.6.1",
"pg": "^8.16.3",
"zod": "^4.2.1"
},
"packageManager": "bun@1.3.5"
}
116 changes: 52 additions & 64 deletions src/lib/components/DisciplineForm.svelte
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
<script lang="ts">
import { MinusCircle, PlusCircle } from '@lucide/svelte';
import { addDisciplines } from '$lib/remote/challenge.remote';
import { Button } from './ui/button';
import * as Field from './ui/field';
import { Input } from './ui/input';
import * as Sheet from './ui/sheet';
import * as Form from './ui/form';
import { type SuperValidated, type Infer, superForm } from 'sveltekit-superforms';
import { addDisciplines } from '$lib/zod';
import { MinusCircle, PlusCircle } from '@lucide/svelte';

let { formData }: { formData: SuperValidated<Infer<typeof addDisciplines>> } = $props();
let { challengeId }: { challengeId: string } = $props();

let sheetOpen = $state(false);
let rows = $state([{ name: '', multiplier: 1 }]);

const disciplineForm = superForm(formData, {
dataType: 'json',
onResult: ({ result }) => {
if (result.type === 'success') sheetOpen = !sheetOpen;
}
});
const disciplineForm = addDisciplines.for(challengeId);

const { enhance, form, constraints } = disciplineForm;
$effect(() => {
disciplineForm.fields.challengeId.set(challengeId);
});
</script>

<Sheet.Root bind:open={sheetOpen}>
Expand All @@ -28,58 +25,49 @@
<Sheet.Content>
<Sheet.Header>
<Sheet.Title>Diszipline hinzufügen</Sheet.Title>
<form method="post" action="?/addDiscipline" use:enhance>
<Form.Fieldset form={disciplineForm} name="discipline">
{#each $form.discipline as _, i}
<div class="flex">
<div class="flex gap-4">
<Form.Control>
{#snippet children({ props })}
<div class="flex flex-col gap-2">
<Form.Label>Name</Form.Label>
<Input
{...$constraints.discipline?.name}
type="text"
{...props}
bind:value={$form.discipline[i].name}
/>
</div>
{/snippet}
</Form.Control>

<Form.Control>
{#snippet children({ props })}
<div class="flex flex-col gap-2">
<Form.Label>Multiplikator</Form.Label>
<Input
{...$constraints.discipline?.multiplier}
type="number"
{...props}
bind:value={$form.discipline[i].multiplier}
/>
</div>
{/snippet}
</Form.Control>
<Form.FieldErrors />
</div>
<Button
type="button"
variant="destructive"
class="mt-auto"
onclick={() => {
$form.discipline = $form.discipline.filter((_, index) => index !== i);
}}><MinusCircle /></Button
>
</div>
{/each}
<Button
type="button"
variant="outline"
onclick={() => ($form.discipline = [...$form.discipline, { multiplier: 1, name: '' }])}
><PlusCircle /> Eine mehr</Button
>
</Form.Fieldset>
<Form.Button class="mt-4" type="submit">Speichern</Form.Button>
<form
{...disciplineForm.enhance(async ({ submit }) => {
await submit();
sheetOpen = false;
rows = [{ name: '', multiplier: 1 }];
})}
>
<input hidden {...disciplineForm.fields.challengeId.as('text')} />
{#each rows as row, i}
<div class="mb-3 flex gap-4">
<Field.Field class="flex-1">
<Field.FieldLabel for={`discipline-name-${i}`}>Name</Field.FieldLabel>
<Input id={`discipline-name-${i}`} name={`discipline[${i}].name`} bind:value={row.name} />
</Field.Field>
<Field.Field class="w-40">
<Field.FieldLabel for={`discipline-multiplier-${i}`}>Multiplikator</Field.FieldLabel>
<Input
id={`discipline-multiplier-${i}`}
type="number"
step="0.1"
name={`discipline[${i}].multiplier`}
bind:value={row.multiplier}
/>
</Field.Field>
<Button
type="button"
variant="destructive"
class="mt-auto"
onclick={() => {
rows = rows.filter((_, index) => index !== i);
}}><MinusCircle /></Button
>
</div>
{/each}
<Field.FieldError issues={disciplineForm.fields.allIssues()} />
<Button
type="button"
variant="outline"
onclick={() => {
rows = [...rows, { multiplier: 1, name: '' }];
}}><PlusCircle /> Eine mehr</Button
>
<Button class="mt-4" type="submit">Speichern</Button>
</form>
</Sheet.Header>
</Sheet.Content>
Expand Down
19 changes: 9 additions & 10 deletions src/lib/components/EntryCard.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script lang="ts">
import { entry as dbEntry, discipline as dbDiscipline } from '$lib/db/schema';
import * as Card from '$lib/components/ui/card';
import { Trash } from '@lucide/svelte';
import * as AlertDialog from '$lib/components/ui/alert-dialog';
import * as Card from '$lib/components/ui/card';
import { buttonVariants } from './ui/button/button.svelte';
import { Trash } from '@lucide/svelte';
import { enhance } from '$app/forms';
import { deleteEntry } from '$lib/remote/challenge.remote';
import { entry as dbEntry, discipline as dbDiscipline } from '$lib/db/schema';

interface Props {
entry: typeof dbEntry.$inferSelect;
Expand All @@ -16,6 +16,7 @@
let { entry, discipline, edit, challengePath }: Props = $props();

let open = $state(false);
const challengeId = $derived(challengePath.split('/').at(-1) ?? '');
</script>

<Card.Root>
Expand All @@ -37,8 +38,6 @@
</Card.Content>
</Card.Root>

<form use:enhance method="post" id="deleteForm" action="{challengePath}/activity/?/delete"></form>

{#snippet deleteDialog()}
<AlertDialog.Root bind:open>
<AlertDialog.Trigger class={buttonVariants({ variant: 'destructive', size: 'icon' })}>
Expand All @@ -54,10 +53,10 @@
<AlertDialog.Footer>
<AlertDialog.Cancel>Abbrechen</AlertDialog.Cancel>
<AlertDialog.Action
value={entry.id}
name="id"
form="deleteForm"
onclick={() => (open = false)}
onclick={async () => {
await deleteEntry({ challengeId, entryId: entry.id });
open = false;
}}
class={buttonVariants({ variant: 'destructive' })}>Löschen</AlertDialog.Action
>
</AlertDialog.Footer>
Expand Down
Loading