front end fixes

This commit is contained in:
Christian Beutel
2025-03-17 02:09:00 +01:00
parent 07ff8807fe
commit d23444c799
36 changed files with 328 additions and 295 deletions

View File

@@ -28,11 +28,11 @@ export async function comments_index(trail: Trail) {
}
export async function comments_create(comment: Comment) {
if (!pb.authStore.model) {
if (!pb.authStore.record) {
throw new Error("Unauthenticated");
}
comment.author = pb.authStore.model!.id;
comment.author = pb.authStore.record!.id;
let r = await fetch('/api/v1/comment', {
method: 'PUT',

View File

@@ -25,11 +25,11 @@ export async function integrations_index(f: (url: RequestInfo | URL, config?: Re
}
export async function integrations_create(integration: Integration) {
if (!pb.authStore.model) {
if (!pb.authStore.record) {
throw new Error("Unauthenticated");
}
integration.user = pb.authStore.model!.id;
integration.user = pb.authStore.record!.id;
let r = await fetch('/api/v1/integration', {
method: 'PUT',

View File

@@ -121,11 +121,11 @@ export async function lists_show(id: string, f: (url: RequestInfo | URL, config?
}
export async function lists_create(list: List, avatar?: File) {
if (!pb.authStore.model) {
if (!pb.authStore.record) {
throw new Error("Unauthenticated");
}
list.author = pb.authStore.model!.id;
list.author = pb.authStore.record!.id;
let r = await fetch('/api/v1/list', {
method: 'PUT',
@@ -241,13 +241,13 @@ function buildFilterText(filter: ListFilter): string {
if (filter.author?.length) {
filterText += `&&author="${filter.author}"`
}
if (pb.authStore.model) {
if (pb.authStore.record) {
if (filter.public === false && filter.shared === false) {
filterText += `&&author="${pb.authStore.model.id}"`
filterText += `&&author="${pb.authStore.record.id}"`
} else if (filter.public === true && filter.shared === false) {
filterText += `&&(public=true||list_share_via_list.user!="${pb.authStore.model.id}"||author="${pb.authStore.model.id}")`
filterText += `&&(public=true||list_share_via_list.user!="${pb.authStore.record.id}"||author="${pb.authStore.record.id}")`
} else if (filter.public === false && filter.shared === true) {
filterText += `&&(public=false||list_share_via_list.user="${pb.authStore.model.id}"||author="${pb.authStore.model.id}")`
filterText += `&&(public=false||list_share_via_list.user="${pb.authStore.record.id}"||author="${pb.authStore.record.id}")`
}
}
return filterText
@@ -268,17 +268,17 @@ function buildSearchFilterText(filter: ListFilter): string {
if (filter.public !== undefined) {
filterText += `(public = ${filter.public}`
if (!filter.author?.length || filter.author == pb.authStore.model?.id) {
filterText += ` OR author = ${pb.authStore.model?.id}`
if (!filter.author?.length || filter.author == pb.authStore.record?.id) {
filterText += ` OR author = ${pb.authStore.record?.id}`
}
filterText += ")"
}
if (filter.shared !== undefined) {
if (filter.shared === true) {
filterText += ` OR shares = ${pb.authStore.model?.id}`
filterText += ` OR shares = ${pb.authStore.record?.id}`
} else {
filterText += ` AND NOT shares = ${pb.authStore.model?.id}`
filterText += ` AND NOT shares = ${pb.authStore.record?.id}`
}
}

View File

@@ -46,7 +46,7 @@ export async function summit_logs_index(author: string, filter?: SummitLogFilter
}
export async function summit_logs_create(summitLog: SummitLog, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
summitLog.author = pb.authStore.model!.id
summitLog.author = pb.authStore.record!.id
let r = await f('/api/v1/summit-log', {
method: 'PUT',
@@ -101,7 +101,7 @@ export async function summit_logs_create(summitLog: SummitLog, f: (url: RequestI
}
export async function summit_logs_update(oldSummitLog: SummitLog, newSummitLog: SummitLog) {
newSummitLog.author = pb.authStore.model!.id
newSummitLog.author = pb.authStore.record!.id
let r = await fetch('/api/v1/summit-log/' + newSummitLog.id, {
method: 'POST',

View File

@@ -182,7 +182,7 @@ export async function trails_create(trail: Trail, photos: File[], gpx: File | Bl
trail.summit_logs.push(model.id!);
}
trail.author = pb.authStore.model!.id
trail.author = pb.authStore.record!.id
let r = await f(`/api/v1/trail?` + new URLSearchParams({
expand: "category,waypoints,summit_logs,trail_share_via_trail",
@@ -501,17 +501,17 @@ function buildFilterText(filter: TrailFilter, includeGeo: boolean): string {
if (filter.public !== undefined) {
filterText += `(public = ${filter.public}`
if (!filter.author?.length || filter.author == pb.authStore.model?.id) {
filterText += ` OR author = ${pb.authStore.model?.id}`
if (!filter.author?.length || filter.author == pb.authStore.record?.id) {
filterText += ` OR author = ${pb.authStore.record?.id}`
}
filterText += ")"
}
if (filter.shared !== undefined) {
if (filter.shared === true) {
filterText += ` OR shares = ${pb.authStore.model?.id}`
filterText += ` OR shares = ${pb.authStore.record?.id}`
} else {
filterText += ` AND NOT shares = ${pb.authStore.model?.id}`
filterText += ` AND NOT shares = ${pb.authStore.record?.id}`
}
}

View File

@@ -25,7 +25,7 @@ export async function users_create(user: User) {
export async function users_search(q: string, includeSelf: boolean = true) {
let r = await fetch('/api/v1/user/anonymous?' + new URLSearchParams({
"filter": `username~"${q}"${includeSelf ? '' : `&&id!="${pb.authStore.model?.id}"`}`,
"filter": `username~"${q}"${includeSelf ? '' : `&&id!="${pb.authStore.record?.id}"`}`,
}), {
method: 'GET',
})
@@ -62,7 +62,7 @@ export async function users_auth_methods(f: (url: RequestInfo | URL, config?: Re
const response = await r.json();
throw new APIError(r.status, response.message, response.detail)
}
return await r.json()
return await r.json() as AuthMethodsList
}

View File

@@ -7,7 +7,7 @@ export const waypoint: Writable<Waypoint> = writable(new Waypoint(0, 0));
export async function waypoints_create(waypoint: Waypoint, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
waypoint.author = pb.authStore.model!.id
waypoint.author = pb.authStore.record!.id
let r = await f('/api/v1/waypoint', {
method: 'PUT',
@@ -45,7 +45,7 @@ export async function waypoints_create(waypoint: Waypoint, f: (url: RequestInfo
}
export async function waypoints_update(oldWaypoint: Waypoint, newWaypoint: Waypoint) {
newWaypoint.author = pb.authStore.model!.id
newWaypoint.author = pb.authStore.record!.id
let r = await fetch('/api/v1/waypoint/' + newWaypoint.id, {
method: 'POST',