-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #288 from cofacts/page-list-display
Replace <ArticleItem> with more reusable card components. Merge without review after 10 days since this PR is marked as reviewable.
- Loading branch information
Showing
17 changed files
with
885 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ node_modules/* | |
.next | ||
coverage | ||
!.storybook | ||
public/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import gql from 'graphql-tag'; | ||
import { ngettext, msgid } from 'ttag'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import { TYPE_ICON } from 'constants/replyType'; | ||
import Tooltip from 'components/Tooltip'; | ||
|
||
const useStyles = makeStyles(() => ({ | ||
opinions: { | ||
display: 'flex', | ||
}, | ||
opinion: { | ||
display: 'flex', | ||
alignItems: 'center', | ||
'&:not(:first-child)': { | ||
paddingLeft: 15, | ||
}, | ||
'& > span:nth-child(2)': { | ||
paddingLeft: 4, | ||
}, | ||
}, | ||
optionIcon: { | ||
fontSize: 14, | ||
}, | ||
})); | ||
|
||
function ReplyCountInfo({ normalArticleReplies }) { | ||
const classes = useStyles(); | ||
|
||
const replyCount = normalArticleReplies.length; | ||
const opinions = normalArticleReplies.reduce((result, { replyType }) => { | ||
if (result[replyType]) { | ||
result[replyType] += 1; | ||
} else { | ||
result[replyType] = 1; | ||
} | ||
return result; | ||
}, {}); | ||
|
||
return ( | ||
<Tooltip | ||
title={ | ||
replyCount === 0 ? ( | ||
'' | ||
) : ( | ||
<div className={classes.opinions}> | ||
{Object.entries(opinions).map(([k, v]) => { | ||
const IconComponent = TYPE_ICON[k]; | ||
return ( | ||
<span key={k} className={classes.opinion}> | ||
<IconComponent className={classes.optionIcon} /> | ||
<span>{v}</span> | ||
</span> | ||
); | ||
})} | ||
</div> | ||
) | ||
} | ||
arrow | ||
> | ||
<span> | ||
{ngettext( | ||
msgid`${replyCount} response`, | ||
`${replyCount} responses`, | ||
replyCount | ||
)} | ||
</span> | ||
</Tooltip> | ||
); | ||
} | ||
|
||
ReplyCountInfo.fragments = { | ||
ReplyCountInfo: gql` | ||
fragment NormalArticleReplyForReplyCountInfo on ArticleReply { | ||
replyType | ||
} | ||
`, | ||
}; | ||
|
||
export default ReplyCountInfo; |
Oops, something went wrong.