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:
@@ -2,52 +2,67 @@
|
||||
"/": [
|
||||
"src/routes/+page.server.ts",
|
||||
"src/routes/+layout.ts",
|
||||
"src/routes/+layout.ts"
|
||||
"src/routes/+layout.server.ts",
|
||||
"src/routes/+layout.ts",
|
||||
"src/routes/+layout.server.ts"
|
||||
],
|
||||
"/accounts": [
|
||||
"src/routes/accounts/+page.server.ts",
|
||||
"src/routes/+layout.ts"
|
||||
"src/routes/+layout.ts",
|
||||
"src/routes/+layout.server.ts"
|
||||
],
|
||||
"/accounts/new": [
|
||||
"src/routes/+layout.ts"
|
||||
"src/routes/+layout.ts",
|
||||
"src/routes/+layout.server.ts"
|
||||
],
|
||||
"/accounts/[id]": [
|
||||
"src/routes/+layout.ts"
|
||||
"src/routes/+layout.ts",
|
||||
"src/routes/+layout.server.ts"
|
||||
],
|
||||
"/items": [
|
||||
"src/routes/items/+page.server.ts",
|
||||
"src/routes/+layout.ts"
|
||||
"src/routes/+layout.ts",
|
||||
"src/routes/+layout.server.ts"
|
||||
],
|
||||
"/items/[id]": [
|
||||
"src/routes/items/[id]/+page.server.ts",
|
||||
"src/routes/+layout.ts"
|
||||
"src/routes/+layout.ts",
|
||||
"src/routes/+layout.server.ts"
|
||||
],
|
||||
"/login": [
|
||||
"src/routes/login/+page.server.ts",
|
||||
"src/routes/+layout.ts"
|
||||
"src/routes/+layout.ts",
|
||||
"src/routes/+layout.server.ts"
|
||||
],
|
||||
"/logout": [
|
||||
"src/routes/logout/+page.server.ts",
|
||||
"src/routes/+layout.ts"
|
||||
"src/routes/+layout.ts",
|
||||
"src/routes/+layout.server.ts"
|
||||
],
|
||||
"/receipts": [
|
||||
"src/routes/receipts/+page.server.ts",
|
||||
"src/routes/+layout.ts"
|
||||
"src/routes/+layout.ts",
|
||||
"src/routes/+layout.server.ts"
|
||||
],
|
||||
"/receipts/new": [
|
||||
"src/routes/+layout.ts"
|
||||
"src/routes/+layout.ts",
|
||||
"src/routes/+layout.server.ts"
|
||||
],
|
||||
"/receipts/[id]": [
|
||||
"src/routes/+layout.ts"
|
||||
"src/routes/+layout.ts",
|
||||
"src/routes/+layout.server.ts"
|
||||
],
|
||||
"/transactions": [
|
||||
"src/routes/transactions/+page.server.ts",
|
||||
"src/routes/+layout.ts"
|
||||
"src/routes/+layout.ts",
|
||||
"src/routes/+layout.server.ts"
|
||||
],
|
||||
"/transactions/new": [
|
||||
"src/routes/+layout.ts"
|
||||
"src/routes/+layout.ts",
|
||||
"src/routes/+layout.server.ts"
|
||||
],
|
||||
"/transactions/[id]": [
|
||||
"src/routes/+layout.ts"
|
||||
"src/routes/+layout.ts",
|
||||
"src/routes/+layout.server.ts"
|
||||
]
|
||||
}
|
||||
+11
-2
@@ -15,17 +15,26 @@ type PageServerParentData = EnsureDefined<LayoutServerData>;
|
||||
type PageParentData = EnsureDefined<LayoutData>;
|
||||
type LayoutRouteId = RouteId | "/" | "/receipts" | "/receipts/new" | "/receipts/[id]" | "/logout" | "/transactions" | "/transactions/new" | "/transactions/[id]" | "/accounts" | "/accounts/new" | "/accounts/[id]" | "/items" | "/items/[id]" | "/login" | null
|
||||
type LayoutParams = RouteParams & { id?: string }
|
||||
type LayoutServerParentData = EnsureDefined<{}>;
|
||||
type LayoutParentData = EnsureDefined<{}>;
|
||||
|
||||
export type PageServerLoad<OutputData extends OutputDataShape<PageServerParentData> = OutputDataShape<PageServerParentData>> = Kit.ServerLoad<RouteParams, PageServerParentData, OutputData, RouteId>;
|
||||
export type PageServerLoadEvent = Parameters<PageServerLoad>[0];
|
||||
export type ActionData = unknown;
|
||||
type ExcludeActionFailure<T> = T extends Kit.ActionFailure<any> ? never : T extends void ? never : T;
|
||||
type ActionsSuccess<T extends Record<string, (...args: any) => any>> = { [Key in keyof T]: ExcludeActionFailure<Awaited<ReturnType<T[Key]>>>; }[keyof T];
|
||||
type ExtractActionFailure<T> = T extends Kit.ActionFailure<infer X> ? X extends void ? never : X : never;
|
||||
type ActionsFailure<T extends Record<string, (...args: any) => any>> = { [Key in keyof T]: Exclude<ExtractActionFailure<Awaited<ReturnType<T[Key]>>>, void>; }[keyof T];
|
||||
type ActionsExport = typeof import('./proxy+page.server.js').actions
|
||||
export type SubmitFunction = Kit.SubmitFunction<Expand<ActionsSuccess<ActionsExport>>, Expand<ActionsFailure<ActionsExport>>>
|
||||
export type ActionData = Expand<Kit.AwaitedActions<ActionsExport>> | null;
|
||||
export type PageServerData = Expand<OptionalUnion<EnsureDefined<Kit.LoadProperties<Awaited<ReturnType<typeof import('./proxy+page.server.js').load>>>>>>;
|
||||
export type PageData = Expand<Omit<PageParentData, keyof PageServerData> & EnsureDefined<PageServerData>>;
|
||||
export type Action<OutputData extends Record<string, any> | void = Record<string, any> | void> = Kit.Action<RouteParams, OutputData, RouteId>
|
||||
export type Actions<OutputData extends Record<string, any> | void = Record<string, any> | void> = Kit.Actions<RouteParams, OutputData, RouteId>
|
||||
export type PageProps = { params: RouteParams; data: PageData; form: ActionData }
|
||||
export type LayoutServerData = null;
|
||||
export type LayoutServerLoad<OutputData extends Partial<App.PageData> & Record<string, any> | void = Partial<App.PageData> & Record<string, any> | void> = Kit.ServerLoad<LayoutParams, LayoutServerParentData, OutputData, LayoutRouteId>;
|
||||
export type LayoutServerLoadEvent = Parameters<LayoutServerLoad>[0];
|
||||
export type LayoutServerData = Expand<OptionalUnion<EnsureDefined<Kit.LoadProperties<Awaited<ReturnType<typeof import('./proxy+layout.server.js').load>>>>>>;
|
||||
export type LayoutLoad<OutputData extends OutputDataShape<LayoutParentData> = OutputDataShape<LayoutParentData>> = Kit.Load<LayoutParams, LayoutServerData, LayoutParentData, OutputData, LayoutRouteId>;
|
||||
export type LayoutLoadEvent = Parameters<LayoutLoad>[0];
|
||||
export type LayoutData = Expand<Omit<LayoutParentData, keyof LayoutParentData & EnsureDefined<LayoutServerData>> & OptionalUnion<EnsureDefined<LayoutParentData & EnsureDefined<LayoutServerData>>>>;
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import type * as Kit from '@sveltejs/kit';
|
||||
|
||||
type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
|
||||
// @ts-ignore
|
||||
type MatcherParam<M> = M extends (param : string) => param is infer U ? U extends string ? U : string : string;
|
||||
type RouteParams = { };
|
||||
type RouteId = '/api/toggle-darkmode';
|
||||
|
||||
export type RequestHandler = Kit.RequestHandler<RouteParams, RouteId>;
|
||||
export type RequestEvent = Kit.RequestEvent<RouteParams, RouteId>;
|
||||
@@ -0,0 +1,17 @@
|
||||
// @ts-nocheck
|
||||
import type { LayoutServerLoad } from "./$types";
|
||||
|
||||
export const load = async ({ locals }: Parameters<LayoutServerLoad>[0]) => {
|
||||
const user = locals.user as (Record<string, unknown> & { id: string; darkmode?: boolean }) | null;
|
||||
return {
|
||||
user: user
|
||||
? {
|
||||
id: user.id,
|
||||
email: user.email,
|
||||
name: user.name,
|
||||
avatar: user.avatar,
|
||||
darkmode: !!user.darkmode,
|
||||
}
|
||||
: null,
|
||||
};
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
// @ts-nocheck
|
||||
import type { PageServerLoad } from "./$types";
|
||||
import type { Actions, PageServerLoad } from "./$types";
|
||||
import type { StackqItem } from "$lib/types/items";
|
||||
|
||||
const COLLECTION = "Stackq_Items";
|
||||
@@ -13,3 +13,22 @@ export const load = async ({ locals }: Parameters<PageServerLoad>[0]) => {
|
||||
const itemsForParent = list.map((i) => ({ id: i.id, Item: i.Item, SKU: i.SKU }));
|
||||
return { items: list, itemsForParent };
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
setDarkmode: async ({ request, locals }: import('./$types').RequestEvent) => {
|
||||
const user = locals.user as { id: string } | null;
|
||||
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 };
|
||||
}
|
||||
},
|
||||
};
|
||||
;null as any as Actions;
|
||||
Reference in New Issue
Block a user