2023-10-23 23:11:59 +02:00
|
|
|
"use server"
|
2023-08-01 14:11:46 +02:00
|
|
|
|
2023-10-23 23:11:59 +02:00
|
|
|
import { cookies } from "next/headers"
|
2023-08-01 14:11:46 +02:00
|
|
|
|
2023-10-23 23:11:59 +02:00
|
|
|
import type { Theme } from "@/utils/constants"
|
|
|
|
import { COOKIE_MAX_AGE, DEFAULT_THEME, THEMES } from "@/utils/constants"
|
2023-08-01 14:11:46 +02:00
|
|
|
|
|
|
|
export const setTheme = (theme: Theme): void => {
|
2023-10-23 23:11:59 +02:00
|
|
|
cookies().set("theme", theme, {
|
|
|
|
path: "/",
|
|
|
|
maxAge: COOKIE_MAX_AGE,
|
2023-08-01 14:11:46 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getTheme = (): Theme => {
|
2023-10-23 23:11:59 +02:00
|
|
|
const theme = cookies().get("theme")?.value ?? DEFAULT_THEME
|
2023-08-01 14:11:46 +02:00
|
|
|
if (THEMES.includes(theme as Theme)) {
|
|
|
|
return theme as Theme
|
|
|
|
}
|
|
|
|
return DEFAULT_THEME
|
|
|
|
}
|