Skip to content

Commit a07ef01

Browse files
author
Manuel Bichler
committed
some ui/ux updates
1 parent ab190a3 commit a07ef01

27 files changed

+728
-1172
lines changed

additional.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
declare global {
2+
interface Window {
3+
ethereum?: import("ethers").providers.ExternalProvider;
4+
}
5+
}
6+
export {};

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,19 @@
2020
"@web3auth/base": "^4.0.0",
2121
"@web3auth/modal": "^4.2.3",
2222
"@web3auth/openlogin-adapter": "^4.2.0",
23+
"boring-avatars": "^1.7.0",
2324
"eslint": "8.32.0",
2425
"eslint-config-next": "13.1.4",
2526
"ethers": "^5.7.2",
2627
"next": "13.1.4",
2728
"react": "18.2.0",
2829
"react-dom": "18.2.0",
2930
"react-hook-form": "^7.42.1",
31+
"tailwind-merge": "^1.8.1",
3032
"typescript": "4.9.4"
3133
},
3234
"devDependencies": {
35+
"@tailwindcss/aspect-ratio": "^0.4.2",
3336
"@tailwindcss/forms": "^0.5.3",
3437
"@types/elliptic": "^6.4.14",
3538
"autoprefixer": "^10.4.13",

pnpm-lock.yaml

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
3.79 KB
Loading

public/favicon/apple-touch-icon.png

3.99 KB
Loading

public/favicon/browserconfig.xml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<browserconfig>
3+
<msapplication>
4+
<tile>
5+
<square150x150logo src="/mstile-150x150.png"/>
6+
<TileColor>#da532c</TileColor>
7+
</tile>
8+
</msapplication>
9+
</browserconfig>

public/favicon/favicon-16x16.png

1.04 KB
Loading

public/favicon/favicon-32x32.png

1.58 KB
Loading

public/favicon/favicon.ico

14.7 KB
Binary file not shown.

public/favicon/mstile-150x150.png

1.57 KB
Loading

public/favicon/safari-pinned-tab.svg

+19
Loading

public/favicon/site.webmanifest

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "",
3+
"short_name": "",
4+
"icons": [
5+
{
6+
"src": "/android-chrome-72x72.png",
7+
"sizes": "72x72",
8+
"type": "image/png"
9+
}
10+
],
11+
"theme_color": "#ffffff",
12+
"background_color": "#ffffff",
13+
"display": "standalone"
14+
}

public/labio.png

3.51 KB
Loading

src/components/button.tsx

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { classNames } from "@/utils/classNames";
2+
import * as React from "react";
3+
import { twMerge } from "tailwind-merge";
4+
5+
const variants = {
6+
primary: "bg-indigo-600 text-white hover:bg-indigo-700 ",
7+
white: "border border-gray-300 hover:bg-gray-50 text-gray-700",
8+
};
9+
10+
const sizes = {
11+
md: "py-2 px-4 text-sm",
12+
lg: "py-2 px-4 text-base",
13+
xl: "py-3 px-6 text-base",
14+
};
15+
16+
type ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {
17+
variant?: keyof typeof variants;
18+
size?: keyof typeof sizes;
19+
isLoading?: boolean;
20+
};
21+
22+
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
23+
(
24+
{
25+
type = "button",
26+
className = "",
27+
variant = "primary",
28+
size = "md",
29+
isLoading = false,
30+
...props
31+
},
32+
ref
33+
) => {
34+
const clNames = classNames(
35+
"flex justify-center items-center disabled:opacity-70 disabled:cursor-not-allowed rounded-md shadow-sm font-medium focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2",
36+
variants[variant],
37+
sizes[size]
38+
);
39+
const mergedClassNames = twMerge(clNames, className);
40+
return (
41+
<button ref={ref} type={type} className={mergedClassNames} {...props}>
42+
{/* {isLoading && <Spinner size="sm" className="text-current" />} */}
43+
<span className="mx-2">{props.children}</span>
44+
</button>
45+
);
46+
}
47+
);
48+
49+
Button.displayName = "Button";

src/components/dashboard/forms/addPaperForm.tsx

+79-32
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,66 @@
1+
import { Button } from "@/components/button";
12
import lighthouse from "@lighthouse-web3/sdk";
3+
import { ethers } from "ethers";
24
import { useState } from "react";
35
import { useForm } from "react-hook-form";
46

57
export function AddPaperForm() {
6-
const [paperFile, setPaperFile] = useState(null);
8+
const [data, setData] = useState(null);
9+
const [encrypted, setEncrypted] = useState(false);
710

811
const { register, handleSubmit } = useForm();
912

10-
const onSubmit = async (data) => {
11-
if (!paperFile) throw Error("No file selected");
12-
const fileUrl = await deployImage();
13-
console.log("fileUrl :>> ", fileUrl);
14-
console.log("data :>> ", data);
13+
const encryptionSignature = async () => {
14+
const provider = new ethers.providers.Web3Provider(window.ethereum);
15+
const signer = provider.getSigner();
16+
const address = await signer.getAddress();
17+
const messageRequested = (await lighthouse.getAuthMessage(address)).data
18+
.message;
19+
const signedMessage = await signer.signMessage(messageRequested);
20+
return {
21+
signedMessage: signedMessage,
22+
publicKey: address,
23+
};
1524
};
1625

17-
const onChangePaperFile = (e) => {
18-
setPaperFile(URL.createObjectURL(e.target.files[0]));
26+
//percentage of upload data done
27+
const progressCallback = (progressData) => {
28+
const total = progressData?.total;
29+
const uploaded = progressData?.uploaded;
30+
const percentageToBeDone = parseInt((total / uploaded).toFixed(2));
31+
let percentageDone = 100 - percentageToBeDone;
32+
console.log("percentageDone", percentageDone);
1933
};
2034

21-
const deployImage = async () => {
22-
const progressCallback = (progressData) => {
23-
const total = progressData?.total;
24-
const uploaded = progressData?.uploaded;
25-
const percentageToBeDone = parseInt((total / uploaded).toFixed(2));
26-
let percentageDone = 100 - percentageToBeDone;
27-
console.log("percentageDone", percentageDone);
28-
};
35+
const onSubmit = async (data) => {
36+
if (!data) throw Error("No file selected");
37+
const fileUrl = await uploadData();
38+
console.log("fileUrl :>> ", fileUrl);
39+
};
2940

30-
const output = await lighthouse.upload(
31-
paperFile,
41+
const uploadData = async () => {
42+
// upload encrypted file to IPFS and return the url
43+
if (encrypted) {
44+
const sig = await encryptionSignature();
45+
const response = await lighthouse.uploadEncrypted(
46+
data,
47+
sig.publicKey,
48+
process.env.NEXT_PUBLIC_LIGHTHOUSE_API_KEY,
49+
sig.signedMessage,
50+
progressCallback
51+
);
52+
const url = `https://gateway.lighthouse.storage/ipfs/${response.data.Hash}`;
53+
console.log("Encrypted FileUrl: ", url);
54+
return url;
55+
}
56+
// upload unencrypted file to IPFS and return the url
57+
const response = await lighthouse.upload(
58+
data,
3259
process.env.NEXT_PUBLIC_LIGHTHOUSE_API_KEY,
3360
progressCallback
3461
);
35-
console.log("File Status:", output);
36-
const url = `Visit at https://gateway.lighthouse.storage/ipfs/${output.data.Hash}`;
62+
const url = `Vhttps://gateway.lighthouse.storage/ipfs/${response.data.Hash}`;
63+
console.log("File URL: ", url);
3764
return url;
3865
};
3966

@@ -44,7 +71,7 @@ export function AddPaperForm() {
4471
// Display response
4572
console.log("ACCESSCON:", response);
4673
};
47-
74+
console.log("encrypted :>>", encrypted);
4875
return (
4976
<div className="px-4 pt-8 mx-auto max-w-7xl sm:px-6 lg:px-8">
5077
<div className="flex flex-col">
@@ -104,7 +131,33 @@ export function AddPaperForm() {
104131
/>
105132
</div>
106133
</div>
134+
<div className="sm:col-span-4">
135+
<div className="flex items-start h-">
136+
<input
137+
id="encrypt"
138+
aria-describedby="encrypt-description"
139+
name="encrypt"
140+
type="checkbox"
141+
onChange={() => setEncrypted(!encrypted)}
142+
className="w-4 h-4 mt-[0.5px] text-indigo-600 border-gray-300 rounded focus:ring-indigo-500"
143+
/>
107144

145+
<div className="ml-3 text-sm">
146+
<label
147+
htmlFor="encrypt"
148+
className="font-medium text-gray-700"
149+
>
150+
Encrypt data
151+
</label>
152+
<p id="encrypt-description" className="text-gray-500">
153+
The data will be encrypted before being stored on the
154+
IPFS public network. Meaning it can only be accessed by
155+
the persons who have the key to decrypt the data once
156+
downloaded.
157+
</p>
158+
</div>
159+
</div>
160+
</div>
108161
<div className="sm:col-span-6">
109162
<label
110163
htmlFor="cover-photo"
@@ -138,7 +191,7 @@ export function AddPaperForm() {
138191
id="file-upload"
139192
name="file-upload"
140193
type="file"
141-
onChange={(e) => setPaperFile(e)}
194+
onChange={(e) => setData(e)}
142195
className="sr-only"
143196
/>
144197
</label>
@@ -154,18 +207,12 @@ export function AddPaperForm() {
154207

155208
<div className="pt-5">
156209
<div className="flex justify-end">
157-
<button
158-
type="button"
159-
className="px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-md shadow-sm hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2"
160-
>
210+
<Button type="button" variant="white">
161211
Clear form
162-
</button>
163-
<button
164-
type="submit"
165-
className="inline-flex justify-center px-4 py-2 ml-3 text-sm font-medium text-white bg-indigo-600 border border-transparent rounded-md shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2"
166-
>
212+
</Button>
213+
<Button type="submit" className="inline-flex justify-center ml-3">
167214
Save Paper
168-
</button>
215+
</Button>
169216
</div>
170217
</div>
171218
</form>

0 commit comments

Comments
 (0)