diff --git a/packages/DApp/src/components/votes/VotingCards.tsx b/packages/DApp/src/components/votes/VotingCards.tsx index 412cad6..bffff54 100644 --- a/packages/DApp/src/components/votes/VotingCards.tsx +++ b/packages/DApp/src/components/votes/VotingCards.tsx @@ -16,7 +16,7 @@ export function VotingCards() { const [sortedBy, setSortedBy] = useState(VotingSortingEnum.EndingSoonest) const [voteType, setVoteType] = useState('') const [filterKeyword, setFilterKeyword] = useState('') - const roomsToShow = useVotingCommunities(filterKeyword, voteType, sortedBy) + const { roomsToShow, empty } = useVotingCommunities(filterKeyword, voteType, sortedBy) return (
@@ -53,7 +53,8 @@ export function VotingCards() { return } })} - {roomsToShow.length === 0 && } + {roomsToShow.length === 0 && empty && } + {roomsToShow.length === 0 && !empty &&
Community not found
}
) } diff --git a/packages/DApp/src/hooks/useVotingCommunities.ts b/packages/DApp/src/hooks/useVotingCommunities.ts index fac2502..a31cc93 100644 --- a/packages/DApp/src/hooks/useVotingCommunities.ts +++ b/packages/DApp/src/hooks/useVotingCommunities.ts @@ -10,10 +10,10 @@ export function useVotingCommunities( filterKeyword: string, voteType: string, sortedBy: VotingSortingEnum -): DetailedVotingRoom[] { +): { roomsToShow: DetailedVotingRoom[]; empty: boolean } { const [roomsWithCommunity, setRoomsWithCommunity] = useState([]) const [filteredRooms, setFilteredRooms] = useState([]) - + const [empty, setEmpty] = useState(false) const { votingContract } = useContracts() const [roomList] = useContractCall({ abi: votingContract.interface, @@ -22,6 +22,15 @@ export function useVotingCommunities( args: [], }) ?? [[]] + useEffect(() => { + if (roomList.length === 0 && empty == false) { + setEmpty(true) + } + if (roomList.length > 0 && empty == true) { + setEmpty(false) + } + }, [JSON.stringify(roomList)]) + const contractCalls = roomList.map((el: any) => { return { abi: votingContract.interface, @@ -57,5 +66,5 @@ export function useVotingCommunities( setFilteredRooms(filteredRooms.sort(sortVotingFunction(sortedBy))) }, [roomsWithCommunity, filterKeyword, voteType, sortedBy]) - return filteredRooms + return { roomsToShow: filteredRooms, empty } }