Skip to content

Commit

Permalink
some ui/ux updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Bichler committed Jan 24, 2023
1 parent ab190a3 commit a07ef01
Show file tree
Hide file tree
Showing 27 changed files with 728 additions and 1,172 deletions.
6 changes: 6 additions & 0 deletions additional.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare global {
interface Window {
ethereum?: import("ethers").providers.ExternalProvider;
}
}
export {};
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@
"@web3auth/base": "^4.0.0",
"@web3auth/modal": "^4.2.3",
"@web3auth/openlogin-adapter": "^4.2.0",
"boring-avatars": "^1.7.0",
"eslint": "8.32.0",
"eslint-config-next": "13.1.4",
"ethers": "^5.7.2",
"next": "13.1.4",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hook-form": "^7.42.1",
"tailwind-merge": "^1.8.1",
"typescript": "4.9.4"
},
"devDependencies": {
"@tailwindcss/aspect-ratio": "^0.4.2",
"@tailwindcss/forms": "^0.5.3",
"@types/elliptic": "^6.4.14",
"autoprefixer": "^10.4.13",
Expand Down
22 changes: 22 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added public/favicon/android-chrome-72x72.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/favicon/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions public/favicon/browserconfig.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
<msapplication>
<tile>
<square150x150logo src="/mstile-150x150.png"/>
<TileColor>#da532c</TileColor>
</tile>
</msapplication>
</browserconfig>
Binary file added public/favicon/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/favicon/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/favicon/favicon.ico
Binary file not shown.
Binary file added public/favicon/mstile-150x150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions public/favicon/safari-pinned-tab.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions public/favicon/site.webmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "",
"short_name": "",
"icons": [
{
"src": "/android-chrome-72x72.png",
"sizes": "72x72",
"type": "image/png"
}
],
"theme_color": "#ffffff",
"background_color": "#ffffff",
"display": "standalone"
}
Binary file added public/labio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions src/components/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { classNames } from "@/utils/classNames";
import * as React from "react";
import { twMerge } from "tailwind-merge";

const variants = {
primary: "bg-indigo-600 text-white hover:bg-indigo-700 ",
white: "border border-gray-300 hover:bg-gray-50 text-gray-700",
};

const sizes = {
md: "py-2 px-4 text-sm",
lg: "py-2 px-4 text-base",
xl: "py-3 px-6 text-base",
};

type ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {
variant?: keyof typeof variants;
size?: keyof typeof sizes;
isLoading?: boolean;
};

export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
(
{
type = "button",
className = "",
variant = "primary",
size = "md",
isLoading = false,
...props
},
ref
) => {
const clNames = classNames(
"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",
variants[variant],
sizes[size]
);
const mergedClassNames = twMerge(clNames, className);
return (
<button ref={ref} type={type} className={mergedClassNames} {...props}>
{/* {isLoading && <Spinner size="sm" className="text-current" />} */}
<span className="mx-2">{props.children}</span>
</button>
);
}
);

Button.displayName = "Button";
111 changes: 79 additions & 32 deletions src/components/dashboard/forms/addPaperForm.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,66 @@
import { Button } from "@/components/button";
import lighthouse from "@lighthouse-web3/sdk";
import { ethers } from "ethers";
import { useState } from "react";
import { useForm } from "react-hook-form";

export function AddPaperForm() {
const [paperFile, setPaperFile] = useState(null);
const [data, setData] = useState(null);
const [encrypted, setEncrypted] = useState(false);

const { register, handleSubmit } = useForm();

const onSubmit = async (data) => {
if (!paperFile) throw Error("No file selected");
const fileUrl = await deployImage();
console.log("fileUrl :>> ", fileUrl);
console.log("data :>> ", data);
const encryptionSignature = async () => {
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
const address = await signer.getAddress();
const messageRequested = (await lighthouse.getAuthMessage(address)).data
.message;
const signedMessage = await signer.signMessage(messageRequested);
return {
signedMessage: signedMessage,
publicKey: address,
};
};

const onChangePaperFile = (e) => {
setPaperFile(URL.createObjectURL(e.target.files[0]));
//percentage of upload data done
const progressCallback = (progressData) => {
const total = progressData?.total;
const uploaded = progressData?.uploaded;
const percentageToBeDone = parseInt((total / uploaded).toFixed(2));
let percentageDone = 100 - percentageToBeDone;
console.log("percentageDone", percentageDone);
};

const deployImage = async () => {
const progressCallback = (progressData) => {
const total = progressData?.total;
const uploaded = progressData?.uploaded;
const percentageToBeDone = parseInt((total / uploaded).toFixed(2));
let percentageDone = 100 - percentageToBeDone;
console.log("percentageDone", percentageDone);
};
const onSubmit = async (data) => {
if (!data) throw Error("No file selected");
const fileUrl = await uploadData();
console.log("fileUrl :>> ", fileUrl);
};

const output = await lighthouse.upload(
paperFile,
const uploadData = async () => {
// upload encrypted file to IPFS and return the url
if (encrypted) {
const sig = await encryptionSignature();
const response = await lighthouse.uploadEncrypted(
data,
sig.publicKey,
process.env.NEXT_PUBLIC_LIGHTHOUSE_API_KEY,
sig.signedMessage,
progressCallback
);
const url = `https://gateway.lighthouse.storage/ipfs/${response.data.Hash}`;
console.log("Encrypted FileUrl: ", url);
return url;
}
// upload unencrypted file to IPFS and return the url
const response = await lighthouse.upload(
data,
process.env.NEXT_PUBLIC_LIGHTHOUSE_API_KEY,
progressCallback
);
console.log("File Status:", output);
const url = `Visit at https://gateway.lighthouse.storage/ipfs/${output.data.Hash}`;
const url = `Vhttps://gateway.lighthouse.storage/ipfs/${response.data.Hash}`;
console.log("File URL: ", url);
return url;
};

Expand All @@ -44,7 +71,7 @@ export function AddPaperForm() {
// Display response
console.log("ACCESSCON:", response);
};

console.log("encrypted :>>", encrypted);
return (
<div className="px-4 pt-8 mx-auto max-w-7xl sm:px-6 lg:px-8">
<div className="flex flex-col">
Expand Down Expand Up @@ -104,7 +131,33 @@ export function AddPaperForm() {
/>
</div>
</div>
<div className="sm:col-span-4">
<div className="flex items-start h-">
<input
id="encrypt"
aria-describedby="encrypt-description"
name="encrypt"
type="checkbox"
onChange={() => setEncrypted(!encrypted)}
className="w-4 h-4 mt-[0.5px] text-indigo-600 border-gray-300 rounded focus:ring-indigo-500"
/>

<div className="ml-3 text-sm">
<label
htmlFor="encrypt"
className="font-medium text-gray-700"
>
Encrypt data
</label>
<p id="encrypt-description" className="text-gray-500">
The data will be encrypted before being stored on the
IPFS public network. Meaning it can only be accessed by
the persons who have the key to decrypt the data once
downloaded.
</p>
</div>
</div>
</div>
<div className="sm:col-span-6">
<label
htmlFor="cover-photo"
Expand Down Expand Up @@ -138,7 +191,7 @@ export function AddPaperForm() {
id="file-upload"
name="file-upload"
type="file"
onChange={(e) => setPaperFile(e)}
onChange={(e) => setData(e)}
className="sr-only"
/>
</label>
Expand All @@ -154,18 +207,12 @@ export function AddPaperForm() {

<div className="pt-5">
<div className="flex justify-end">
<button
type="button"
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"
>
<Button type="button" variant="white">
Clear form
</button>
<button
type="submit"
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"
>
</Button>
<Button type="submit" className="inline-flex justify-center ml-3">
Save Paper
</button>
</Button>
</div>
</div>
</form>
Expand Down
Loading

1 comment on commit a07ef01

@vercel
Copy link

@vercel vercel bot commented on a07ef01 Jan 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

labio – ./

labio.vercel.app
labio-mani.vercel.app
labio-git-main-mani.vercel.app

Please sign in to comment.