Skip to content

Commit

Permalink
did passed in as parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobHomanics committed Apr 30, 2024
1 parent 2db0e3f commit 2f6ce31
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 3 deletions.
9 changes: 7 additions & 2 deletions packages/nextjs/app/nft-storage/_components/SpaceEnsurer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import React, { ReactNode, useEffect } from "react";
import { Loader } from "./Loader";
import { useW3 } from "@w3ui/react";

export function SpaceEnsurer({ children }: { children: ReactNode }): ReactNode {
export function SpaceEnsurer({ did, children }: { did: `did:${string}:${string}`; children: ReactNode }): ReactNode {
const [{ client }] = useW3();
useEffect(
function () {
async function ensureCurrentSpace(): Promise<void> {
if (client != null && client.currentSpace() == null) {
await client?.setCurrentSpace(`did:key:z6MkhCcXJFhNaNTcjQ1ZVRdccBH61PBuUb1AZ1xK4GgyeGPe`);
await client?.setCurrentSpace(did);

// const space = await client?.createSpace("An example space");
// await client.setCurrentSpace(space.did());

// await client?.setCurrentSpace(did);
// const space = client.spaces().length > 0 ? client.spaces()[0] : await client.createSpace("example space");
// if (space != null) {
// await client.setCurrentSpace(space.did());
Expand Down
73 changes: 73 additions & 0 deletions packages/nextjs/app/nft-storage/_components/SpaceEnsurerCopy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// import React, { ReactNode, useEffect, useState } from "react";
// import { Loader } from "./Loader";
// import { useW3 } from "@w3ui/react";
// import { v4 as uuidv4 } from "uuid";

// export function SpaceEnsurerCopy({
// did,
// children,
// }: {
// did: `did:${string}:${string}`;
// children: ReactNode;
// }): ReactNode {
// const [selectedDid, setSelectedDid] = useState<`did:${string}:${string}`>();

// const [{ client }] = useW3();
// useEffect(
// function () {
// async function ensureCurrentSpace(): Promise<void> {
// if (client != null && client.currentSpace() == null) {
// if (did) await client?.setCurrentSpace(did);
// // const space = client.spaces().length > 0 ? client.spaces()[0] : await client.createSpace("example space");
// // if (space != null) {
// // await client.setCurrentSpace(space.did());
// // }
// }
// }
// void ensureCurrentSpace();
// },
// [client],
// );

// let output;

// if (client != null) {
// if (client.currentSpace() == null) {
// // output = (
// // <>
// // <input
// // type="text"
// // id="first_name"
// // className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
// // placeholder="Scaffold NFT"
// // required
// // onChange={(event: any) => {
// // // onChange(event.target.value);
// // }}
// // />{" "}
// // <button
// // type="submit"
// // onClick={async () => {
// // console.log(client.currentSpace());
// // if (client.currentSpace() === undefined) {
// // const newSpace = await client?.createSpace(uuidv4());
// // console.log(newSpace);
// // await client.setCurrentSpace(newSpace.did());
// // console.log(newSpace);
// // }
// // }}
// // className="btn btn-primary m-1"
// // >
// // Upload
// // </button>
// // </>
// // );
// } else {
// output = children;
// }
// } else {
// output = <Loader />;
// }

// return output;
// }
2 changes: 1 addition & 1 deletion packages/nextjs/app/nft-storage/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const NftStoragePage: NextPage = () => {
<Authenticator>
<AuthenticationEnsurer>
<Identity />
<SpaceEnsurer>
<SpaceEnsurer did="did:key:z6MkhCcXJFhNaNTcjQ1ZVRdccBH61PBuUb1AZ1xK4GgyeGPe">
<MyUploader />
</SpaceEnsurer>
</AuthenticationEnsurer>
Expand Down

0 comments on commit 2f6ce31

Please sign in to comment.