From 27dcca05e01ff6efe8c1963b13d565f59c1d8771 Mon Sep 17 00:00:00 2001 From: blahkheart Date: Sun, 24 Apr 2022 19:37:27 +0100 Subject: [PATCH 1/3] some commit --- .../src/routes/party/components/VoteTable.jsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/react-app/src/routes/party/components/VoteTable.jsx b/packages/react-app/src/routes/party/components/VoteTable.jsx index 7054b3e..5e9c894 100644 --- a/packages/react-app/src/routes/party/components/VoteTable.jsx +++ b/packages/react-app/src/routes/party/components/VoteTable.jsx @@ -37,7 +37,7 @@ import React, { useState, useMemo, useEffect, useRef } from "react"; import { useParams, useHistory } from "react-router-dom"; import AddressChakra from "../../../components/AddressChakra"; import { ethers } from "ethers"; -import { NETWORK, NETWORKS } from "../../../constants"; +import { NETWORK } from "../../../constants"; export const VoteTable = ({ partyData, @@ -132,6 +132,8 @@ export const VoteTable = ({ headers: { "Content-Type": "application/json" }, body: JSON.stringify(note), }); + const testDataX = await noteRes.json(); + console.log("This is ", testDataX.message); // TODO: Find a more efficient approach instead of re-requesting the whole party const partyRes = await fetch(`${process.env.REACT_APP_API_URL}/party/${id}`); const data = await partyRes.json(); @@ -208,6 +210,20 @@ export const VoteTable = ({ } }; + // function testFunc() { + // let c; + // c = partyData.candidates.map( + // d => { + // let varVar = partyData.notes?.filter(n => n.candidate.toLowerCase() === d.toLowerCase()).reverse()[0]?.message; + // console.log("Doing test to..",d); + // console.log("Doing more test to..",varVar); + // return ( + // {varVar} + // ); + // } + // ) + // } + // // testFunc(); const candidates = useMemo( _ => { let c; @@ -230,6 +246,7 @@ export const VoteTable = ({ partyData.notes?.filter(n => n.candidate.toLowerCase() === d.toLowerCase()).reverse()[0] ?.message } + {/* {testFunc} */} {d.toLowerCase() === address.toLowerCase() ? ( From 3b0a3196b043866ae471e76ac948f9b37b373446 Mon Sep 17 00:00:00 2001 From: blahkheart Date: Wed, 27 Apr 2022 00:31:55 +0100 Subject: [PATCH 2/3] Changed 'Remaining Votes' to 'Your Remaining Votes' --- packages/react-app/src/routes/party/Party.jsx | 21 ++++++++++++++ .../src/routes/party/components/VoteTable.jsx | 28 ++++++------------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/packages/react-app/src/routes/party/Party.jsx b/packages/react-app/src/routes/party/Party.jsx index bd94a12..2d5f34d 100644 --- a/packages/react-app/src/routes/party/Party.jsx +++ b/packages/react-app/src/routes/party/Party.jsx @@ -76,6 +76,24 @@ export default function Party({ })(); }, [readContracts]); + // Update UI when other users adds notes + const updateUiNotes = async () => { + try { + // if (!loading) { + const res = await fetch(`${process.env.REACT_APP_API_URL}/party/${id}`); + const party = await res.json(); + const partyNotes = party.notes.length; + const newNoteAdded = partyData.notes.length; + if (partyNotes !== newNoteAdded) { + setPartyData(party); + } + console.log("RUNNING UI UPDATES"); + // } + } catch (error) { + console.log(error); + return null; + } + } // Calculate percent distribution from submitted ballots and memo table const calculateDistribution = () => { try { @@ -142,9 +160,12 @@ export default function Party({ const cachedVoteTable = useMemo(() => { try { + // updateUiNotes(); return ( { - // let varVar = partyData.notes?.filter(n => n.candidate.toLowerCase() === d.toLowerCase()).reverse()[0]?.message; - // console.log("Doing test to..",d); - // console.log("Doing more test to..",varVar); - // return ( - // {varVar} - // ); - // } - // ) - // } - // // testFunc(); const candidates = useMemo( _ => { let c; @@ -388,7 +375,7 @@ export const VoteTable = ({ ) : null}
- Remaining Votes: + Your Remaining Votes:
@@ -399,7 +386,10 @@ export const VoteTable = ({ Address - Note + + Note + } disabled={isRefreshing} onClick={updateUiNotes} /> + Score From d2c310c5fc82a26feab2b21fe76276f7ffb0c668 Mon Sep 17 00:00:00 2001 From: blahkheart Date: Thu, 28 Apr 2022 05:17:09 +0100 Subject: [PATCH 3/3] added notes refresh button to VoteTable component and added a function that refreshes the notes whenever a user updates their note --- packages/react-app/src/routes/party/Party.jsx | 21 ++++++++---------- .../src/routes/party/components/VoteTable.jsx | 22 ++++++++++++++++--- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/packages/react-app/src/routes/party/Party.jsx b/packages/react-app/src/routes/party/Party.jsx index 2d5f34d..1b3206c 100644 --- a/packages/react-app/src/routes/party/Party.jsx +++ b/packages/react-app/src/routes/party/Party.jsx @@ -79,21 +79,20 @@ export default function Party({ // Update UI when other users adds notes const updateUiNotes = async () => { try { - // if (!loading) { - const res = await fetch(`${process.env.REACT_APP_API_URL}/party/${id}`); - const party = await res.json(); - const partyNotes = party.notes.length; - const newNoteAdded = partyData.notes.length; - if (partyNotes !== newNoteAdded) { - setPartyData(party); - } - console.log("RUNNING UI UPDATES"); - // } + const res = await fetch(`${process.env.REACT_APP_API_URL}/party/${id}`); + const party = await res.json(); + const partyNotes = party.notes.length; + const newNoteAdded = partyData.notes.length; + if (partyNotes !== newNoteAdded) { + setPartyData(party); + } + console.log("UPDATING NOTES"); } catch (error) { console.log(error); return null; } } + // Calculate percent distribution from submitted ballots and memo table const calculateDistribution = () => { try { @@ -160,12 +159,10 @@ export default function Party({ const cachedVoteTable = useMemo(() => { try { - // updateUiNotes(); return ( - @@ -388,7 +389,22 @@ export const VoteTable = ({ Address Note - } disabled={isRefreshing} onClick={updateUiNotes} /> + + } + onClick={() => { + setIsNoteRefreshing(true), + updateUiNotes(), + setTimeout(() => { + setIsNoteRefreshing(false) + }, 2000); + }} + /> + Score