mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
fix bknd theme
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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__) {
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user