feat: add sdk context and useSdk
This commit is contained in:
parent
8643363736
commit
7f26bc1060
|
@ -0,0 +1,18 @@
|
||||||
|
import React from "react";
|
||||||
|
import {Sdk} from "@lumeweb/portal-sdk";
|
||||||
|
|
||||||
|
export const SdkContext = React.createContext<
|
||||||
|
Partial<Sdk>
|
||||||
|
>({});
|
||||||
|
|
||||||
|
export const SdkContextProvider: React.FC< {sdk: Sdk, children: React.ReactNode}> = ({sdk, children}) => {
|
||||||
|
return (
|
||||||
|
<SdkContext.Provider value={sdk}>
|
||||||
|
{children}
|
||||||
|
</SdkContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export function useSdk(): Partial<Sdk>{
|
||||||
|
return React.useContext(SdkContext);
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ import {Refine} from "@refinedev/core";
|
||||||
import {PortalAuthProvider} from "~/data/auth-provider.js";
|
import {PortalAuthProvider} from "~/data/auth-provider.js";
|
||||||
import routerProvider from "@refinedev/remix-router";
|
import routerProvider from "@refinedev/remix-router";
|
||||||
import { defaultProvider } from "./data/file-provider";
|
import { defaultProvider } from "./data/file-provider";
|
||||||
|
import {SdkContextProvider} from "~/components/lib/sdk-context.js";
|
||||||
|
|
||||||
export const links: LinksFunction = () => [
|
export const links: LinksFunction = () => [
|
||||||
{ rel: "stylesheet", href: stylesheet },
|
{ rel: "stylesheet", href: stylesheet },
|
||||||
|
@ -39,9 +40,10 @@ export function Layout({children}: { children: React.ReactNode }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
|
const auth = PortalAuthProvider.create("https://alpha.pinner.xyz")
|
||||||
return (
|
return (
|
||||||
<Refine
|
<Refine
|
||||||
authProvider={PortalAuthProvider.create("https://alpha.pinner.xyz")}
|
authProvider={auth}
|
||||||
routerProvider={routerProvider}
|
routerProvider={routerProvider}
|
||||||
dataProvider={defaultProvider}
|
dataProvider={defaultProvider}
|
||||||
resources={[
|
resources={[
|
||||||
|
@ -49,7 +51,9 @@ export default function App() {
|
||||||
{ name: 'users' }
|
{ name: 'users' }
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<Outlet/>
|
<SdkContextProvider sdk={(auth as PortalAuthProvider).sdk}>
|
||||||
|
<Outlet/>
|
||||||
|
</SdkContextProvider>
|
||||||
</Refine>
|
</Refine>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue