mirror of
https://github.com/randyjc/Rahoot.git
synced 2026-03-14 04:25:35 +01:00
33 lines
850 B
TypeScript
33 lines
850 B
TypeScript
"use client"
|
|
|
|
import { useEffect } from "react"
|
|
import { useThemeStore } from "@rahoot/web/stores/theme"
|
|
|
|
const ThemeHydrator = () => {
|
|
const { setBackground, setBrandName } = useThemeStore()
|
|
|
|
useEffect(() => {
|
|
const load = async () => {
|
|
try {
|
|
const res = await fetch("/api/theme", { cache: "no-store" })
|
|
const data = await res.json()
|
|
if (res.ok && data.theme) {
|
|
if (typeof data.theme.backgroundUrl === "string") {
|
|
setBackground(data.theme.backgroundUrl || null)
|
|
}
|
|
if (typeof data.theme.brandName === "string") {
|
|
setBrandName(data.theme.brandName)
|
|
}
|
|
}
|
|
} catch (error) {
|
|
console.error("Failed to hydrate theme", error)
|
|
}
|
|
}
|
|
load()
|
|
}, [setBackground, setBrandName])
|
|
|
|
return null
|
|
}
|
|
|
|
export default ThemeHydrator
|