Skip to content

Commit

Permalink
🚨 Fix linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
foosel committed Apr 9, 2024
1 parent 2c90609 commit a7114e7
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/components/AchievementStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import ACHIEVEMENTS from "../data/achievements.json";
const MARGIN = 10;
const FONTSIZE = 12;

const numberFormatter = (value, total) =>
countFormatter(value) + " (" + Math.floor((value / total) * 100) + "%)";

const measureText = (text, font) => {
const canvas = document.createElement("canvas");
const context = canvas.getContext("2d");
Expand All @@ -35,15 +38,8 @@ export default function AchievementStats(props) {
const [spoiler, setSpoiler] = useState(false);

const {days} = useDays();

const numberFormatter = (value) => {
return (
countFormatter(value) +
" (" +
Math.floor((value / instanceCount) * 100) +
"%)"
);
};
const theme = useTheme();
const isSmallScreen = useMediaQuery(theme.breakpoints.down("md"));

const getDescriptionOf = (label) => {
if (label === "(Hidden)") return "This achievement is hidden.";
Expand Down Expand Up @@ -71,7 +67,7 @@ export default function AchievementStats(props) {
>
<p className="label">
<strong>
{label}: {numberFormatter(payload[0].value)}
{label}: {numberFormatter(payload[0].value, instanceCount)}
</strong>
</p>
<p className="desc">{getDescriptionOf(label)}</p>
Expand All @@ -91,7 +87,9 @@ export default function AchievementStats(props) {
const font = `${FONTSIZE}px ${theme.typography.fontFamily}`;

setInstanceCount(stats.instances);
setMaxTextWidthRight(measureText(numberFormatter(stats.instances), font));
setMaxTextWidthRight(
measureText(numberFormatter(stats.instances, stats.instances), font)
);

const data = [];
for (const a in ACHIEVEMENTS) {
Expand Down Expand Up @@ -120,11 +118,7 @@ export default function AchievementStats(props) {

setAchievementData(data);
console.log("Achievement data", data);
}, [stats, spoiler]);

const theme = useTheme();

const isSmallScreen = useMediaQuery(theme.breakpoints.down("lg"));
}, [stats, spoiler, theme.typography.fontFamily]);

return (
<Stats
Expand Down Expand Up @@ -172,7 +166,7 @@ export default function AchievementStats(props) {
fill: theme.palette.text.secondary,
fontSize: FONTSIZE
}}
tickFormatter={numberFormatter}
tickFormatter={(v) => numberFormatter(v, instanceCount)}
/>
)}
<Tooltip
Expand Down

0 comments on commit a7114e7

Please sign in to comment.