Enhance SvelteKit project by adding new API routes for dark mode toggling, updating existing route parameters, and improving type definitions. Refactor component imports and optimize asset handling for better performance and maintainability.
This commit is contained in:
@@ -4,6 +4,22 @@ const load = async ({ locals }) => {
|
||||
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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user