From 82d135143e32002cb063a5789256a07cff991b8c Mon Sep 17 00:00:00 2001 From: nekosoffy <161766793+nekosoffy@users.noreply.github.com> Date: Sat, 30 Nov 2024 09:46:35 -0300 Subject: [PATCH 1/4] refactor(museum): remove use of a magic number --- src/pages/museum.tsx | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/pages/museum.tsx b/src/pages/museum.tsx index 1ab00875..4dfb2328 100644 --- a/src/pages/museum.tsx +++ b/src/pages/museum.tsx @@ -20,6 +20,13 @@ import { import { usePlayers } from "@/contexts/players-context"; import { usePreferences } from "@/contexts/preferences-context"; +const reqs: Record = { + "A Complete Collection": Object.values(museum).flatMap((item) => + Object.values(item), + ).length, + "Treasure Trove": 40, +}; + export default function Museum() { const [open, setIsOpen] = useState(false); const [museumArtifact, setMuseumArtifact] = useState(null); @@ -53,25 +60,16 @@ export default function Museum() { const getAchievementProgress = (name: string) => { let completed = false; let additionalDescription = ""; + const collection = + museumArtifactCollected.size + museumMineralCollected.size; if (!activePlayer || !activePlayer.museum) return { completed, additionalDescription }; - if (name === "Treasure Trove") { - completed = - museumArtifactCollected.size + museumMineralCollected.size >= 40; - if (!completed) { - additionalDescription = ` - ${ - 40 - (museumArtifactCollected.size + museumMineralCollected.size) - } more`; - } - } else { - completed = - museumArtifactCollected.size + museumMineralCollected.size >= 95; + if (Object.hasOwn(reqs, name)) { + completed = collection >= reqs[name]; if (!completed) { - additionalDescription = ` - ${ - 95 - (museumArtifactCollected.size + museumMineralCollected.size) - } more`; + additionalDescription = ` - ${reqs[name] - collection} left`; } } From 99c1a58fde6599b4f2e889f37aae4cf2ff2ffbd2 Mon Sep 17 00:00:00 2001 From: nekosoffy <161766793+nekosoffy@users.noreply.github.com> Date: Sat, 30 Nov 2024 11:52:42 -0300 Subject: [PATCH 2/4] fix(museum): remove re-render with useEffect There was a slight but noticeable re-render of the page's numbers, probably due to useEffect. --- src/pages/museum.tsx | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/pages/museum.tsx b/src/pages/museum.tsx index 4dfb2328..13af6585 100644 --- a/src/pages/museum.tsx +++ b/src/pages/museum.tsx @@ -4,7 +4,7 @@ import achievements from "@/data/achievements.json"; import museum from "@/data/museum.json"; import { MuseumItem } from "@/types/items"; -import { useEffect, useState } from "react"; +import { useState, useMemo } from "react"; import { AchievementCard } from "@/components/cards/achievement-card"; import { BooleanCard } from "@/components/cards/boolean-card"; @@ -34,38 +34,30 @@ export default function Museum() { const [_artifactFilter, setArtifactFilter] = useState("all"); const [_mineralFilter, setMineralFilter] = useState("all"); - const [museumArtifactCollected, setMuseumArtifactCollected] = useState< - Set - >(new Set()); - - const [museumMineralCollected, setMuseumMineralCollected] = useState< - Set - >(new Set()); - const { activePlayer } = usePlayers(); const { show, toggleShow } = usePreferences(); // unblur dialog const [showPrompt, setPromptOpen] = useState(false); - useEffect(() => { - if (activePlayer) { - setMuseumArtifactCollected( - new Set(activePlayer?.museum?.artifacts ?? []), - ); - setMuseumMineralCollected(new Set(activePlayer?.museum?.minerals ?? [])); - } - }, [activePlayer]); + const [museumArtifactCollected, museumMineralCollected] = useMemo( + () => [ + new Set(activePlayer?.museum?.artifacts ?? []), + new Set(activePlayer?.museum?.minerals ?? []), + ], + [activePlayer], + ); const getAchievementProgress = (name: string) => { let completed = false; let additionalDescription = ""; - const collection = - museumArtifactCollected.size + museumMineralCollected.size; if (!activePlayer || !activePlayer.museum) return { completed, additionalDescription }; + const collection = + museumArtifactCollected.size + museumMineralCollected.size; + if (Object.hasOwn(reqs, name)) { completed = collection >= reqs[name]; if (!completed) { From 9e18123c8a0e6c1e76a3a3452ed7787e4defe29c Mon Sep 17 00:00:00 2001 From: nekosoffy <161766793+nekosoffy@users.noreply.github.com> Date: Sat, 30 Nov 2024 13:35:30 -0300 Subject: [PATCH 3/4] feat(museum): add numerical counter on filters --- src/pages/museum.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/pages/museum.tsx b/src/pages/museum.tsx index 13af6585..0b1ffc25 100644 --- a/src/pages/museum.tsx +++ b/src/pages/museum.tsx @@ -68,6 +68,13 @@ export default function Museum() { return { completed, additionalDescription }; }; + const remainingDonations = { + artifacts: + Object.values(museum.artifacts).length - museumArtifactCollected.size, + minerals: + Object.values(museum.minerals).length - museumMineralCollected.size, + }; + return ( <> @@ -142,13 +149,13 @@ export default function Museum() { @@ -187,13 +194,13 @@ export default function Museum() { From 6f0e9370daad0e4dcb3579ca9865faebda0a55c2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 5 Dec 2024 17:21:21 +0000 Subject: [PATCH 4/4] docs(contributor): contrib-readme-action has updated readme --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 9af262af..5f12fab0 100644 --- a/README.md +++ b/README.md @@ -76,25 +76,25 @@ Below are some incredible people that the website wouldn't be without today. - - TheLDB + + softy-dev
- Landon + Softy
- - brandonsaldan + + TheLDB
- Brandon Saldan + Landon
- - nekosoffy + + brandonsaldan
- Null + Brandon Saldan