Skip to content

Instantly share code, notes, and snippets.

@lushiyun
Created September 26, 2020 22:30
Show Gist options
  • Save lushiyun/5c3f3085498c40f6f87d92f0b1b77ec2 to your computer and use it in GitHub Desktop.
Save lushiyun/5c3f3085498c40f6f87d92f0b1b77ec2 to your computer and use it in GitHub Desktop.
... // omitted other imports
import { selectUnreadMessages } from '../messages/messagesSlice'
const TeamListItem = ({ team }) => {
...
const numOfUnreads = useSelector((state) =>
selectUnreadMessages(state, team.id)
).length
const getFontWeight = () => {
if (location.pathname.slice(7) === team.id) {
return 'fontWeightRegular'
}
return numOfUnreads === 0 ? 'fontWeightRegular' : 'fontWeightBold'
}
const renderedNumOfUnreads = () => {
if (location.pathname.slice(7) === team.id) {
return 0
}
return numOfUnreads
}
return (
// material UI
<Link to={`/teams/${team.id}`}>
<Badge badgeContent={renderedNumOfUnreads()}>
<Typography>
<Box fontWeight={getFontWeight()}>{team.name}</Box>
</Typography>
</Badge>
</Link>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment