feat: added comments
All checks were successful
Commit / ci (push) Successful in 52s
Release / publish (push) Successful in 2m40s

This commit is contained in:
2025-12-10 19:16:18 +01:00
parent 5b8a436b91
commit 2702615b34
10 changed files with 666 additions and 1 deletions

View File

@@ -0,0 +1 @@
ALTER TABLE "rating" ALTER COLUMN "comment" SET NOT NULL;

View File

@@ -0,0 +1,436 @@
{
"id": "0528e286-2cd4-4447-a3a4-5a7c2cda83b9",
"prevId": "8f81af0f-3a4e-4fb8-b7f1-cf4e6eec7ecb",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.account": {
"name": "account",
"schema": "",
"columns": {
"userId": {
"name": "userId",
"type": "text",
"primaryKey": false,
"notNull": true
},
"type": {
"name": "type",
"type": "text",
"primaryKey": false,
"notNull": true
},
"provider": {
"name": "provider",
"type": "text",
"primaryKey": false,
"notNull": true
},
"providerAccountId": {
"name": "providerAccountId",
"type": "text",
"primaryKey": false,
"notNull": true
},
"refresh_token": {
"name": "refresh_token",
"type": "text",
"primaryKey": false,
"notNull": false
},
"access_token": {
"name": "access_token",
"type": "text",
"primaryKey": false,
"notNull": false
},
"expires_at": {
"name": "expires_at",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"token_type": {
"name": "token_type",
"type": "text",
"primaryKey": false,
"notNull": false
},
"scope": {
"name": "scope",
"type": "text",
"primaryKey": false,
"notNull": false
},
"id_token": {
"name": "id_token",
"type": "text",
"primaryKey": false,
"notNull": false
},
"session_state": {
"name": "session_state",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"account_userId_user_id_fk": {
"name": "account_userId_user_id_fk",
"tableFrom": "account",
"tableTo": "user",
"columnsFrom": ["userId"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.authenticator": {
"name": "authenticator",
"schema": "",
"columns": {
"credentialID": {
"name": "credentialID",
"type": "text",
"primaryKey": false,
"notNull": true
},
"userId": {
"name": "userId",
"type": "text",
"primaryKey": false,
"notNull": true
},
"providerAccountId": {
"name": "providerAccountId",
"type": "text",
"primaryKey": false,
"notNull": true
},
"credentialPublicKey": {
"name": "credentialPublicKey",
"type": "text",
"primaryKey": false,
"notNull": true
},
"counter": {
"name": "counter",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"credentialDeviceType": {
"name": "credentialDeviceType",
"type": "text",
"primaryKey": false,
"notNull": true
},
"credentialBackedUp": {
"name": "credentialBackedUp",
"type": "boolean",
"primaryKey": false,
"notNull": true
},
"transports": {
"name": "transports",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"authenticator_userId_user_id_fk": {
"name": "authenticator_userId_user_id_fk",
"tableFrom": "authenticator",
"tableTo": "user",
"columnsFrom": ["userId"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"authenticator_credentialID_unique": {
"name": "authenticator_credentialID_unique",
"nullsNotDistinct": false,
"columns": ["credentialID"]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.session": {
"name": "session",
"schema": "",
"columns": {
"sessionToken": {
"name": "sessionToken",
"type": "text",
"primaryKey": true,
"notNull": true
},
"userId": {
"name": "userId",
"type": "text",
"primaryKey": false,
"notNull": true
},
"expires": {
"name": "expires",
"type": "timestamp",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {
"session_userId_user_id_fk": {
"name": "session_userId_user_id_fk",
"tableFrom": "session",
"tableTo": "user",
"columnsFrom": ["userId"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.verificationToken": {
"name": "verificationToken",
"schema": "",
"columns": {
"identifier": {
"name": "identifier",
"type": "text",
"primaryKey": false,
"notNull": true
},
"token": {
"name": "token",
"type": "text",
"primaryKey": false,
"notNull": true
},
"expires": {
"name": "expires",
"type": "timestamp",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.user": {
"name": "user",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": false
},
"emailVerified": {
"name": "emailVerified",
"type": "timestamp",
"primaryKey": false,
"notNull": false
},
"image": {
"name": "image",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"user_email_unique": {
"name": "user_email_unique",
"nullsNotDistinct": false,
"columns": ["email"]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.akti": {
"name": "akti",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"title": {
"name": "title",
"type": "text",
"primaryKey": false,
"notNull": true
},
"summary": {
"name": "summary",
"type": "text",
"primaryKey": false,
"notNull": true
},
"body": {
"name": "body",
"type": "text",
"primaryKey": false,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"version": {
"name": "version",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 1
}
},
"indexes": {},
"foreignKeys": {
"akti_user_id_user_id_fk": {
"name": "akti_user_id_user_id_fk",
"tableFrom": "akti",
"tableTo": "user",
"columnsFrom": ["user_id"],
"columnsTo": ["id"],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.rating": {
"name": "rating",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"akti_id": {
"name": "akti_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"rating": {
"name": "rating",
"type": "real",
"primaryKey": false,
"notNull": true
},
"comment": {
"name": "comment",
"type": "text",
"primaryKey": false,
"notNull": true
},
"akti_version": {
"name": "akti_version",
"type": "integer",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {
"rating_akti_id_akti_id_fk": {
"name": "rating_akti_id_akti_id_fk",
"tableFrom": "rating",
"tableTo": "akti",
"columnsFrom": ["akti_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
},
"rating_user_id_user_id_fk": {
"name": "rating_user_id_user_id_fk",
"tableFrom": "rating",
"tableTo": "user",
"columnsFrom": ["user_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
}
},
"enums": {},
"schemas": {},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}

View File

@@ -29,6 +29,13 @@
"when": 1764000151184,
"tag": "0003_tranquil_iron_monger",
"breakpoints": true
},
{
"idx": 4,
"version": "7",
"when": 1765385786051,
"tag": "0004_wealthy_groot",
"breakpoints": true
}
]
}

View File

@@ -0,0 +1,31 @@
<script lang="ts">
import { Rating as FbRating } from 'flowbite-svelte';
import UserDisplay from '../UserDisplay.svelte';
interface Rating {
rating: number;
comment: string;
outdated?: boolean;
user?: {
name: string | null;
image: string | null;
};
}
let { rating }: { rating: Rating } = $props();
</script>
<div
class="w-full bg-white border border-gray-200 dark:bg-gray-800 dark:border-gray-700 shadow-md flex flex-col items-start p-5 gap-5"
>
{#if rating.user}
<UserDisplay user={rating.user} />
{/if}
{#if rating.outdated}
<span class="self-end">i</span>
{/if}
<p class="text-left">{rating.comment}</p>
{#if rating.rating}
<FbRating id="example-1b" total={5} size={30} rating={rating.rating} class="self-end mt-auto" />
{/if}
</div>

View File

@@ -0,0 +1,27 @@
<script lang="ts">
import { Button, Label, Textarea } from 'flowbite-svelte';
import RatingInput from './RatingInput.svelte';
interface Rating {
rating: number;
comment: string;
}
let { rating }: { rating: Rating } = $props();
</script>
<form method="POST" class="flex flex-col gap-5">
<div>
<Label>Komentar</Label>
<Textarea
value={rating.comment}
name="comment"
required
minlength={5}
class="w-full min-h-40"
/>
</div>
<div>
<Label>Bewärtig</Label>
<RatingInput value={rating.rating} name="rating" />
</div>
<Button type="submit" class="grow-0 self-end">Spichere</Button>
</form>

View File

@@ -0,0 +1,63 @@
<script lang="ts">
import { StarHalfSolid, StarSolid } from 'flowbite-svelte-icons';
import { twMerge, type ClassNameValue } from 'tailwind-merge';
let {
value = $bindable(5),
name,
disabled = false,
class: className
}: { value?: number; name?: string; disabled?: boolean; class?: ClassNameValue } = $props();
let stars = $derived(
[0, 1, 2, 3, 4].map((i) => {
if (value - i >= 1) {
return { id: i, value: 1 };
} else if (value - i >= 0.5) {
return { id: i, value: 0.5 };
}
return { id: i, value: 0 };
})
);
</script>
{#if name}
<input
type="number"
{name}
bind:value
tabindex="-1"
style="opacity: 0; position: absolute; pointer-events: none; z-index: -1; bottom: 0; left: 50%; height: 0; width: 0;"
/>
{/if}
<span class={twMerge('flex justify-between ', className)}>
<!-- es -->
{#each stars as s (s.id)}
<button
type="button"
{disabled}
onclick={() => {
if (s.id === 0 && value == 0.5) {
value = 0;
return;
}
if (value === s.id + 1) {
value = s.id + 0.5;
return;
}
value = s.id + 1;
}}
class="grid grid-cols-2 grid-rows-1"
>
{#if s.value >= 1}
<StarSolid class="col-span-2 text-amber-400" />
{:else}
<StarSolid class="col-span-2 col-start-1 row-start-1" />
{#if s.value >= 0.5}
<StarHalfSolid class="col-span-1 col-start-1 row-start-1 text-amber-400" />
{/if}
{/if}
</button>
{/each}
</span>

View File

@@ -26,7 +26,7 @@ export const ratings = pgTable('rating', {
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
rating: real().notNull(),
comment: text(),
comment: text().notNull(),
aktiVersion: integer('akti_version').notNull()
});

View File

@@ -4,10 +4,17 @@
import { EditOutline, CloseOutline } from 'flowbite-svelte-icons';
import AktiEditor from '$lib/components/akti/AktiEditor.svelte';
import UserDisplay from '$lib/components/UserDisplay.svelte';
import RatingCard from '$lib/components/rating/RatingCard.svelte';
import { resolve } from '$app/paths';
let { data }: PageProps = $props();
let edit = $state(false);
let canComment = $derived.by(() => {
if (!data.session) return false;
if (data.akti.author.id === data.session.user.id) return false;
return true;
});
</script>
<div class="flex justify-between">
@@ -37,4 +44,19 @@
</div>
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
{@html data.akti.body}
<div class="mt-10 mb-5 flex justify-between items-center">
<h3>Kommentär</h3>
{#if canComment}
<Button href={resolve('/akti/[aktiId]/comment', { aktiId: data.akti.id })}>
Ä Kommentar da la
</Button>
{/if}
</div>
<section class="grid grid-cols-1 gap-5 2xl:grid-cols-3">
{#each data.ratings as rating (rating.id)}
<RatingCard {rating} />
{/each}
</section>
{/if}

View File

@@ -0,0 +1,68 @@
import type { PageServerLoad } from './$types';
import { ensureAuth } from '$lib/auth';
import { error, redirect, type Actions } from '@sveltejs/kit';
import { extractFormData } from '$lib/extractFormData';
import { aktis, ratings } from '$lib/server/db/schema';
import { eq } from 'drizzle-orm';
import * as v from 'valibot';
import { db } from '$lib/server/db';
import { resolve } from '$app/paths';
export const load: PageServerLoad = async (event) => {
const user = await ensureAuth(event);
const res = await db
.select({ authorId: aktis.author })
.from(aktis)
.where(eq(aktis.id, event.params.aktiId));
if (!res[0]) return error(404);
if (res[0].authorId === user.id) return error(403);
return;
};
export const actions = {
default: async (event) => {
const user = await ensureAuth(event);
if (!event.params.aktiId) return error(404);
const akti = await db
.select({ id: aktis.id, version: aktis.version, author: aktis.author })
.from(aktis)
.limit(1)
.where(eq(aktis.id, event.params.aktiId));
if (!akti || akti.length == 0) return error(404);
if (akti[0].author == user.id) return error(403);
const rating = (
await extractFormData(
event.request,
v.object({
comment: v.pipe(v.string(), v.minLength(5)),
rating: v.pipe(
v.string(),
v.transform((i) => Number.parseFloat(i)),
v.minValue(0),
v.maxValue(5)
)
})
)
).data;
if (!rating) return error(400);
await db.insert(ratings).values({
...rating,
userId: user.id,
aktiId: event.params.aktiId,
aktiVersion: akti[0].version
});
return redirect(303, resolve(`/akti/[aktiId]`, { aktiId: event.params.aktiId }));
}
} satisfies Actions;

View File

@@ -0,0 +1,10 @@
<script lang="ts">
import RatingEditor from '$lib/components/rating/RatingEditor.svelte';
</script>
<RatingEditor
rating={{
comment: '',
rating: 5
}}
/>