mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-13 08:37:03 -05:00
26 lines
726 B
TypeScript
26 lines
726 B
TypeScript
import type { ActionFunction } from "@remix-run/node";
|
|
import { json } from "@remix-run/node";
|
|
|
|
import { getThemeSession } from "./session.server";
|
|
import { isTheme } from "./provider";
|
|
|
|
export const action: ActionFunction = async ({ request }) => {
|
|
const themeSession = await getThemeSession(request);
|
|
const requestText = await request.text();
|
|
const form = new URLSearchParams(requestText);
|
|
const theme = form.get("theme");
|
|
|
|
if (!isTheme(theme)) {
|
|
return json({
|
|
success: false,
|
|
message: `theme value of ${theme ?? "null"} is not a valid theme`,
|
|
});
|
|
}
|
|
|
|
themeSession.setTheme(theme);
|
|
return json(
|
|
{ success: true },
|
|
{ headers: { "Set-Cookie": await themeSession.commit() } }
|
|
);
|
|
};
|