ghost-portal/packages/page-society/src/Overview/Votes.tsx
2022-01-01 09:30:15 +02:00

46 lines
1.2 KiB
TypeScript

// Copyright 2017-2022 @polkadot/app-society authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { VoteSplit, VoteType } from '../types';
import React, { useEffect, useState } from 'react';
import { useTranslation } from '../translate';
import VotesExpander from './VotesExpander';
interface Props {
votes?: VoteType[];
}
function Votes ({ votes }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const [{ allAye, allNay, allSkeptic }, setVoteSplit] = useState<VoteSplit>({ allAye: [], allNay: [], allSkeptic: [] });
useEffect((): void => {
votes && setVoteSplit({
allAye: votes.filter(([, vote]) => vote.isApprove),
allNay: votes.filter(([, vote]) => vote.isReject),
allSkeptic: votes.filter(([, vote]) => vote.isSkeptic)
});
}, [votes]);
return (
<td className='expand'>
<VotesExpander
label={t<string>('Skeptics')}
votes={allSkeptic}
/>
<VotesExpander
label={t<string>('Approvals')}
votes={allAye}
/>
<VotesExpander
label={t<string>('Rejections')}
votes={allNay}
/>
</td>
);
}
export default React.memo(Votes);