Skip to content

Commit

Permalink
Add date sorting to era shows
Browse files Browse the repository at this point in the history
  • Loading branch information
jcraigk committed Nov 4, 2024
1 parent 182e40c commit f31e615
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 13 deletions.
1 change: 1 addition & 0 deletions app/api/api_v2/shows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def page_of_shows
shows = Show.published
.includes(
:venue,
:tour,
:album_cover_attachment,
:album_zip_attachment,
:cover_art_attachment,
Expand Down
50 changes: 45 additions & 5 deletions app/javascript/components/EraShows.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Helmet } from "react-helmet-async";
import LayoutWrapper from "./layout/LayoutWrapper";
import Shows from "./Shows";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faList, faTh, faCircleChevronLeft, faCircleChevronRight } from "@fortawesome/free-solid-svg-icons";
import { faList, faTh, faCircleChevronLeft, faCircleChevronRight, faSortAmountDown, faSortAmountUp } from "@fortawesome/free-solid-svg-icons";

export const eraShowsLoader = async ({ params }) => {
const { year } = params;
Expand All @@ -24,10 +24,19 @@ export const eraShowsLoader = async ({ params }) => {
};

const EraShows = () => {
const { shows, year } = useLoaderData();
const { shows: initialShows, year } = useLoaderData();
const [viewMode, setViewMode] = useState("grid");
const [sortOption, setSortOption] = useState("desc");
const [yearsData, setYearsData] = useState(null);

const sortedShows = [...initialShows].sort((a, b) => {
if (sortOption === "asc") {
return new Date(a.date) - new Date(b.date);
} else {
return new Date(b.date) - new Date(a.date);
}
});

useEffect(() => {
const fetchYearsData = async () => {
try {
Expand All @@ -46,6 +55,10 @@ const EraShows = () => {
setViewMode(mode);
};

const handleSortOptionChange = (option) => {
setSortOption(option);
};

const renderViewToggleButtons = () => (
<div className="view-toggle buttons has-addons">
<button
Expand All @@ -69,6 +82,29 @@ const EraShows = () => {
</div>
);

const renderSortButtons = () => (
<div className="view-toggle buttons has-addons">
<button
className={`button ${sortOption === "desc" ? "is-selected" : ""}`}
onClick={() => handleSortOptionChange("desc")}
disabled={sortOption === "desc"}
>
<span className="icon">
<FontAwesomeIcon icon={faSortAmountDown} />
</span>
</button>
<button
className={`button ${sortOption === "asc" ? "is-selected" : ""}`}
onClick={() => handleSortOptionChange("asc")}
disabled={sortOption === "asc"}
>
<span className="icon">
<FontAwesomeIcon icon={faSortAmountUp} />
</span>
</button>
</div>
);

const yearLinks = () => {
if (!yearsData) return null;
const yearIndex = yearsData.findIndex((y) => y.period === year);
Expand Down Expand Up @@ -96,8 +132,9 @@ const EraShows = () => {
const sidebarContent = (
<div className="sidebar-content">
<p className="sidebar-title">{year}</p>
<p className="sidebar-subtitle">{shows.length} shows</p>
<p className="sidebar-subtitle">{sortedShows.length} shows</p>
{renderViewToggleButtons()}
{renderSortButtons()}
<div className="hidden-mobile">{yearLinks()}</div>
</div>
);
Expand All @@ -108,8 +145,11 @@ const EraShows = () => {
<title>{year} - Phish.in</title>
</Helmet>
<LayoutWrapper sidebarContent={sidebarContent}>
<div className="display-phone-only">{renderViewToggleButtons()}</div>
<Shows shows={shows} tourHeaders={true} viewMode={viewMode} />
<div className="display-phone-only">
{renderViewToggleButtons()}
{renderSortButtons()}
</div>
<Shows shows={sortedShows} tourHeaders={true} viewMode={viewMode} />
{yearLinks()}
</LayoutWrapper>
</>
Expand Down
32 changes: 24 additions & 8 deletions app/javascript/stylesheets/content.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ main {
.view-toggle {
margin-bottom: 0px !important;

&:not(:first-child) {
margin-top: 1rem;
}

button {
padding: 8px 16px;
font-size: 1rem;
Expand Down Expand Up @@ -558,6 +562,14 @@ main {
width: 100%;
}

.view-toggle {
justify-content: center;

&:not(:first-child) {
margin-top: 0px !important;
}
}

.sidebar-control-container {
position: relative;
top: 3px;
Expand Down Expand Up @@ -631,6 +643,18 @@ main {
}

@media (max-width: 420px) {
.display-phone-only {
display: flex !important;
justify-content: center;
align-items: center;
gap: 1rem;
}

.view-toggle {
display: flex;
gap: 0.5rem; /* Space between buttons within each group */
}

.grid-view {
grid-template-columns: repeat(auto-fit, minmax(152px, 1fr));
gap: 0.7rem;
Expand All @@ -644,19 +668,11 @@ main {
display: none;
}

.view-toggle {
justify-content: center;
}

.list-item {
min-height: 2rem;
padding: 0.25rem 0.6rem;
}

.display-phone-only {
display: block !important;
}

.hidden-phone {
display: none !important;
}
Expand Down

0 comments on commit f31e615

Please sign in to comment.