Skip to content

Commit

Permalink
Give shield icon to moderators (#176)
Browse files Browse the repository at this point in the history
This is useful for distinguishing them on the site and transparency. Took this from the some1 fork, it's a good idea.

To avoid this being too extraneous, I'm only showing the icons in chat now, not in the games table or lobby.
  • Loading branch information
ekzhang authored Dec 28, 2024
1 parent c7929db commit daaef4c
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/components/Chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ function Chat({
component={InternalLink}
to={`/profile/${item.user}`}
underline="none"
showIcon
/>
: {item.message}
</Typography>,
Expand Down
2 changes: 1 addition & 1 deletion src/components/GameInfoRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function GameInfoRow({ gameId, onClick }) {
}
return (
<Tooltip title={title} arrow placement="top">
<Icon fontSize="small" />
<Icon fontSize="small" sx={{ display: "block" }} />
</Tooltip>
);
};
Expand Down
12 changes: 6 additions & 6 deletions src/components/ProfileGamesTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ const useStyles = makeStyles((theme) => ({
paddingLeft: 12,
paddingRight: 12,
},
"& svg": {
display: "block",
},
"& th": {
background: theme.palette.background.panel,
},
Expand All @@ -49,6 +46,11 @@ const useStyles = makeStyles((theme) => ({
display: "none",
},
},
starIcon: {
display: "block",
color: amber[500],
marginBlock: -4,
},
}));

function ProfileGamesTable({ userId, gamesWithScores, handleClickGame }) {
Expand Down Expand Up @@ -115,9 +117,7 @@ function ProfileGamesTable({ userId, gamesWithScores, handleClickGame }) {
{game.scores &&
game.scores[userId] ===
Math.max(0, ...Object.values(game.scores)) && (
<StarIcon
style={{ color: amber[500], marginBlock: -4 }}
/>
<StarIcon className={classes.starIcon} />
)}
</TableCell>
</TableRow>
Expand Down
1 change: 1 addition & 0 deletions src/components/ProfileName.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function ProfileName({ userId }) {
return (
<User
id={userId}
showIcon
render={(player, userEl) => {
const isOnline =
player.connections && Object.keys(player.connections).length > 0;
Expand Down
37 changes: 22 additions & 15 deletions src/components/User.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import SecurityIcon from "@mui/icons-material/Security";
import WhatshotIcon from "@mui/icons-material/Whatshot";
import { useTheme } from "@mui/material/styles";
import makeStyles from "@mui/styles/makeStyles";
import clsx from "clsx";
import { useNavigate } from "react-router-dom";

import useFirebaseRef from "../hooks/useFirebaseRef";
import useStats from "../hooks/useStats";
import { colors } from "../util";

const useStyles = makeStyles(() => ({
inlineIcon: {
fontSize: "inherit",
display: "inline",
position: "relative",
left: "-0.1em",
top: "0.15em",
color: "inherit",
},
patronIcon: {
cursor: "pointer",
"&:hover": {
Expand All @@ -32,6 +42,7 @@ function User({
component,
render,
forcePatron,
showIcon,
showRating,
...other
}) {
Expand All @@ -46,7 +57,7 @@ function User({
return null;
}

const handleClick = (e) => {
const handlePatronClick = (e) => {
e.preventDefault();
navigate("/donate");
};
Expand All @@ -68,20 +79,16 @@ function User({
{loadingStats ? "⋯" : Math.round(stats[showRating].rating)}
</span>
)}
{(user.patron || forcePatron) && (
<WhatshotIcon
className={classes.patronIcon}
onClick={handleClick}
fontSize="inherit"
style={{
display: "inline",
position: "relative",
left: "-0.1em",
top: "0.15em",
color: "inherit",
}}
/>
)}
{showIcon &&
(user.admin ? (
// Moderator icon takes precedence over patron icon.
<SecurityIcon className={classes.inlineIcon} />
) : user.patron || forcePatron ? (
<WhatshotIcon
className={clsx(classes.inlineIcon, classes.patronIcon)}
onClick={handlePatronClick}
/>
) : null)}
<span>{user.name}</span>
</Component>
);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/DonatePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function DonatePage() {
<ul>
<li>
Bragging rights with a patron icon next to your name (e.g.,{" "}
<User id={user.id} forcePatron />
<User id={user.id} showIcon forcePatron />
).
</li>
<li>
Expand Down
3 changes: 0 additions & 3 deletions src/pages/LobbyPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ const useStyles = makeStyles((theme) => ({
paddingLeft: 12,
paddingRight: 12,
},
"& svg": {
display: "block",
},
"& tbody > tr:hover": {
background: theme.palette.action.hover,
cursor: "pointer",
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ProfilePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function ProfilePage() {
<Subheading className={classes.statsHeading}>
Statistics
</Subheading>
<EqualizerIcon />
<EqualizerIcon sx={{ mt: "1px" }} />
</div>
<div style={{ marginLeft: "auto" }}>
<Select
Expand Down

0 comments on commit daaef4c

Please sign in to comment.