Created
September 26, 2020 22:30
-
-
Save lushiyun/5c3f3085498c40f6f87d92f0b1b77ec2 to your computer and use it in GitHub Desktop.
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
... // 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