mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 21:06:04 +00:00
removed admin config from server, theme is now client side, fixed module manager migrations
This commit is contained in:
@@ -4,7 +4,13 @@ import { createContext, startTransition, useContext, useEffect, useRef, useState
|
||||
import { useApi } from "ui/client";
|
||||
import { type TSchemaActions, getSchemaActions } from "./schema/actions";
|
||||
import { AppReduced } from "./utils/AppReduced";
|
||||
import type { AppTheme } from "ui/client/use-theme";
|
||||
|
||||
export type BkndAdminOptions = {
|
||||
logo_return_path?: string;
|
||||
basepath?: string;
|
||||
theme?: AppTheme;
|
||||
};
|
||||
type BkndContext = {
|
||||
version: number;
|
||||
schema: ModuleSchemas;
|
||||
@@ -14,7 +20,7 @@ type BkndContext = {
|
||||
requireSecrets: () => Promise<void>;
|
||||
actions: ReturnType<typeof getSchemaActions>;
|
||||
app: AppReduced;
|
||||
adminOverride?: ModuleConfigs["server"]["admin"];
|
||||
options: BkndAdminOptions;
|
||||
fallback: boolean;
|
||||
};
|
||||
|
||||
@@ -29,13 +35,15 @@ enum Fetching {
|
||||
|
||||
export function BkndProvider({
|
||||
includeSecrets = false,
|
||||
adminOverride,
|
||||
options,
|
||||
children,
|
||||
fallback = null,
|
||||
}: { includeSecrets?: boolean; children: any; fallback?: React.ReactNode } & Pick<
|
||||
BkndContext,
|
||||
"adminOverride"
|
||||
>) {
|
||||
}: {
|
||||
includeSecrets?: boolean;
|
||||
children: any;
|
||||
fallback?: React.ReactNode;
|
||||
options?: BkndAdminOptions;
|
||||
}) {
|
||||
const [withSecrets, setWithSecrets] = useState<boolean>(includeSecrets);
|
||||
const [schema, setSchema] =
|
||||
useState<Pick<BkndContext, "version" | "schema" | "config" | "permissions" | "fallback">>();
|
||||
@@ -93,13 +101,6 @@ export function BkndProvider({
|
||||
fallback: true,
|
||||
} as any);
|
||||
|
||||
if (adminOverride) {
|
||||
newSchema.config.server.admin = {
|
||||
...newSchema.config.server.admin,
|
||||
...adminOverride,
|
||||
};
|
||||
}
|
||||
|
||||
startTransition(() => {
|
||||
document.startViewTransition(() => {
|
||||
setSchema(newSchema);
|
||||
@@ -122,13 +123,13 @@ export function BkndProvider({
|
||||
}, []);
|
||||
|
||||
if (!fetched || !schema) return fallback;
|
||||
const app = new AppReduced(schema?.config as any);
|
||||
const app = new AppReduced(schema?.config as any, options);
|
||||
const actions = getSchemaActions({ api, setSchema, reloadSchema });
|
||||
const hasSecrets = withSecrets && !error;
|
||||
|
||||
return (
|
||||
<BkndContext.Provider
|
||||
value={{ ...schema, actions, requireSecrets, app, adminOverride, hasSecrets }}
|
||||
value={{ ...schema, actions, requireSecrets, app, options: app.options, hasSecrets }}
|
||||
key={local_version}
|
||||
>
|
||||
{/*{error && (
|
||||
@@ -153,3 +154,12 @@ export function useBknd({ withSecrets }: { withSecrets?: boolean } = {}): BkndCo
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
export function useBkndOptions(): BkndAdminOptions {
|
||||
const ctx = useContext(BkndContext);
|
||||
return (
|
||||
ctx.options ?? {
|
||||
basepath: "/",
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user