|
@ -1,5 +1,7 @@ |
|
|
import React, { useEffect, useMemo, useState } from 'react'; |
|
|
import React, { useEffect, useMemo, useState } from 'react'; |
|
|
import { Grid, Statistic, Tab } from 'semantic-ui-react'; |
|
|
import { |
|
|
|
|
|
Grid, Header, Statistic, Tab, |
|
|
|
|
|
} from 'semantic-ui-react'; |
|
|
import PropTypes from 'prop-types'; |
|
|
import PropTypes from 'prop-types'; |
|
|
import { useTranslation } from 'react-i18next'; |
|
|
import { useTranslation } from 'react-i18next'; |
|
|
import PollChartBar from './PollChartBar'; |
|
|
import PollChartBar from './PollChartBar'; |
|
@ -38,23 +40,32 @@ const PollGraph = (props) => { |
|
|
), [pollOptions, t, totalVotes, userVoteIndex]); |
|
|
), [pollOptions, t, totalVotes, userVoteIndex]); |
|
|
|
|
|
|
|
|
const panes = useMemo(() => { |
|
|
const panes = useMemo(() => { |
|
|
|
|
|
// TODO: tidy up duplicated code below using CHART_TYPE_BAR and CHART_TYPE_DONUT |
|
|
const chartBarPane = ( |
|
|
const chartBarPane = ( |
|
|
<Tab.Pane attached={false}> |
|
|
<Tab.Pane attached={false}> |
|
|
<Grid columns="equal"> |
|
|
<Grid columns="equal"> |
|
|
<Grid.Row> |
|
|
<Grid.Row> |
|
|
<Grid.Column /> |
|
|
<Grid.Column /> |
|
|
<Grid.Column width={8}> |
|
|
<Grid.Column width={8} textAlign="center"> |
|
|
<PollChartBar |
|
|
{totalVotes > 0 |
|
|
pollOptions={pollOptions} |
|
|
? ( |
|
|
voteCounts={voteCounts} |
|
|
<PollChartBar |
|
|
voterNames={voterNames} |
|
|
pollOptions={pollOptions} |
|
|
/> |
|
|
voteCounts={voteCounts} |
|
|
|
|
|
voterNames={voterNames} |
|
|
|
|
|
/> |
|
|
|
|
|
) |
|
|
|
|
|
: ( |
|
|
|
|
|
<Header as="h4"> |
|
|
|
|
|
{t('topic.poll.tab.results.no.votes')} |
|
|
|
|
|
</Header> |
|
|
|
|
|
)} |
|
|
</Grid.Column> |
|
|
</Grid.Column> |
|
|
<Grid.Column /> |
|
|
<Grid.Column /> |
|
|
</Grid.Row> |
|
|
</Grid.Row> |
|
|
<Grid.Row> |
|
|
<Grid.Row> |
|
|
<Grid.Column textAlign="center"> |
|
|
<Grid.Column textAlign="center"> |
|
|
{footer} |
|
|
{totalVotes > 0 && footer} |
|
|
</Grid.Column> |
|
|
</Grid.Column> |
|
|
</Grid.Row> |
|
|
</Grid.Row> |
|
|
</Grid> |
|
|
</Grid> |
|
@ -65,18 +76,26 @@ const PollGraph = (props) => { |
|
|
<Grid columns="equal"> |
|
|
<Grid columns="equal"> |
|
|
<Grid.Row> |
|
|
<Grid.Row> |
|
|
<Grid.Column /> |
|
|
<Grid.Column /> |
|
|
<Grid.Column width={8}> |
|
|
<Grid.Column width={8} textAlign="center"> |
|
|
<PollChartDonut |
|
|
{totalVotes > 0 |
|
|
pollOptions={pollOptions} |
|
|
? ( |
|
|
voteCounts={voteCounts} |
|
|
<PollChartDonut |
|
|
voterNames={voterNames} |
|
|
pollOptions={pollOptions} |
|
|
/> |
|
|
voteCounts={voteCounts} |
|
|
|
|
|
voterNames={voterNames} |
|
|
|
|
|
/> |
|
|
|
|
|
) |
|
|
|
|
|
: ( |
|
|
|
|
|
<Header as="h4"> |
|
|
|
|
|
{t('topic.poll.tab.results.no.votes')} |
|
|
|
|
|
</Header> |
|
|
|
|
|
)} |
|
|
</Grid.Column> |
|
|
</Grid.Column> |
|
|
<Grid.Column /> |
|
|
<Grid.Column /> |
|
|
</Grid.Row> |
|
|
</Grid.Row> |
|
|
<Grid.Row> |
|
|
<Grid.Row> |
|
|
<Grid.Column textAlign="center"> |
|
|
<Grid.Column textAlign="center"> |
|
|
{footer} |
|
|
{totalVotes > 0 && footer} |
|
|
</Grid.Column> |
|
|
</Grid.Column> |
|
|
</Grid.Row> |
|
|
</Grid.Row> |
|
|
</Grid> |
|
|
</Grid> |
|
@ -87,7 +106,7 @@ const PollGraph = (props) => { |
|
|
{ menuItem: { key: 'chart-bar', icon: 'chart bar' }, render: () => chartBarPane }, |
|
|
{ menuItem: { key: 'chart-bar', icon: 'chart bar' }, render: () => chartBarPane }, |
|
|
{ menuItem: { key: 'chart-donut', icon: 'chart pie' }, render: () => chartDonutPane }, |
|
|
{ menuItem: { key: 'chart-donut', icon: 'chart pie' }, render: () => chartDonutPane }, |
|
|
]); |
|
|
]); |
|
|
}, [footer, pollOptions, voteCounts, voterNames]); |
|
|
}, [footer, pollOptions, t, totalVotes, voteCounts, voterNames]); |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<Tab |
|
|
<Tab |
|
|