touchups after refactor
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
<script lang="ts">
|
||||
import type { Notification } from "$lib/models/notification";
|
||||
import { fly } from "svelte/transition";
|
||||
import NotificationCard from "./notification_card.svelte";
|
||||
import { goto } from "$app/navigation";
|
||||
import { page } from "$app/stores";
|
||||
import type { Notification } from "$lib/models/notification";
|
||||
import {
|
||||
notifications_index,
|
||||
notifications_mark_as_seen,
|
||||
} from "$lib/stores/notification_store";
|
||||
import { currentUser } from "$lib/stores/user_store";
|
||||
import { goto } from "$app/navigation";
|
||||
import { onMount } from "svelte";
|
||||
import SkeletonListItem from "../base/skeleton_list_item.svelte";
|
||||
import { fly } from "svelte/transition";
|
||||
import SkeletonNotificationCard from "../base/skeleton_notification_card.svelte";
|
||||
import NotificationCard from "./notification_card.svelte";
|
||||
import { _ } from "svelte-i18n";
|
||||
|
||||
let notifications: Notification[] = [];
|
||||
|
||||
@@ -134,7 +134,7 @@
|
||||
{/each}
|
||||
{:else}
|
||||
<p class="text-gray-500 text-sm text-center py-6">
|
||||
No notifications
|
||||
{$_("no-notifications")}
|
||||
</p>
|
||||
{/if}
|
||||
</ul>
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
? $_("planned-a-trail")
|
||||
: $_("completed-a-trail")}
|
||||
<p class="text-xs text-gray-500 mb-3">
|
||||
{new Date(activity.date).toLocaleDateString(undefined, {
|
||||
{new Date(activity.created).toLocaleDateString(undefined, {
|
||||
month: "long",
|
||||
day: "2-digit",
|
||||
year: "numeric",
|
||||
|
||||
@@ -174,6 +174,7 @@
|
||||
"no-account": "Du hast noch kein Konto?",
|
||||
"no-data": "Keine Daten",
|
||||
"no-grid": "Kein Gitter",
|
||||
"no-notifications": "",
|
||||
"no-preference": "Keine Präferenz",
|
||||
"no-results": "Keine Ergebnisse gefunden",
|
||||
"no-routes-added": "",
|
||||
|
||||
@@ -174,6 +174,7 @@
|
||||
"no-account": "Don't have an account?",
|
||||
"no-data": "No data",
|
||||
"no-grid": "No Grid",
|
||||
"no-notifications": "No notifications",
|
||||
"no-preference": "No preference",
|
||||
"no-results": "No results found",
|
||||
"no-routes-added": "No routes added",
|
||||
|
||||
@@ -174,6 +174,7 @@
|
||||
"no-account": "Pas encore de compte ?",
|
||||
"no-data": "",
|
||||
"no-grid": "",
|
||||
"no-notifications": "",
|
||||
"no-preference": "Pas de préférence",
|
||||
"no-results": "Pas de résultat",
|
||||
"no-routes-added": "",
|
||||
|
||||
@@ -174,6 +174,7 @@
|
||||
"no-account": "Nincs még fiókja?",
|
||||
"no-data": "",
|
||||
"no-grid": "",
|
||||
"no-notifications": "",
|
||||
"no-preference": "Nincs preferált",
|
||||
"no-results": "Nincs eredmény",
|
||||
"no-routes-added": "",
|
||||
|
||||
@@ -174,6 +174,7 @@
|
||||
"no-account": "Non hai ancora un account?",
|
||||
"no-data": "",
|
||||
"no-grid": "",
|
||||
"no-notifications": "",
|
||||
"no-preference": "Nessuna preferenza",
|
||||
"no-results": "Nessun risultato trovato",
|
||||
"no-routes-added": "",
|
||||
|
||||
@@ -174,6 +174,7 @@
|
||||
"no-account": "Heb je nog geen account?",
|
||||
"no-data": "",
|
||||
"no-grid": "",
|
||||
"no-notifications": "",
|
||||
"no-preference": "Geen voorkeur",
|
||||
"no-results": "Er zijn geen zoekresultaten",
|
||||
"no-routes-added": "",
|
||||
|
||||
@@ -174,6 +174,7 @@
|
||||
"no-account": "Nie masz konta?",
|
||||
"no-data": "",
|
||||
"no-grid": "",
|
||||
"no-notifications": "",
|
||||
"no-preference": "Brak preferencji",
|
||||
"no-results": "Brak wyników",
|
||||
"no-routes-added": "",
|
||||
|
||||
@@ -174,6 +174,7 @@
|
||||
"no-account": "Não tem uma conta?",
|
||||
"no-data": "",
|
||||
"no-grid": "",
|
||||
"no-notifications": "",
|
||||
"no-preference": "Nenhuma preferência",
|
||||
"no-results": "Nenhum resultado encontrado",
|
||||
"no-routes-added": "",
|
||||
|
||||
@@ -174,6 +174,7 @@
|
||||
"no-account": "还未注册?",
|
||||
"no-data": "",
|
||||
"no-grid": "",
|
||||
"no-notifications": "",
|
||||
"no-preference": "尚未规划",
|
||||
"no-results": "没有找到结果",
|
||||
"no-routes-added": "",
|
||||
|
||||
@@ -12,6 +12,7 @@ interface Activity {
|
||||
elevation_loss: number;
|
||||
type: "trail" | "summit_log"
|
||||
author: string;
|
||||
created: string;
|
||||
}
|
||||
|
||||
export { type Activity }
|
||||
@@ -3,7 +3,7 @@ import type { Comment } from "../comment";
|
||||
|
||||
const CommentCreateSchema = z.object({
|
||||
text: z.string(),
|
||||
rating: z.number(),
|
||||
rating: z.number().optional(),
|
||||
author: z.string().length(15),
|
||||
trail: z.string().length(15),
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { UserAnonymous } from "./user";
|
||||
export class Comment {
|
||||
id?: string;
|
||||
text: string;
|
||||
rating: number;
|
||||
rating?: number;
|
||||
author: string;
|
||||
trail: string;
|
||||
created?: string;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { object, string } from "yup";
|
||||
import type { Trail } from "./trail";
|
||||
import type { ListShare } from "./list_share";
|
||||
import type { UserAnonymous } from "./user";
|
||||
@@ -36,11 +35,4 @@ export interface ListFilter {
|
||||
public?: boolean;
|
||||
shared?: boolean;
|
||||
sortOrder?: "+" | "-"
|
||||
}
|
||||
|
||||
export const listSchema = object<List>({
|
||||
id: string().optional(),
|
||||
name: string().required(),
|
||||
description: string().optional(),
|
||||
avatar: string().optional()
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import * as M from "maplibre-gl";
|
||||
import { number, object, string } from "yup";
|
||||
|
||||
class Waypoint {
|
||||
id?: string;
|
||||
|
||||
@@ -7,7 +7,8 @@ export async function activities_index(author: string, page: number = 1, perPage
|
||||
const r = await f('/api/v1/activity?' + new URLSearchParams({
|
||||
"perPage": perPage.toString(),
|
||||
page: page.toString(),
|
||||
filter: `author="${author}"`
|
||||
filter: `author="${author}"`,
|
||||
sort: "-created"
|
||||
}), {
|
||||
method: 'GET',
|
||||
})
|
||||
|
||||
@@ -8,7 +8,7 @@ export async function notifications_index(data: { recipient: string, seen?: bool
|
||||
filter: `created>=@month&&recipient='${data.recipient}'` + (data.seen !== undefined ? `&&seen=${data.seen}` : ''),
|
||||
sort: '+seen,-created',
|
||||
page: page.toString(),
|
||||
"per-page": perPage.toString()
|
||||
"perPage": perPage.toString()
|
||||
}), {
|
||||
method: 'GET',
|
||||
})
|
||||
|
||||
@@ -18,7 +18,7 @@ export const editTrail: Writable<Trail> = writable(new Trail(""));
|
||||
|
||||
export async function trails_index(perPage: number = 21, random: boolean = false, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
||||
const r = await f('/api/v1/trail?' + new URLSearchParams({
|
||||
"per-page": perPage.toString(),
|
||||
"perPage": perPage.toString(),
|
||||
expand: "category,waypoints,summit_logs",
|
||||
sort: random ? "@random" : "",
|
||||
}), {
|
||||
@@ -102,7 +102,7 @@ export async function trails_search_bounding_box(northEast: M.LngLat, southWest:
|
||||
}
|
||||
|
||||
r = await fetch('/api/v1/trail?' + new URLSearchParams({
|
||||
"per-page": "-1",
|
||||
"perPage": "-1",
|
||||
filter: `'${trailIds.join(',')}'~id`,
|
||||
expand: "category,waypoints,summit_logs",
|
||||
sort: `+name`,
|
||||
|
||||
@@ -60,11 +60,13 @@ export async function show<T>(event: RequestEvent, collection: Collection) {
|
||||
}
|
||||
|
||||
export async function create<T>(event: RequestEvent, schema: ZodSchema, collection: Collection) {
|
||||
const data = await event.request.json();
|
||||
const searchParams = Object.fromEntries(event.url.searchParams);
|
||||
const safeSearchParams = RecordOptionsSchema.parse(searchParams);
|
||||
|
||||
const data = await event.request.json();
|
||||
const safeData = schema.parse(data);
|
||||
|
||||
const r = await pb.collection(Collection[collection]).create<T>(safeData)
|
||||
const r = await pb.collection(Collection[collection]).create<T>(safeData, safeSearchParams)
|
||||
|
||||
return r
|
||||
}
|
||||
@@ -106,10 +108,12 @@ export async function remove(event: RequestEvent, collection: Collection) {
|
||||
|
||||
export function handleError(e: any) {
|
||||
if (e instanceof ZodError) {
|
||||
return error(400, e.message)
|
||||
return error(400, { message: "invalid_params", details: e.issues } as any)
|
||||
} else if (e instanceof ClientResponseError && e.status > 0) {
|
||||
return error(e.status as NumericRange<400, 599>, e.message)
|
||||
return error(e.status as NumericRange<400, 599>, { message: e.message, detail: e.originalError.data } as any)
|
||||
} else if (e instanceof SyntaxError) {
|
||||
return error(400, "invalid_json")
|
||||
} else {
|
||||
return e
|
||||
return error(500, e.toString())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user