fix bknd theme

This commit is contained in:
dswbx
2025-02-06 15:00:54 +01:00
parent e14d528386
commit 0a5cc2ad98
14 changed files with 82 additions and 52 deletions

View File

@@ -15,6 +15,7 @@ type BkndContext = {
actions: ReturnType<typeof getSchemaActions>;
app: AppReduced;
adminOverride?: ModuleConfigs["server"]["admin"];
fallback: boolean;
};
const BkndContext = createContext<BkndContext>(undefined!);
@@ -37,7 +38,7 @@ export function BkndProvider({
>) {
const [withSecrets, setWithSecrets] = useState<boolean>(includeSecrets);
const [schema, setSchema] =
useState<Pick<BkndContext, "version" | "schema" | "config" | "permissions">>();
useState<Pick<BkndContext, "version" | "schema" | "config" | "permissions" | "fallback">>();
const [fetched, setFetched] = useState(false);
const [error, setError] = useState<boolean>();
const errorShown = useRef<boolean>();
@@ -78,7 +79,8 @@ export function BkndProvider({
version: 0,
schema: getDefaultSchema(),
config: getDefaultConfig(),
permissions: []
permissions: [],
fallback: true
} as any);
if (adminOverride) {

View File

@@ -60,6 +60,7 @@ export const useBaseUrl = () => {
type BkndWindowContext = {
user?: TApiUser;
logout_route: string;
color_scheme?: "light" | "dark";
};
export function useBkndWindowContext(): BkndWindowContext {
if (typeof window !== "undefined" && window.__BKND__) {

View File

@@ -1,8 +1,9 @@
import { useBknd } from "ui/client/bknd";
import { useTheme } from "ui/client/use-theme";
export function useBkndSystem() {
const { config, schema, actions: bkndActions } = useBknd();
const theme = config.server.admin.color_scheme ?? "light";
const { theme } = useTheme();
const actions = {
theme: {

View File

@@ -1,8 +1,18 @@
import { useBkndWindowContext } from "ui/client/ClientProvider";
import { useBknd } from "ui/client/bknd";
export function useTheme(): { theme: "light" | "dark" } {
const b = useBknd();
const theme = b.app.getAdminConfig().color_scheme as any;
export type Theme = "light" | "dark";
return { theme };
export function useTheme(fallback: Theme = "light"): { theme: Theme } {
const b = useBknd();
const winCtx = useBkndWindowContext();
if (b) {
if (b?.adminOverride?.color_scheme) {
return { theme: b.adminOverride.color_scheme };
} else if (!b.fallback) {
return { theme: b.config.server.admin.color_scheme ?? fallback };
}
}
return { theme: winCtx.color_scheme ?? fallback };
}