mirror of
https://github.com/randyjc/Rahoot.git
synced 2026-03-14 04:25:35 +01:00
adding theming to client and bug fixes
This commit is contained in:
32
packages/web/src/components/ThemeHydrator.tsx
Normal file
32
packages/web/src/components/ThemeHydrator.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
"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
|
||||
Reference in New Issue
Block a user