Skip to content

Commit 5bc1e2f

Browse files
committed
connect dashboard to cloud
1 parent 82fd75a commit 5bc1e2f

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

dashboard/src/pages/cloud/tenants/ledgers/documents.tsx

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import React from "react";
1+
import React, { useContext } from "react";
22
// import { rawConnect } from "@fireproof/cloud";
33
import { Link, useNavigate, useParams } from "react-router-dom";
4-
import { useFireproof } from "use-fireproof";
4+
import { toCloud, useFireproof } from "use-fireproof";
5+
import { AppContext } from "../../../../app-context.jsx";
56
import { Button } from "../../../../components/Button.jsx";
67
import { DynamicTable } from "../../../../components/DynamicTable.jsx";
78
import { headersForDocs } from "../../../../components/dynamicTableHelpers.js";
9+
import { SimpleTokenStrategy } from "../../../../../../core/gateways/cloud/to-cloud.js";
810
// import { DEFAULT_ENDPOINT } from "../../../../helpers.js";
911

1012
interface Document {
@@ -14,14 +16,33 @@ interface Document {
1416

1517
export function LedgerDocuments() {
1618
const { tenantId, ledgerId } = useParams();
17-
// const { cloud } = useContext(AppContext);
19+
const { cloud } = useContext(AppContext);
20+
const cloudToken = cloud.getCloudToken();
21+
22+
// Wait for token before rendering the main component
23+
if (cloudToken.isPending) {
24+
return <div>Loading...</div>;
25+
}
26+
if (!cloudToken.data) {
27+
return <div>Not found</div>;
28+
}
29+
30+
return <LedgerDocumentsContent tenantId={tenantId} ledgerId={ledgerId} token={cloudToken.data.token} />;
31+
}
32+
33+
function LedgerDocumentsContent({ tenantId, ledgerId, token }: { tenantId?: string; ledgerId?: string; token: string }) {
1834
const navigate = useNavigate();
1935

20-
const { useLiveQuery, database } = useFireproof(ledgerId || "");
21-
// Connect to Fireproof Cloud
22-
// if (database && ledgerId && tenantId) {
23-
// rawConnect(database as any, `${tenantId}-${ledgerId}`, DEFAULT_ENDPOINT);
24-
// }
36+
const { useLiveQuery, database, attach } = useFireproof(ledgerId || "", {
37+
attach: toCloud({
38+
urls: { base: "fpcloud://localhost:8787?protocol=ws" },
39+
tenant: tenantId,
40+
ledger: ledgerId,
41+
strategy: new SimpleTokenStrategy(token),
42+
}),
43+
});
44+
45+
console.log(attach.ctx);
2546

2647
const allDocs = useLiveQuery<Document>("_id");
2748
const docs = allDocs.docs.filter((doc) => !!doc);

0 commit comments

Comments
 (0)