update state management

This commit is contained in:
Fran Jurmanović
2025-02-08 18:34:06 +01:00
parent 01fc6e9feb
commit 3ad4b95656
10 changed files with 93 additions and 86 deletions

View File

@@ -1,24 +1,24 @@
import { updateConfig, getConfigFiles } from '$api/serverService';
import type { Actions } from './$types';
import type { Actions, RequestEvent } from './$types';
import { checkAuth } from '$api/authService';
import { getTracks } from '$api/lookupService';
import { redirect } from '@sveltejs/kit';
export const load = async ({ params }) => {
const isAuth = await checkAuth();
export const load = async (event) => {
const isAuth = await checkAuth(event);
if (!isAuth) return redirect(308, '/login');
const config = await getConfigFiles(params.id);
const tracks = await getTracks();
const config = await getConfigFiles(event, event.params.id);
const tracks = await getTracks(event);
return {
id: params.id,
id: event.params.id,
config,
tracks
};
};
export const actions = {
event: async ({ request }) => {
const formData = await request.formData();
event: async (event: RequestEvent) => {
const formData = await event.request.formData();
const id = formData.get('id') as string;
const object: any = {};
formData.forEach((value, key) => {
@@ -32,7 +32,7 @@ export const actions = {
object[key] = value != '' && !Number.isNaN(+value) ? +value : value;
}
});
await updateConfig(id, 'event.json', object, true, true);
await updateConfig(event, id, 'event.json', object, true, true);
redirect(303, '/dashboard');
}
} satisfies Actions;