diff --git a/src/pages/advent-calendar-2024/components/corner-layout.jsx b/src/pages/advent-calendar-2024/components/corner-layout.jsx index 349eaa1f19..182e9f96ca 100644 --- a/src/pages/advent-calendar-2024/components/corner-layout.jsx +++ b/src/pages/advent-calendar-2024/components/corner-layout.jsx @@ -36,19 +36,6 @@ const CornerLayout = () => { }; }, []); - const handleViewProgress = () => { - const completedDays = - JSON.parse(localStorage.getItem("completedDays")) || []; - - // Encode completed days as a Base64 string - const encodedDays = base64Encode(completedDays.join(",")); - const params = new URLSearchParams({ - completedDays: encodedDays, - }); - - navigate(`/advent-calendar-2024/progress-view?${params.toString()}`); - }; - const copyToClipboard = () => { const url = window.location.href; // Get the current URL @@ -60,9 +47,6 @@ const CornerLayout = () => { .catch((err) => console.error("Failed to copy: ", err)); }; - // Helper function to determine if the link should be underlined - const isCurrentPage = (path) => location.pathname === path; - return ( {isTabletOrBigger && ( diff --git a/src/pages/advent-calendar-2024/components/navbar.jsx b/src/pages/advent-calendar-2024/components/navbar.jsx index c5fe89262b..43448dad1b 100644 --- a/src/pages/advent-calendar-2024/components/navbar.jsx +++ b/src/pages/advent-calendar-2024/components/navbar.jsx @@ -21,7 +21,7 @@ import { useLocation, useNavigate } from "react-router-dom"; import { base64Encode } from "../utils/url-encoder"; import RotatingSVG from "./label-rotate"; -const SheetView = ({ isOpen, onClose, handleViewProgress }) => { +const SheetView = ({ isOpen, onClose }) => { return ( isOpen && ( @@ -59,7 +59,7 @@ const SheetView = ({ isOpen, onClose, handleViewProgress }) => {

In{" "} - + My Progress {" "} page, you can see the days you've completed, your @@ -120,19 +120,6 @@ const NavBar = () => { }; }, []); - const handleViewProgress = () => { - const completedDays = - JSON.parse(localStorage.getItem("completedDays")) || []; - - // Encode completed days as a Base64 string - const encodedDays = base64Encode(completedDays.join(",")); - const params = new URLSearchParams({ - completedDays: encodedDays, - }); - - navigate(`/advent-calendar-2024/progress-view?${params.toString()}`); - }; - // Helper function to determine if the link should be underlined const isCurrentPage = (path) => location.pathname === path; @@ -152,7 +139,7 @@ const NavBar = () => { }, { title: "My Progress", - onPress: handleViewProgress, + to: "/advent-calendar-2024/progress-view", decoration: isCurrentPage("/advent-calendar-2024/progress-view") ? "underline" : "none", @@ -169,11 +156,7 @@ const NavBar = () => { }, ]} /> - setIsSheetOpen(false)} - handleViewProgress={handleViewProgress} - /> + setIsSheetOpen(false)} /> ) : ( @@ -205,7 +188,7 @@ const NavBar = () => { > My progress @@ -232,11 +215,7 @@ const NavBar = () => { - setIsSheetOpen(false)} - handleViewProgress={handleViewProgress} - /> + setIsSheetOpen(false)} /> ); }; diff --git a/src/pages/advent-calendar-2024/pages/calendar-view.jsx b/src/pages/advent-calendar-2024/pages/calendar-view.jsx index e2fcf5c5f5..4bb4f55600 100644 --- a/src/pages/advent-calendar-2024/pages/calendar-view.jsx +++ b/src/pages/advent-calendar-2024/pages/calendar-view.jsx @@ -39,8 +39,6 @@ import { updateCompletedDays } from "../utils/state-manager"; import { base64Encode } from "../utils/url-encoder.jsx"; const CalendarView = () => { - const location = useLocation(); - const navigate = useNavigate(); const { isMobile } = useScreenSize(); // Load completed days from local storage on initial mount @@ -90,20 +88,13 @@ const CalendarView = () => { const newCompletedDays = [...completedDays, date]; // Update completed days state and local storage localStorage.setItem("completedDays", JSON.stringify(newCompletedDays)); - updateCompletedDays( - newCompletedDays, - setCompletedDays, - navigate, - location - ); + updateCompletedDays(newCompletedDays, setCompletedDays); // Check for achievements checkAndUnlockAchievements( newCompletedDays, achievements, setAchievements, - navigate, - location, handleShowToast ); } @@ -111,7 +102,7 @@ const CalendarView = () => { const clearLocalStorage = () => { localStorage.removeItem("completedDays"); // Clear from local storage - updateCompletedDays([], setCompletedDays, navigate, location); // Clear state + updateCompletedDays([], setCompletedDays); // Clear state achievementsConfig.forEach(({ id }) => { localStorage.removeItem(ACHIEVEMENT_PREFIX + id); }); @@ -154,20 +145,7 @@ const CalendarView = () => { }, [completedDays, availableDays, calendarDays]); const [isSheetOpen, setIsSheetOpen] = useState(false); - const handleViewProgress = () => { - const completedDays = - JSON.parse(localStorage.getItem("completedDays")) || []; - - // Encode completed days as a Base64 string - const encodedDays = base64Encode(completedDays.join(",")); - const params = new URLSearchParams({ - completedDays: encodedDays, - }); - - navigate(`/advent-calendar-2024/progress-view?${params.toString()}`); - }; - - const SheetView = ({ isOpen, onClose, handleViewProgress }) => { + const SheetView = ({ isOpen, onClose }) => { return ( isOpen && ( @@ -205,7 +183,9 @@ const CalendarView = () => {

In{" "} - + My Progress {" "} page, you can see the days you've completed, your @@ -332,11 +312,7 @@ const CalendarView = () => { - setIsSheetOpen(false)} - handleViewProgress={handleViewProgress} - /> + setIsSheetOpen(false)} /> ); diff --git a/src/pages/advent-calendar-2024/utils/achievement-config.jsx b/src/pages/advent-calendar-2024/utils/achievement-config.jsx index a86ef72e7c..255271cdf9 100644 --- a/src/pages/advent-calendar-2024/utils/achievement-config.jsx +++ b/src/pages/advent-calendar-2024/utils/achievement-config.jsx @@ -135,8 +135,6 @@ export const checkAndUnlockAchievements = ( newCompletedDays, achievements, setAchievements, - navigate, - location, showToast ) => { achievementsConfig.forEach(({ id, check, name, message, icon, isSecret }) => { @@ -160,9 +158,7 @@ export const checkAndUnlockAchievements = ( Object.keys(achievements) .filter((key) => achievements[key].isCompleted) .map((key) => key), - setAchievements, - navigate, - location + setAchievements ); } } diff --git a/src/pages/advent-calendar-2024/utils/state-manager.jsx b/src/pages/advent-calendar-2024/utils/state-manager.jsx index 65463f013e..e867b7fd47 100644 --- a/src/pages/advent-calendar-2024/utils/state-manager.jsx +++ b/src/pages/advent-calendar-2024/utils/state-manager.jsx @@ -1,25 +1,9 @@ -// utils/stateManager.js -import { base64Encode } from "./url-encoder"; - -export const updateCompletedDays = ( - days, - setCompletedDays, - navigate, - location -) => { +export const updateCompletedDays = (days, setCompletedDays) => { setCompletedDays(days); localStorage.setItem("completedDays", JSON.stringify(days)); - const params = new URLSearchParams(location.search); - params.set("completedDays", base64Encode(days.join(","))); - navigate({ search: params.toString() }, { replace: true }); }; -export const updateAchievements = ( - newAchievements, - setAchievements, - navigate, - location -) => { +export const updateAchievements = (newAchievements, setAchievements) => { // Get existing achievements from local storage const existingAchievements = JSON.parse(localStorage.getItem("achievements")) || []; @@ -32,9 +16,4 @@ export const updateAchievements = ( // Update state and local storage setAchievements(updatedAchievements); localStorage.setItem("achievements", JSON.stringify(updatedAchievements)); - - // Update the URL parameters - const params = new URLSearchParams(location.search); - params.set("achievements", base64Encode(updatedAchievements.join(","))); - navigate({ search: params.toString() }, { replace: true }); };