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

@@ -4,7 +4,7 @@ import { currentUser } from '$lib/stores/user_store';
pb.authStore.loadFromCookie(document.cookie)
pb.authStore.onChange(() => {
currentUser.set(pb.authStore.model as User)
currentUser.set(pb.authStore.record as User)
const secure = location.protocol === "https:"
document.cookie = pb.authStore.exportToCookie({ httpOnly: false, secure: secure, sameSite: "Lax" })
}, true)

View File

@@ -56,9 +56,9 @@ const auth: Handle = async ({ event, resolve }) => {
// validate the user existence and if the path is acceesible
if (!pb.authStore.model && isRouteProtected(url.pathname)) {
if (!pb.authStore.record && isRouteProtected(url.pathname)) {
throw redirect(302, '/login?r=' + url.pathname);
} else if (pb.authStore.model && url.pathname === "/login") {
} else if (pb.authStore.record && url.pathname === "/login") {
throw redirect(302, '/');
} else if (envPub.PUBLIC_DISABLE_SIGNUP === "true" && url.pathname === "/register") {
throw redirect(302, '/');
@@ -76,9 +76,9 @@ const auth: Handle = async ({ event, resolve }) => {
let meiliApiKey: string = "";
let settings: Settings | undefined;
if (pb.authStore.model) {
meiliApiKey = pb.authStore.model.token
settings = await pb.collection('settings').getFirstListItem<Settings>(`user="${pb.authStore.model.id}"`, { requestKey: null })
if (pb.authStore.record) {
meiliApiKey = pb.authStore.record.token
settings = await pb.collection('settings').getFirstListItem<Settings>(`user="${pb.authStore.record.id}"`, { requestKey: null })
} else {
const r = await event.fetch(pb.buildURL("/public/search/token"));
const response = await r.json();
@@ -88,15 +88,15 @@ const auth: Handle = async ({ event, resolve }) => {
event.locals.ms = ms
event.locals.pb = pb
event.locals.user = pb.authStore.model
event.locals.user = pb.authStore.record
event.locals.settings = settings
const lang = settings?.language ?? event.request.headers.get('accept-language')?.split(',')[0]
if (lang) {
locale.set(lang)
if (pb.authStore.model) {
pb.authStore.model!.language = lang;
if (pb.authStore.record) {
pb.authStore.record!.language = lang;
}
}

View File

@@ -108,7 +108,7 @@
}
}
let user = $derived(browser ? $currentUser : pb.authStore.model);
let user = $derived(browser ? $currentUser : pb.authStore.record);
</script>
<Drawer bind:open={drawerOpen}>

View File

@@ -21,7 +21,7 @@
let showInfo: boolean = $state(false);
let loading: boolean = $state(false);
let infoLoaded: boolean = $state(false);
let subjectIsOwned: boolean = subject.author == pb.authStore.model?.id;
let subjectIsOwned: boolean = subject.author == pb.authStore.record?.id;
let author: UserAnonymous | undefined = $state();
async function fetchInfo() {

View File

@@ -74,13 +74,13 @@
/>
{/if}
</div>
{#if (trail.public || trailIsShared) && pb.authStore.model}
{#if (trail.public || trailIsShared) && pb.authStore.record}
<div
class="flex absolute top-4 right-4 {trail.public && trailIsShared
? 'w-14'
: 'w-8'} h-8 rounded-full items-center justify-center bg-background text-content"
>
{#if trail.public && pb.authStore.model}
{#if trail.public && pb.authStore.record}
<span
class="tooltip"
class:mr-2={trail.public && trailIsShared}

View File

@@ -62,10 +62,10 @@
]
: []),
{ text: $_("print"), value: "print", icon: "print" },
...(trail.author != pb.authStore.model?.id
...(trail.author != pb.authStore.record?.id
? []
: [{ text: $_("add-to-list"), value: "list", icon: "bookmark" }]),
...(trail.author != pb.authStore.model?.id
...(trail.author != pb.authStore.record?.id
? []
: [{ text: $_("share"), value: "share", icon: "share" }]),
...(allowEdit

View File

@@ -169,7 +169,7 @@
placeholder={`${$_("filter-categories")}...`}
></MultiSelect>
<hr class="my-4 border-separator" />
{#if pb.authStore.model}
{#if pb.authStore.record}
<UserSearch
onclick={(item) => setAuthorFilter(item)}
onclear={() => {

View File

@@ -62,7 +62,7 @@
const tabs = [
$_("summit-book"),
$_("photos"),
...(pb.authStore.model ? [$_("comment", { values: { n: 2 } })] : []),
...(pb.authStore.record ? [$_("comment", { values: { n: 2 } })] : []),
];
const trailIsShared =
@@ -192,14 +192,14 @@
<div
class="absolute bottom-0 w-full h-full bg-gradient-to-b from-transparent to-black opacity-60"
></div>
{#if (trail.public || trailIsShared) && pb.authStore.model}
{#if (trail.public || trailIsShared) && pb.authStore.record}
<div
class="flex absolute top-6 right-6 {trail.public &&
trailIsShared
? 'w-16'
: 'w-8'} h-8 rounded-full items-center justify-center bg-white text-primary"
>
{#if trail.public && pb.authStore.model}
{#if trail.public && pb.authStore.record}
<span
class:tooltip={mode != "map"}
class:mr-3={trail.public && trailIsShared}

View File

@@ -54,7 +54,7 @@
<h4 class="font-semibold text-lg">
{trail.name}
</h4>
{#if trail.public && pb.authStore.model}
{#if trail.public && pb.authStore.record}
<span class="tooltip ml-3" data-title={$_("public")}>
<i class="fa fa-globe"></i>
</span>

View File

@@ -18,5 +18,5 @@ register('zh', () => import('./locales/zh.json'))
init({
fallbackLocale: defaultLocale,
initialLocale: browser ? pb.authStore.model?.language ?? window.navigator.language : defaultLocale,
initialLocale: browser ? pb.authStore.record?.language ?? window.navigator.language : defaultLocale,
})

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',

View File

@@ -12,10 +12,10 @@ export async function GET(event: RequestEvent) {
try {
const r = await pb.collection('users').listAuthMethods();
for (const provider of r.authProviders) {
for (const provider of r.oauth2.providers) {
const imageURL = `${env.PUBLIC_POCKETBASE_URL}/_/images/oauth2/${provider.name}.svg`
provider['img' as keyof typeof provider] = await imageUrlToBase64(imageURL, event.fetch);
provider['url' as keyof typeof provider] = `${provider.authUrl}${redirectURL}`
provider['url' as keyof typeof provider] = `${provider.authURL}${redirectURL}`
}
return json(r)
} catch (e: any) {

View File

@@ -21,7 +21,7 @@ export async function GET(event: RequestEvent) {
parts.push(encodeURIComponent(safeParams.data.record));
parts.push(encodeURIComponent(safeParams.data.file));
let fileURL = pb.buildUrl(parts.join("/"));
let fileURL = pb.buildURL(parts.join("/"));
try {
const r = await event.fetch(fileURL)

View File

@@ -8,7 +8,7 @@ export async function GET(event: RequestEvent) {
try {
const r = await list<List>(event, Collection.lists);
for (const t of r.items) {
if (!t.author || !pb.authStore.model) {
if (!t.author || !pb.authStore.record) {
continue;
}
if (!t.expand) {

View File

@@ -9,7 +9,7 @@ export async function GET(event: RequestEvent) {
const r = await list<SummitLog>(event, Collection.summit_logs);
for (const t of r.items) {
if (!t.author || !pb.authStore.model) {
if (!t.author || !pb.authStore.record) {
continue;
}
if (!t.expand) {

View File

@@ -9,7 +9,7 @@ export async function GET(event: RequestEvent) {
const r = await list<Trail>(event, Collection.trails);
for (const t of r.items) {
if (!t.author || !pb.authStore.model) {
if (!t.author || !pb.authStore.record) {
continue;
}
if (!t.expand) {

View File

@@ -8,7 +8,7 @@ export async function GET(event: RequestEvent) {
try {
const r = await show<Trail>(event, Collection.trails)
if (pb.authStore.model) {
if (pb.authStore.record) {
if (!r.expand) {
r.expand = {} as any
}

View File

@@ -4,7 +4,7 @@ import { handleError } from '$lib/util/api_util';
import { error, json, type RequestEvent } from '@sveltejs/kit';
export async function GET(event: RequestEvent) {
if (!pb.authStore.model) {
if (!pb.authStore.record) {
return json({
max_lat: 0,
min_lat: 0,
@@ -13,7 +13,7 @@ export async function GET(event: RequestEvent) {
});
}
try {
const r = await pb.collection('trails_bounding_box').getOne<TrailBoundingBox>(pb.authStore.model!.id)
const r = await pb.collection('trails_bounding_box').getOne<TrailBoundingBox>(pb.authStore.record!.id)
return json(r)
} catch (e: any) {
throw handleError(e);

View File

@@ -4,7 +4,7 @@ import { handleError } from '$lib/util/api_util';
import { error, json, type RequestEvent } from '@sveltejs/kit';
export async function GET(event: RequestEvent) {
if (!pb.authStore.model) {
if (!pb.authStore.record) {
return json({
min_distance: 0,
max_distance: 20000,
@@ -15,7 +15,7 @@ export async function GET(event: RequestEvent) {
});
}
try {
const r = await pb.collection('trails_filter').getOne<TrailFilterValues>(pb.authStore.model!.id)
const r = await pb.collection('trails_filter').getOne<TrailFilterValues>(pb.authStore.record!.id)
return json(r)
} catch (e: any) {
throw handleError(e);

View File

@@ -10,7 +10,7 @@ export async function GET(event: RequestEvent) {
const searchParams = Object.fromEntries(event.url.searchParams);
const safeSearchParams = TrailRecommendSchema.parse(searchParams);
const r = await event.fetch(pb.buildUrl("/trail/recommend?" + new URLSearchParams({
const r = await event.fetch(pb.buildURL("/trail/recommend?" + new URLSearchParams({
size: safeSearchParams.size?.toString() ?? ""
})));
@@ -23,7 +23,7 @@ export async function GET(event: RequestEvent) {
const result: Trail[] = await r.json();
for (const t of result) {
if (!t.author || !pb.authStore.model) {
if (!t.author || !pb.authStore.record) {
continue;
}
if (!t.expand) {

View File

@@ -23,9 +23,9 @@ export async function POST(event: RequestEvent) {
const safeData = UserUpdateSchema.parse(data);
if (safeData.email && safeData.email != pb.authStore.model!.email) {
if (safeData.email && safeData.email != pb.authStore.record!.email) {
const r = await pb.collection('users').requestEmailChange(safeData.email);
pb.authStore.model!.email = safeData.email;
pb.authStore.record!.email = safeData.email;
}
const r = await pb.collection('users').update<User>(safeParams.id, safeData)
if (safeData.password) {

View File

@@ -15,21 +15,19 @@
import { type AuthProviderInfo } from "pocketbase";
import { _ } from "svelte-i18n";
import { z } from "zod";
import type { PageProps } from "./$types";
let loading: boolean = $state(false);
const authProviders = page.data.authMethods.authProviders;
let { data: pageData }: PageProps = $props();
const authProviders = pageData.authMethods.oauth2.providers;
let loginLabel = $state("");
if (
page.data.authMethods.usernamePassword &&
page.data.authMethods.emailPassword
) {
if (pageData.authMethods.password) {
loginLabel = `${$_("username")}/${$_("email")}`;
}else if (pageData.authMethods.password) {
loginLabel = `${$_("username")}/${$_("email")}`;
} else if (page.data.authMethods.usernamePassword) {
loginLabel = `${$_("username")}`;
} else if (page.data.authMethods.emailPassword) {
loginLabel = `${$_("email")}`;
}
const { form, errors, data } = createForm<User>({
@@ -100,7 +98,7 @@
<LogoTextTwoLineLight></LogoTextTwoLineLight>
{/if}
<h4 class="text-xl font-semibold">{$_("slogan")}</h4>
{#if page.data.authMethods.usernamePassword || page.data.authMethods.emailPassword}
{#if page.data.authMethods.password}
<div class="space-y-6 w-80">
<TextField
name="username"
@@ -147,13 +145,13 @@
<div class="w-80 space-y-4">
{#each authProviders as provider}
<a
href={provider.url}
href={(provider as any).url}
class="btn-secondary inline-flex min-w-full justify-center"
onclick={() => setProvider(provider)}
>
<img
class="w-5 aspect-square mr-4"
src={provider.img}
src={(provider as any).img}
alt="Provider logo"
/>
Login with {provider.displayName}

View File

@@ -10,7 +10,7 @@ export const load: Load = async ({ params, fetch }) => {
return error(400, "Bad Request")
}
const categories = await categories_index(fetch)
const lists = await lists_index({ q: "", author: pb.authStore.model?.id ?? "" }, 1, -1, fetch)
const lists = await lists_index({ q: "", author: pb.authStore.record?.id ?? "" }, 1, -1, fetch)
let trail: Trail;
if (params.id === "new") {