diff --git a/app/javascript/components/EraShows.jsx b/app/javascript/components/EraShows.jsx index 7e300f50..6f18aa1c 100644 --- a/app/javascript/components/EraShows.jsx +++ b/app/javascript/components/EraShows.jsx @@ -1,6 +1,6 @@ import { authFetch } from "./helpers/utils"; -import React, { useState, useEffect } from "react"; -import { useLoaderData, Link } from "react-router-dom"; +import React, { useEffect, useState } from "react"; +import { useLoaderData, Link, useOutletContext } from "react-router-dom"; import { Helmet } from "react-helmet-async"; import LayoutWrapper from "./layout/LayoutWrapper"; import Shows from "./Shows"; @@ -25,8 +25,7 @@ export const eraShowsLoader = async ({ params }) => { const EraShows = () => { const { shows: initialShows, year } = useLoaderData(); - const [viewMode, setViewMode] = useState("grid"); - const [sortOption, setSortOption] = useState("desc"); + const { viewMode, setViewMode, sortOption, setSortOption } = useOutletContext(); const [yearsData, setYearsData] = useState(null); const sortedShows = [...initialShows].sort((a, b) => { @@ -51,19 +50,11 @@ const EraShows = () => { fetchYearsData(); }, []); - const handleViewModeChange = (mode) => { - setViewMode(mode); - }; - - const handleSortOptionChange = (option) => { - setSortOption(option); - }; - const renderViewToggleButtons = () => (
); return ( - <> - -
- {renderViewToggleButtons()} - {renderSortButtons()} -
+ +
+ {renderViewToggleButtons()} + {renderSortButtons()} +
-
- {Object.keys(eras) - .sort((a, b) => (sortOption === "asc" ? a.localeCompare(b) : b.localeCompare(a))) - .map((era) => ( - -
-
{era} Era
- {formatNumber(eras[era].total_shows, "show")} -
-
    - {eras[era].periods - .sort((a, b) => - sortOption === "asc" ? a.period.localeCompare(b.period) : b.period.localeCompare(a.period) - ) - .map((periodData) => - viewMode === "list" ? renderListItem(periodData) : renderGridItem(periodData) - )} -
-
- ) - )} -
-
- +
+ {Object.keys(eras) + .sort((a, b) => (sortOption === "asc" ? a.localeCompare(b) : b.localeCompare(a))) + .map((era) => ( + +
+
{era} Era
+ {formatNumber(eras[era].total_shows, "show")} +
+
    + {eras[era].periods + .sort((a, b) => + sortOption === "asc" ? a.period.localeCompare(b.period) : b.period.localeCompare(a.period) + ) + .map((periodData) => + viewMode === "list" ? renderListItem(periodData) : renderGridItem(periodData) + )} +
+
+ ))} +
+
); }; export default Eras; - - diff --git a/app/javascript/components/layout/Layout.jsx b/app/javascript/components/layout/Layout.jsx index d36cc783..5c8bcefb 100644 --- a/app/javascript/components/layout/Layout.jsx +++ b/app/javascript/components/layout/Layout.jsx @@ -1,5 +1,5 @@ import React, { useRef, useState, useEffect } from "react"; -import { Outlet, useNavigate, useNavigation, ScrollRestoration} from "react-router-dom"; +import { Outlet, useNavigate, useNavigation, ScrollRestoration } from "react-router-dom"; import Navbar from "./Navbar"; import Loader from "../controls/Loader"; import Player from "../controls/Player"; @@ -28,6 +28,7 @@ const Layout = ({ props }) => { const [draftPlaylistMeta, setDraftPlaylistMeta] = useState(initialDraftPlaylistMeta); const [isDraftPlaylistSaved, setIsDraftPlaylistSaved] = useState(false); const [activeTrack, setActiveTrack] = useState(null); + const [viewMode, setViewMode] = useState("grid"); // Add viewMode state here const audioRef = useRef(null); const { setNotice, setAlert } = useFeedback(); @@ -43,7 +44,6 @@ const Layout = ({ props }) => { usernameUpdatedAt: props.usernameUpdatedAt, email: props.email, }, "Google login successful"); - // Attempt login from jwt stored locally } else { let jwt = ""; let username = ""; @@ -60,7 +60,7 @@ const Layout = ({ props }) => { if (jwt && username && email) { setUser({ jwt, username, usernameUpdatedAt, email }); } else { - setUser('anonymous'); + setUser("anonymous"); } } }, []); @@ -87,7 +87,7 @@ const Layout = ({ props }) => { localStorage.removeItem("usernameUpdatedAt"); localStorage.removeItem("email"); } - navigate("/") + navigate("/"); setUser("anonymous"); setNotice("Logged out successfully"); }; @@ -124,34 +124,38 @@ const Layout = ({ props }) => { return ( <> - {navigation.state === 'loading' && } + {navigation.state === "loading" && } -
- +
+