Merge branch 'feature'
This commit is contained in:
53
web/src/lib/stores/comment_store.ts
Normal file
53
web/src/lib/stores/comment_store.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { Comment } from "$lib/models/comment";
|
||||
import { pb } from "$lib/pocketbase";
|
||||
import { ClientResponseError } from "pocketbase";
|
||||
import { writable, type Writable } from "svelte/store";
|
||||
|
||||
export const comments: Writable<Comment[]> = writable([])
|
||||
|
||||
|
||||
export async function comments_create(comment: Comment) {
|
||||
if (!pb.authStore.model) {
|
||||
throw new Error("Unauthenticated");
|
||||
}
|
||||
|
||||
comment.author = pb.authStore.model!.id;
|
||||
|
||||
let r = await fetch('/api/v1/comment', {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(comment),
|
||||
})
|
||||
|
||||
if (!r.ok) {
|
||||
throw new ClientResponseError(await r.json())
|
||||
}
|
||||
|
||||
const model: Comment = await r.json();
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
export async function comments_update(comment: Comment) {
|
||||
let r = await fetch('/api/v1/comment/' + comment.id, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(comment),
|
||||
})
|
||||
|
||||
if (!r.ok) {
|
||||
throw new ClientResponseError(await r.json())
|
||||
}
|
||||
|
||||
const model: Comment = await r.json();
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
export async function comments_delete(comment: Comment) {
|
||||
const r = await fetch('/api/v1/comment/' + comment.id, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
|
||||
if (!r.ok) {
|
||||
throw new ClientResponseError(await r.json())
|
||||
}
|
||||
}
|
||||
@@ -170,7 +170,7 @@ export async function trails_search_bounding_box(northEast: LatLng, southWest: L
|
||||
|
||||
export async function trails_show(id: string, loadGPX?: boolean, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
||||
const r = await f(`/api/v1/trail/${id}?` + new URLSearchParams({
|
||||
expand: "category,waypoints,summit_logs",
|
||||
expand: "category,waypoints,summit_logs,comments_via_trail.author",
|
||||
}), {
|
||||
method: 'GET',
|
||||
})
|
||||
@@ -251,7 +251,7 @@ export async function trails_create(trail: Trail, photos: File[], gpx: File | Bl
|
||||
}
|
||||
}
|
||||
|
||||
export async function trails_update(oldTrail: Trail, newTrail: Trail, photos: File[], gpx: File | Blob | null) {
|
||||
export async function trails_update(oldTrail: Trail, newTrail: Trail, photos?: File[], gpx?: File | Blob | null) {
|
||||
|
||||
const waypointUpdates = compareObjectArrays<Waypoint>(oldTrail.expand.waypoints ?? [], newTrail.expand.waypoints ?? []);
|
||||
|
||||
@@ -306,10 +306,13 @@ export async function trails_update(oldTrail: Trail, newTrail: Trail, photos: Fi
|
||||
formData.append("gpx", gpx);
|
||||
}
|
||||
|
||||
for (const photo of photos) {
|
||||
formData.append("photos", photo)
|
||||
if (photos) {
|
||||
for (const photo of photos) {
|
||||
formData.append("photos", photo)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const deletedPhotos = oldTrail.photos.filter(oldPhoto => !newTrail.photos.find(newPhoto => newPhoto === oldPhoto));
|
||||
|
||||
for (const deletedPhoto of deletedPhotos) {
|
||||
|
||||
Reference in New Issue
Block a user