Skip to content
Open

Trend #110

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions front/src/common-app/components/define-trend.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import * as React from 'react';
import { cx } from 'emotion';
import * as classes from './table-player.styles';
import Typography from '@material-ui/core/Typography';
import Table from '@material-ui/core/Table';
import TableBody from '@material-ui/core/TableBody';
import TableCell from '@material-ui/core/TableCell';
import TableContainer from '@material-ui/core/TableContainer';
import TableHead from '@material-ui/core/TableHead';
import TableRow from '@material-ui/core/TableRow';
import { PlayerVotingStatus } from 'core';

interface Props {
playersCollection: PlayerVotingStatus[];
headingLevel?: React.ElementType;
}

export const TablePlayerTrendComponent: React.FC<Props> = (props: Props) => {
const { playersCollection, headingLevel } = props;

const getTrend = (): string => {
const result = playersCollection.map((elem: PlayerVotingStatus) =>
playersCollection.filter(
(player: PlayerVotingStatus) => player.vote === elem.vote
).length
);

const foundIndex = result.indexOf(Math.max(...result));

return playersCollection[foundIndex].vote;
Copy link
Member

Choose a reason for hiding this comment

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

Some feedback, this is business code, let's extract it to the define-trend.business.ts

Instead of using map and filter, why not using redux and do this in one go

If you use reduce in the proper way you can create an struct like. {xs: 3, s: 4}

};

return (
<div className={classes.container}>
<TableContainer className={classes.table}>
<Table aria-label="customized table">
<TableHead>
<TableRow>
<TableCell className={cx(classes.head, classes.cell)}>
Vote Trend
</TableCell>
<TableCell
className={cx(classes.head, classes.cell)}
align="right"
>
Result
</TableCell>
</TableRow>
</TableHead>
<TableBody className={classes.body}>
<TableRow key={1}>
Copy link
Member

Choose a reason for hiding this comment

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

If we don't have a map, we don't need to use key prop

<TableCell className={classes.cell} component="th" scope="row"/>
<TableCell className={classes.cell} align="right">
{ getTrend()}
</TableCell>
</TableRow>
</TableBody>
</Table>
</TableContainer>
</div>
);
};

TablePlayerTrendComponent.defaultProps = {
headingLevel: 'h2',
};
7 changes: 7 additions & 0 deletions front/src/pods/master/master.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { DefineStoryComponent } from './components';
import { VoteOptionsComponent } from 'common-app/components';
import { PlayerVotingStatus } from 'core';
import { Button } from '@material-ui/core';
import { TablePlayerTrendComponent } from 'common-app/components/define-trend';

interface Props {
room: string;
Expand Down Expand Up @@ -180,6 +181,12 @@ const ShowVotingResultsComponent: React.FC<ShowVotingResultsProps> = props => {
<div className={classes.containerComponent}>
<TablePlayerComponent playersCollection={playerVotingStatus} />
</div>
<div className={classes.containerComponent}>
<h2 className={classes.title}>Trend</h2>
Copy link
Member

Choose a reason for hiding this comment

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

Why don't move this title inside TablePlayerTrendComponent as TablePlayerComponent? Please check TablePlayerComponent that use Typography and headingLevel prop to change heading components by props

</div>
<div className={classes.containerComponent}>
<TablePlayerTrendComponent playersCollection={playerVotingStatus} />
</div>
<div className={classes.containerComponent}>
<Button
variant="contained"
Expand Down