adds profile page
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { List, type ListFilter } from "$lib/models/list";
|
||||
import type { Trail } from "$lib/models/trail";
|
||||
import { pb } from "$lib/pocketbase";
|
||||
import { getFileURL } from "$lib/util/file_util";
|
||||
import { writable, type Writable } from "svelte/store";
|
||||
@@ -8,10 +9,10 @@ export const list: Writable<List> = writable(new List("", []))
|
||||
|
||||
|
||||
export async function lists_index(filter?: ListFilter) {
|
||||
const dbResponse: List[] = (await pb.collection('lists').getList<List>(1, 5, {
|
||||
const dbResponse: List[] = (await pb.collection('lists').getFullList<List>({
|
||||
expand: "trails",
|
||||
sort: `${filter?.sortOrder ?? "+"}${filter?.sort ?? "name"}`
|
||||
})).items
|
||||
}))
|
||||
|
||||
for (const list of dbResponse) {
|
||||
list.avatar = getFileURL(list, list.avatar);
|
||||
@@ -19,7 +20,7 @@ export async function lists_index(filter?: ListFilter) {
|
||||
|
||||
lists.set(dbResponse);
|
||||
|
||||
if(dbResponse.length > 0) {
|
||||
if (dbResponse.length > 0) {
|
||||
list.set(dbResponse[0])
|
||||
}
|
||||
|
||||
@@ -38,17 +39,29 @@ export async function lists_create(formData: { [key: string]: any; } | FormData)
|
||||
.create<List>(formData);
|
||||
}
|
||||
|
||||
export async function lists_update(list:List, formData: { [key: string]: any; } | FormData) {
|
||||
if((formData.get("avatar") as File).size == 0) {
|
||||
export async function lists_update(list: List, formData: { [key: string]: any; } | FormData) {
|
||||
if ((formData.get("avatar") as File).size == 0) {
|
||||
formData.delete("avatar");
|
||||
}
|
||||
let model = await pb
|
||||
.collection("lists")
|
||||
.update<List>(list.id! ,formData);
|
||||
.update<List>(list.id!, formData);
|
||||
}
|
||||
|
||||
export async function lists_delete(list:List) {
|
||||
export async function lists_delete(list: List) {
|
||||
let success = await pb
|
||||
.collection("lists")
|
||||
.delete(list.id!);
|
||||
}
|
||||
|
||||
export async function lists_add_trail(list: List, trail: Trail) {
|
||||
let model = await pb
|
||||
.collection("lists")
|
||||
.update(list.id!, { "trails+": trail.id });
|
||||
}
|
||||
|
||||
export async function lists_remove_trail(list: List, trail: Trail) {
|
||||
let model = await pb
|
||||
.collection("lists")
|
||||
.update(list.id!, { "trails-": trail.id });
|
||||
}
|
||||
Reference in New Issue
Block a user