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 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' }
|
||||
]}
|
||||
>
|
||||
<SdkContextProvider sdk={(auth as PortalAuthProvider).sdk}>
|
||||
<Outlet/>
|
||||
</SdkContextProvider>
|
||||
</Refine>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue