Compare commits
3 Commits
740d276071
...
c5e22f52e1
Author | SHA1 | Date |
---|---|---|
Derrick Hammer | c5e22f52e1 | |
Derrick Hammer | 5bdd888f63 | |
Derrick Hammer | 849b723e8c |
|
@ -5,26 +5,19 @@ import {accountProvider} from "~/data/account-provider.js";
|
||||||
import type {SdkProvider} from "~/data/sdk-provider.js";
|
import type {SdkProvider} from "~/data/sdk-provider.js";
|
||||||
import {createPortalAuthProvider} from "~/data/auth-provider.js";
|
import {createPortalAuthProvider} from "~/data/auth-provider.js";
|
||||||
|
|
||||||
interface DataProviders {
|
export interface DataProviders {
|
||||||
default: SdkProvider;
|
default: SdkProvider;
|
||||||
auth: AuthProvider;
|
auth: AuthProvider;
|
||||||
[key: string]: SdkProvider | AuthProvider;
|
[key: string]: SdkProvider | AuthProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
let providers: DataProviders;
|
|
||||||
|
|
||||||
export function getProviders(sdk: Sdk) {
|
export function getProviders(sdk: Sdk) {
|
||||||
if (providers) {
|
|
||||||
return providers;
|
|
||||||
}
|
|
||||||
|
|
||||||
accountProvider.sdk = sdk;
|
accountProvider.sdk = sdk;
|
||||||
fileProvider.sdk = sdk;
|
fileProvider.sdk = sdk;
|
||||||
providers = {
|
|
||||||
|
return {
|
||||||
default: accountProvider,
|
default: accountProvider,
|
||||||
auth: createPortalAuthProvider(sdk),
|
auth: createPortalAuthProvider(sdk),
|
||||||
files: fileProvider,
|
files: fileProvider,
|
||||||
};
|
};
|
||||||
|
|
||||||
return providers;
|
|
||||||
}
|
}
|
||||||
|
|
46
app/root.tsx
46
app/root.tsx
|
@ -1,10 +1,4 @@
|
||||||
import {
|
import {Links, Meta, Outlet, Scripts, ScrollRestoration,} from "@remix-run/react";
|
||||||
Links,
|
|
||||||
Meta,
|
|
||||||
Outlet,
|
|
||||||
Scripts,
|
|
||||||
ScrollRestoration,
|
|
||||||
} from "@remix-run/react";
|
|
||||||
|
|
||||||
import stylesheet from "./tailwind.css?url";
|
import stylesheet from "./tailwind.css?url";
|
||||||
import type {LinksFunction} from "@remix-run/node";
|
import type {LinksFunction} from "@remix-run/node";
|
||||||
|
@ -58,16 +52,7 @@ function App() {
|
||||||
|
|
||||||
export default function Root() {
|
export default function Root() {
|
||||||
const [portalUrl, setPortalUrl] = useState(import.meta.env.VITE_PORTAL_URL);
|
const [portalUrl, setPortalUrl] = useState(import.meta.env.VITE_PORTAL_URL);
|
||||||
const sdk = Sdk.create(portalUrl);
|
const [sdk, setSdk] = useState<Sdk| undefined>(portalUrl ? Sdk.create(portalUrl) : undefined);
|
||||||
|
|
||||||
const providers = useMemo(() => getProviders(sdk as Sdk), [sdk]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (sdk) {
|
|
||||||
PinningProcess.setupSdk(sdk as Sdk);
|
|
||||||
}
|
|
||||||
}, [sdk]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!portalUrl) {
|
if (!portalUrl) {
|
||||||
fetch("/api/meta")
|
fetch("/api/meta")
|
||||||
|
@ -81,12 +66,34 @@ export default function Root() {
|
||||||
}
|
}
|
||||||
}, [portalUrl]);
|
}, [portalUrl]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (portalUrl) {
|
||||||
|
setSdk(Sdk.create(portalUrl));
|
||||||
|
}
|
||||||
|
}, [portalUrl]);
|
||||||
|
|
||||||
if (!portalUrl) {
|
if (!portalUrl) {
|
||||||
return <p>Loading...</p>;
|
return <p>Loading...</p>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SdkContextProvider sdk={sdk}>
|
<SdkContextProvider sdk={sdk as Sdk}>
|
||||||
|
<SdkWrapper />
|
||||||
|
</SdkContextProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function SdkWrapper() {
|
||||||
|
const sdk = useSdk();
|
||||||
|
PinningProcess.setupSdk(sdk as Sdk);
|
||||||
|
|
||||||
|
const providers = useMemo(() => getProviders(sdk as Sdk), [sdk]);
|
||||||
|
|
||||||
|
if (!sdk) {
|
||||||
|
return <p>Loading...</p>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
<Refine
|
<Refine
|
||||||
authProvider={providers.auth}
|
authProvider={providers.auth}
|
||||||
|
@ -101,8 +108,7 @@ export default function Root() {
|
||||||
<App/>
|
<App/>
|
||||||
</Refine>
|
</Refine>
|
||||||
</QueryClientProvider>
|
</QueryClientProvider>
|
||||||
</SdkContextProvider>
|
)
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function HydrateFallback() {
|
export function HydrateFallback() {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
"@conform-to/zod": "^1.0.2",
|
"@conform-to/zod": "^1.0.2",
|
||||||
"@fontsource-variable/manrope": "^5.0.19",
|
"@fontsource-variable/manrope": "^5.0.19",
|
||||||
"@radix-ui/react-accordion": "^1.1.2",
|
"@radix-ui/react-accordion": "^1.1.2",
|
||||||
"@lumeweb/portal-sdk": "0.0.0-20240322223747",
|
"@lumeweb/portal-sdk": "0.0.0-20240326154759",
|
||||||
"@radix-ui/react-avatar": "^1.0.4",
|
"@radix-ui/react-avatar": "^1.0.4",
|
||||||
"@radix-ui/react-checkbox": "^1.0.4",
|
"@radix-ui/react-checkbox": "^1.0.4",
|
||||||
"@radix-ui/react-dialog": "^1.0.5",
|
"@radix-ui/react-dialog": "^1.0.5",
|
||||||
|
|
Loading…
Reference in New Issue