Files
Stackq/.svelte-kit/adapter-node/entries/pages/_page.server.ts.js
T

26 lines
864 B
JavaScript

const COLLECTION = "Stackq_Items";
const load = async ({ locals }) => {
const list = await locals.pb.collection(COLLECTION).getFullList({ sort: "-created", expand: "Parent" }).catch(() => []);
const itemsForParent = list.map((i) => ({ id: i.id, Item: i.Item, SKU: i.SKU }));
return { items: list, itemsForParent };
};
const actions = {
setDarkmode: async ({ request, locals }) => {
const user = locals.user;
if (!user) return { success: false };
const formData = await request.formData();
const darkmode = formData.get("darkmode") === "true";
try {
const record = await locals.pb.collection("users").update(user.id, { darkmode });
locals.pb.authStore.save(locals.pb.authStore.token, record);
return { success: true, darkmode };
} catch {
return { success: false };
}
}
};
export {
actions,
load
};