({ request, context })
| 5 | import { sendEvent } from "~/graphJSON.server"; |
| 6 | |
| 7 | export const action: ActionFunction = async ({ request, context }) => { |
| 8 | const themeSession = await getThemeSession(request); |
| 9 | const requestText = await request.text(); |
| 10 | const form = new URLSearchParams(requestText); |
| 11 | const theme = form.get("theme"); |
| 12 | |
| 13 | if (!isTheme(theme)) { |
| 14 | return json({ |
| 15 | success: false, |
| 16 | message: `theme value of ${theme} is not a valid theme`, |
| 17 | }); |
| 18 | } |
| 19 | |
| 20 | themeSession.setTheme(theme); |
| 21 | |
| 22 | context.waitUntil( |
| 23 | sendEvent({ |
| 24 | type: "set-theme", |
| 25 | theme, |
| 26 | }) |
| 27 | ); |
| 28 | |
| 29 | return json( |
| 30 | { success: true }, |
| 31 | { headers: { "Set-Cookie": await themeSession.commit() } } |
| 32 | ); |
| 33 | }; |
| 34 | |
| 35 | export const loader: LoaderFunction = () => redirect("/", { status: 404 }); |
nothing calls this directly
no test coverage detected