-
Notifications
You must be signed in to change notification settings - Fork 7
Trend #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Trend #110
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
| }; | ||
|
|
||
| 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}> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| <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', | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't move this title inside |
||
| </div> | ||
| <div className={classes.containerComponent}> | ||
| <TablePlayerTrendComponent playersCollection={playerVotingStatus} /> | ||
| </div> | ||
| <div className={classes.containerComponent}> | ||
| <Button | ||
| variant="contained" | ||
|
|
||
There was a problem hiding this comment.
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}