Add /mayor/[year] and /mayor/all pages to display mayor data#1507
Add /mayor/[year] and /mayor/all pages to display mayor data#1507matthias-luger wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds new App Router pages to display Hypixel SkyBlock mayor election data for a specific year (/mayor/[year]) and a multi-year view (/mayor/all) using new client-side components that fetch mayor election periods and render them in a structured UI.
Changes:
- Introduces
/mayor/allpage backed by a newAllMayorsclient component fetching a 5-year election window. - Introduces
/mayor/[year]page backed by a newYearlyMayorclient component fetching election results for a single year. - Adds a new
MayorDetailsDisplaycomponent for rendering election periods (accordion + candidate/perk details), plus related styling.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| components/Mayor/YearlyMayor.tsx | Fetches mayor-election data for a given year and renders it via MayorDetailsDisplay. |
| components/Mayor/MayorDetailsDisplay.tsx | Main UI renderer for election periods, candidate selection, and perk display. |
| components/Mayor/MayorDetails.tsx | Additional mayor details component (currently appears unused) with its own fetch + accordion UI. |
| components/Mayor/MayorDetails.module.css | Styles for mayor-related pages/components (container, links, accordion styling). |
| components/Mayor/AllMayors.tsx | Fetches mayor-election data for the “last 5 years” window and renders it via MayorDetailsDisplay. |
| app/mayor/all/page.tsx | Adds the /mayor/all route and composes layout (NavBar/Search + content). |
| app/mayor/[year]/page.tsx | Adds the /mayor/[year] route and composes layout (NavBar/Search + content). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const yearInt = parseInt(year, 10); | ||
| const { data: mayorYearData, isLoading, error } = useGetApiMayorYear(yearInt, { | ||
| query: { | ||
| enabled: !isNaN(yearInt), | ||
| }, | ||
| }); |
There was a problem hiding this comment.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Fixed in 6227d27. /mayor/[year] now shows an explicit Invalid year state for non-numeric input instead of rendering a blank details view, and I also aligned the dynamic route page typing so the page builds correctly. Screenshot: /tmp/mayor-feedback/mayor-invalid-year.png
| {election.candidates?.map(candidate => ( | ||
| <ListGroup.Item | ||
| key={candidate.key} | ||
| action | ||
| onClick={() => setSelectedCandidateKey(candidate.key ?? null)} | ||
| className={`px-3 py-2 mb-2 rounded border ${selectedCandidateKey === candidate.key ? 'bg-primary text-white border-primary shadow' : 'bg-transparent text-light border-secondary opacity-75'}`} | ||
| style={{ cursor: 'pointer', transition: 'all 0.2s ease' }} |
| <h5 className="text-info mb-3 border-bottom pb-2"> | ||
| {selectedCandidateKey === election.winner?.key ? "Election Winner" : "Candidate Details"} | ||
| </h5> |
| {selectedCandidate.perks?.map(perk => ( | ||
| <Col sm={12} lg={6} key={perk.name}> |
| year?: string; | ||
| } | ||
|
|
||
| export function MayorDetailsDisplay({ elections, isSingleYear, year }: Props) { |
| {election.candidates?.map(candidate => ( | ||
| <li key={candidate.key}>{candidate.name}</li> |
| {election.winner.perks?.map(perk => ( | ||
| <li key={perk.name}>{perk.name}: {perk.description}</li> |
| export const metadata: Metadata = { | ||
| title: "All Mayor Flips", | ||
| description: "A list of all mayor flips from the last 5 years.", | ||
| }; |
| export const metadata: Metadata = { | ||
| title: "Mayor Flips", | ||
| description: "A list of items that are affected by the current or upcoming mayor.", | ||
| }; |
| "use client"; | ||
| import { useGetApiMayorYear } from "../../api/_generated/skyApi"; | ||
| import { MayorDetailsDisplay } from "./MayorDetailsDisplay"; | ||
|
|
||
| type Props = { | ||
| year: string; | ||
| }; | ||
|
|
||
| export function YearlyMayor({ year }: Props) { | ||
| const yearInt = parseInt(year, 10); | ||
| const { data: mayorYearData, isLoading, error } = useGetApiMayorYear(yearInt, { | ||
| query: { | ||
| enabled: !isNaN(yearInt), | ||
| }, | ||
| }); | ||
|
|
||
| if (isLoading) { | ||
| return <div>Loading...</div>; | ||
| } | ||
|
|
||
| if (error) { | ||
| return <div>Error loading mayor data for year {year}</div>; | ||
| } | ||
|
|
||
| const elections = mayorYearData?.data ? (Array.isArray(mayorYearData.data) ? mayorYearData.data : [mayorYearData.data]) : []; | ||
|
|
||
| return <MayorDetailsDisplay elections={elections} isSingleYear={true} year={year} />; |
Agent-Logs-Url: https://github.com/Coflnet/hypixel-react/sessions/c31a847d-2c22-475c-9018-4e6bfe4e5f46 Co-authored-by: matthias-luger <[email protected]>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
This reverts commit 6227d27.
No description provided.