public home page with community activity overview
This commit is contained in:
@@ -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');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user