-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(upload folder): init wip upload mvp for testing PE-4643
- Loading branch information
Showing
8 changed files
with
734 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { useEffect, useState } from "react"; | ||
import { ErrMsgCallbackAsProps } from "../types"; | ||
import { ardriveAppUrl, turboConfig } from "../constants"; | ||
import { Page } from "./Page"; | ||
import { | ||
TurboAuthenticatedClient, | ||
TurboFactory, | ||
ArconnectSigner, | ||
} from "@ardrive/turbo-sdk/web"; | ||
import { getArconnect } from "../utils/arconnect"; | ||
import { NewToArDriveInfo } from "../components/NewToArDriveInfo"; | ||
|
||
function UploadForm({ errorCallback }: ErrMsgCallbackAsProps) { | ||
const [selectedFiles, setSelectedFiles] = useState<FileList | null>(null); | ||
|
||
const [turbo, setTurbo] = useState<undefined | TurboAuthenticatedClient>( | ||
undefined, | ||
); | ||
const [sending, setSending] = useState<boolean>(false); | ||
|
||
useEffect(() => { | ||
getArconnect().then(async () => { | ||
const arconnect_signer = new ArconnectSigner(window.arweaveWallet); | ||
|
||
const turbo = TurboFactory.authenticated({ | ||
signer: arconnect_signer, | ||
...turboConfig, | ||
}); | ||
setTurbo(turbo); | ||
}); | ||
}, []); | ||
|
||
// TODO: Query params if needed | ||
// const location = useLocation(); | ||
// useEffect(() => { | ||
|
||
// }, [location.search]); | ||
|
||
const canSubmitForm = !!turbo && !!selectedFiles && !sending; | ||
|
||
const handleSubmit = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => { | ||
e.preventDefault(); | ||
|
||
if (!canSubmitForm) { | ||
return; | ||
} | ||
|
||
setSending(true); | ||
turbo | ||
.uploadFolder({ | ||
files: Array.from(selectedFiles), | ||
maxConcurrentUploads: 1, | ||
}) | ||
.catch((err: unknown) => { | ||
console.log("err", err); | ||
errorCallback( | ||
`Error uploading: ${err instanceof Error ? err.message : err}`, | ||
); | ||
}) | ||
.then((res: unknown) => { | ||
console.log("res", res); | ||
setSending(false); | ||
|
||
// TODO: Success Modal or Page | ||
alert("Great Upload!!\n" + JSON.stringify(res)); | ||
}); | ||
}; | ||
|
||
return ( | ||
<> | ||
<h1>Upload a folder or file with your wallet</h1> | ||
<p> | ||
If you do not have an Arweave wallet, you can create one in{" "} | ||
{/* TODO: Create wallet from turbo sdk/app */} | ||
<a href={ardriveAppUrl}>ArDrive App</a>. | ||
</p> | ||
<form className="form"> | ||
<div className="form-section"> | ||
{/* TODO: Current balance of wallet in AR and Turbo Credits */} | ||
|
||
<label className="form-label">Upload</label> | ||
<input | ||
type="file" | ||
multiple | ||
onChange={(e) => setSelectedFiles(e.target.files)} | ||
/> | ||
{/* <input | ||
// webkitdirectory | ||
type="file" | ||
multiple | ||
onChange={(e) => setSelectedFiles(e.target.files)} | ||
/> */} | ||
</div> | ||
|
||
{sending && <p>Now Sending Fund Transaction...</p>} | ||
|
||
{/* TODO: Estimate price */} | ||
<button | ||
type="submit" | ||
className="proceed-button" | ||
onClick={(e) => handleSubmit(e)} | ||
disabled={!canSubmitForm} | ||
> | ||
Send Upload | ||
</button> | ||
</form> | ||
|
||
<NewToArDriveInfo /> | ||
</> | ||
); | ||
} | ||
|
||
export const UploadPage = () => ( | ||
<Page page={(e) => <UploadForm errorCallback={e} />} /> | ||
); |
Oops, something went wrong.