Skip to content

Commit

Permalink
feat: add submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasgrusz committed Jun 2, 2024
1 parent 35a89d2 commit 9120f48
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 586 deletions.
32 changes: 30 additions & 2 deletions packages/nextjs/app/_components/BountyInfo/BountyInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import styles from "./BountyInfo.module.scss";
import { IoIosDownload, IoIosLock } from "react-icons/io";
import { IoCheckmarkCircleOutline, IoCloudUpload } from "react-icons/io5";
import { useAccount } from "wagmi";
import useBounties from "~~/hooks/useBounties";
import { Bounty } from "~~/types/bounty";

export type BountyInfoProps = Bounty & {
id: number;
progress: number;
close: () => void;
};

const BountyInfo: React.FC<BountyInfoProps> = ({
Expand All @@ -18,16 +21,36 @@ const BountyInfo: React.FC<BountyInfoProps> = ({
progress,
maxProgress,
submissions,
id,
close,
}) => {
const [file, setFile] = useState<File | null>(null);
const uploadFile = (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
if (file) {
console.log(file);
setFile(file);
}
};

const { approve, submitEEGData } = useBounties();

const handleSubmit = async () => {
if (file) {
await approve().then(async () => {
const result = await submitEEGData(id, file);
if (result) {
alert("Submission successful");
close();
} else {
alert("Submission failed");
close();
}
});
} else {
alert("Please select a file to submit");
}
};

const account = useAccount();
const joined = submissions.some(submission => submission.submitter.toLowerCase() === account.address?.toLowerCase());
const finished = progress >= maxProgress;
Expand Down Expand Up @@ -91,7 +114,12 @@ const BountyInfo: React.FC<BountyInfoProps> = ({
)}
{file && <p className="m-auto mt-4">{file.name}</p>}
{file && (
<button className={`w-[100%] bg-green-400 rounded pb-2 pt-2 ${styles.button} text-center`}>Submit</button>
<button
className={`w-[100%] bg-green-400 rounded pb-2 pt-2 ${styles.button} text-center`}
onClick={handleSubmit}
>
Submit
</button>
)}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/app/_components/BountyList/BountyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const BountyList = () => {
{selectedId !== null && (
<motion.div layoutId={selectedId}>
<Backdrop onClick={() => setSelectedId(null)}>
<BountyInfo {...bounties[selectedId]} />
<BountyInfo {...bounties[selectedId]} id={selectedId} close={() => setSelectedId(null)} />
</Backdrop>
</motion.div>
)}
Expand Down
Loading

0 comments on commit 9120f48

Please sign in to comment.