add user accounts and OSM peak catalog with zoom-based notability
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
import { error, redirect } from '@sveltejs/kit';
|
||||
import { db, deleteActivity, getActivity } from '$lib/server/db';
|
||||
import { baggedPeaks, deleteActivity, getActivity } from '$lib/server/db';
|
||||
import { haversine } from '$lib/server/gpx';
|
||||
import type { Actions, PageServerLoad } from './$types';
|
||||
import type { PeakRow } from '$lib/server/db';
|
||||
|
||||
export const load: PageServerLoad = ({ params }) => {
|
||||
const activity = getActivity(Number(params.id));
|
||||
export const load: PageServerLoad = ({ params, locals }) => {
|
||||
const activity = getActivity(Number(params.id), locals.user!.id);
|
||||
if (!activity) error(404, 'Activity not found');
|
||||
|
||||
const points = JSON.parse(activity.points) as {
|
||||
@@ -27,9 +26,7 @@ export const load: PageServerLoad = ({ params }) => {
|
||||
if (points[i].ele !== null) profile.push({ d: dist, ele: points[i].ele! });
|
||||
}
|
||||
|
||||
const bagged = db
|
||||
.prepare('SELECT * FROM peaks WHERE activity_id = ?')
|
||||
.all(activity.id) as PeakRow[];
|
||||
const bagged = baggedPeaks(activity.id, locals.user!.id);
|
||||
|
||||
return {
|
||||
activity: { ...activity, points: undefined },
|
||||
@@ -38,7 +35,7 @@ export const load: PageServerLoad = ({ params }) => {
|
||||
bagged: bagged.map((p) => ({
|
||||
id: p.id,
|
||||
name: p.name,
|
||||
elevation_m: p.elevation_m,
|
||||
elevation_m: Math.round(p.elevation_m ?? 0),
|
||||
lat: p.lat,
|
||||
lon: p.lon,
|
||||
climbed: true
|
||||
@@ -47,8 +44,8 @@ export const load: PageServerLoad = ({ params }) => {
|
||||
};
|
||||
|
||||
export const actions: Actions = {
|
||||
delete: async ({ params }) => {
|
||||
deleteActivity(Number(params.id));
|
||||
delete: async ({ params, locals }) => {
|
||||
deleteActivity(Number(params.id), locals.user!.id);
|
||||
redirect(303, '/activities');
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user