Release v0.1.2
This commit is contained in:
21
webui/src/platform/ModuleContext.tsx
Normal file
21
webui/src/platform/ModuleContext.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import { createContext, type ReactNode, useContext } from "react";
|
||||
import type { PlatformWebModule } from "../types";
|
||||
import { moduleInstalled, uiCapability } from "./modules";
|
||||
|
||||
const PlatformModulesContext = createContext<PlatformWebModule[]>([]);
|
||||
|
||||
export function PlatformModulesProvider({ modules, children }: { modules: PlatformWebModule[]; children: ReactNode }) {
|
||||
return <PlatformModulesContext.Provider value={modules}>{children}</PlatformModulesContext.Provider>;
|
||||
}
|
||||
|
||||
export function usePlatformModules(): PlatformWebModule[] {
|
||||
return useContext(PlatformModulesContext);
|
||||
}
|
||||
|
||||
export function usePlatformModuleInstalled(moduleId: string): boolean {
|
||||
return moduleInstalled(moduleId, usePlatformModules());
|
||||
}
|
||||
|
||||
export function usePlatformUiCapability<T = unknown>(capabilityName: string): T | null {
|
||||
return uiCapability<T>(capabilityName, usePlatformModules());
|
||||
}
|
||||
Reference in New Issue
Block a user