feat: add sdk context and useSdk

This commit is contained in:
Derrick Hammer 2024-03-18 10:09:37 -04:00
parent 8643363736
commit 7f26bc1060
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 24 additions and 2 deletions

View File

@ -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);
}

View File

@ -15,6 +15,7 @@ import {Refine} from "@refinedev/core";
import {PortalAuthProvider} from "~/data/auth-provider.js";
import routerProvider from "@refinedev/remix-router";
import { defaultProvider } from "./data/file-provider";
import {SdkContextProvider} from "~/components/lib/sdk-context.js";
export const links: LinksFunction = () => [
{ rel: "stylesheet", href: stylesheet },
@ -39,9 +40,10 @@ export function Layout({children}: { children: React.ReactNode }) {
}
export default function App() {
const auth = PortalAuthProvider.create("https://alpha.pinner.xyz")
return (
<Refine
authProvider={PortalAuthProvider.create("https://alpha.pinner.xyz")}
authProvider={auth}
routerProvider={routerProvider}
dataProvider={defaultProvider}
resources={[
@ -49,7 +51,9 @@ export default function App() {
{ name: 'users' }
]}
>
<Outlet/>
<SdkContextProvider sdk={(auth as PortalAuthProvider).sdk}>
<Outlet/>
</SdkContextProvider>
</Refine>
);
}