Skip to content

Commit

Permalink
Merge pull request #191 from blahkheart/develop
Browse files Browse the repository at this point in the history
Other party members notes do not update without refresh: issue #179
  • Loading branch information
hmrtn authored Apr 29, 2022
2 parents a9367ca + 45a23ba commit 3ec33cd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
18 changes: 18 additions & 0 deletions packages/react-app/src/routes/party/Party.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,23 @@ export default function Party({
})();
}, [readContracts, distributed]);

// Update UI when other users adds notes
const updateUiNotes = async () => {
try {
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 {
Expand Down Expand Up @@ -147,6 +164,7 @@ export default function Party({
return (
<VoteTable
partyData={partyData}
updateUiNotes={updateUiNotes}
setPartyData={setPartyData}
address={address}
userSigner={userSigner}
Expand Down
32 changes: 28 additions & 4 deletions packages/react-app/src/routes/party/components/VoteTable.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
Box,
Button,
IconButton,
Tooltip,
Text,
Textarea,
NumberInput,
Expand All @@ -18,6 +20,7 @@ import {
Td,
TableCaption,
} from "@chakra-ui/react";
import { RepeatIcon } from "@chakra-ui/icons";
import {
useDisclosure,
Modal,
Expand All @@ -40,8 +43,10 @@ import AddressChakra from "../../../components/AddressChakra";
import { ethers } from "ethers";
import { NETWORK, NETWORKS } from "../../../constants";


export const VoteTable = ({
partyData,
updateUiNotes,
setPartyData,
address,
userSigner,
Expand All @@ -54,6 +59,7 @@ export const VoteTable = ({
const [votesData, setVotesData] = useState(null);
// Init votes left to nvotes
const [votesLeft, setVotesLeft] = useState(null);
const [isNoteRefreshing, setIsNoteRefreshing] = useState(false);
const [candidateNote, setCandidateNote] = useState("");
const [noteChars, setNoteChars] = useState(0);
const [noteIsLoading, setNoteIsLoading] = useState(false);
Expand Down Expand Up @@ -215,7 +221,6 @@ export const VoteTable = ({
console.log("Error: Failed to cast ballot!");
}
};

const candidates = useMemo(
_ => {
let c;
Expand All @@ -238,6 +243,7 @@ export const VoteTable = ({
partyData.notes?.filter(n => n.candidate.toLowerCase() === d.toLowerCase()).reverse()[0]
?.message
}
{/* {testFunc} */}
</Text>
</Box>
{d.toLowerCase() === address.toLowerCase() ? (
Expand Down Expand Up @@ -308,7 +314,7 @@ export const VoteTable = ({
</FormControl>
</ModalBody>
<ModalFooter>
<Button mr={3} onClick={newCandidateNote} isLoading={noteIsLoading} isDisabled={noteChars > 256}>
<Button mr={3} onClick={()=> {newCandidateNote(), updateUiNotes()}} isLoading={noteIsLoading} isDisabled={noteChars > 256}>
Submit
</Button>
<Button onClick={onClose}>Cancel</Button>
Expand Down Expand Up @@ -371,7 +377,7 @@ export const VoteTable = ({
</Center>
) : null}
<Center pt={4}>
<Text fontSize="lg">Remaining Votes:</Text>
<Text fontSize="lg">Your Remaining Votes:</Text>
</Center>
<Center pb="3">
<Text fontWeight="semibold" fontSize="lg">
Expand All @@ -382,7 +388,25 @@ export const VoteTable = ({
<Thead>
<Tr>
<Th>Address</Th>
<Th>Note</Th>
<Th>
Note
<Tooltip label="Refresh notes" fontSize="xs">
<IconButton
isLoading={isNoteRefreshing}
ml={3}
size={"xs"}
variant={"outline"}
icon={<RepeatIcon />}
onClick={() => {
setIsNoteRefreshing(true),
updateUiNotes(),
setTimeout(() => {
setIsNoteRefreshing(false)
}, 2000);
}}
/>
</Tooltip>
</Th>
<Th>Score</Th>
</Tr>
</Thead>
Expand Down

1 comment on commit 3ec33cd

@vercel
Copy link

@vercel vercel bot commented on 3ec33cd May 2, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.