public home page with community activity overview

This commit is contained in:
Vincent van der Wal
2026-07-22 11:19:09 +02:00
parent b17f56b194
commit addef8b78e
11 changed files with 198 additions and 93 deletions
+5 -3
View File
@@ -4,7 +4,7 @@ import { haversine } from '$lib/server/gpx';
import type { Actions, PageServerLoad } from './$types';
export const load: PageServerLoad = ({ params, locals }) => {
const activity = getActivity(Number(params.id), locals.user!.id);
const activity = getActivity(Number(params.id));
if (!activity) error(404, 'Activity not found');
const points = JSON.parse(activity.points) as {
@@ -26,10 +26,11 @@ export const load: PageServerLoad = ({ params, locals }) => {
if (points[i].ele !== null) profile.push({ d: dist, ele: points[i].ele! });
}
const bagged = baggedPeaks(activity.id, locals.user!.id);
const bagged = baggedPeaks(activity.id, activity.user_id);
return {
activity: { ...activity, points: undefined },
canDelete: locals.user?.id === activity.user_id,
latlngs,
profile,
bagged: bagged.map((p) => ({
@@ -45,7 +46,8 @@ export const load: PageServerLoad = ({ params, locals }) => {
export const actions: Actions = {
delete: async ({ params, locals }) => {
deleteActivity(Number(params.id), locals.user!.id);
if (!locals.user) error(401, 'Not signed in');
deleteActivity(Number(params.id), locals.user.id);
redirect(303, '/activities');
}
};
+18 -10
View File
@@ -20,17 +20,21 @@
<div class="head">
<div>
<h1>{a.name}</h1>
<p class="page-sub">{fmtDate(a.date)} · <span class="type">{a.type}</span></p>
<p class="page-sub">
<span class="who">{a.username}</span> · {fmtDate(a.date)} · <span class="type">{a.type}</span>
</p>
</div>
<form
method="POST"
action="?/delete"
use:enhance={({ cancel }) => {
if (!confirm('Delete this activity? Peaks it bagged stay climbed.')) cancel();
}}
>
<button class="btn danger" type="submit">Delete</button>
</form>
{#if data.canDelete}
<form
method="POST"
action="?/delete"
use:enhance={({ cancel }) => {
if (!confirm('Delete this activity? Peaks it bagged stay climbed.')) cancel();
}}
>
<button class="btn danger" type="submit">Delete</button>
</form>
{/if}
</div>
<div class="kpis">
@@ -79,6 +83,10 @@
.type {
text-transform: capitalize;
}
.who {
font-weight: 600;
color: var(--accent-strong);
}
.kpis {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));