make urls look less awful (remove query params)
All checks were successful
deploy / deploy (push) Successful in 53s
All checks were successful
deploy / deploy (push) Successful in 53s
This commit is contained in:
parent
3e10b0108b
commit
171dfd9cc0
@ -6,7 +6,7 @@ import { normalizedRegionName } from "@/utils/utils";
|
||||
import { Metadata } from "next";
|
||||
|
||||
type Props = {
|
||||
params: { id: string };
|
||||
params: { id: string; sort: string; page: string };
|
||||
};
|
||||
|
||||
export async function generateMetadata({
|
||||
@ -47,6 +47,6 @@ export async function generateMetadata({
|
||||
};
|
||||
}
|
||||
|
||||
export default function Player({ params: { id } }: Props) {
|
||||
return <PlayerPage id={id} />;
|
||||
export default function Player({ params: { id, sort, page } }: Props) {
|
||||
return <PlayerPage id={id} sort={sort} page={page} />;
|
||||
}
|
9
src/app/ranking/country/[country]/[page]/page.tsx
Normal file
9
src/app/ranking/country/[country]/[page]/page.tsx
Normal file
@ -0,0 +1,9 @@
|
||||
import GlobalRanking from "@/components/player/GlobalRanking";
|
||||
|
||||
type Props = {
|
||||
params: { page: string; country: string };
|
||||
};
|
||||
|
||||
export default function RankingGlobal({ params: { page, country } }: Props) {
|
||||
return <GlobalRanking page={Number(page)} country={country} />;
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
import GlobalRanking from "@/components/player/GlobalRanking";
|
||||
import { getPageFromSearchQuery } from "@/utils/utils";
|
||||
import { headers } from "next/headers";
|
||||
|
||||
type RankingCountryProps = {
|
||||
params: { country: string };
|
||||
};
|
||||
|
||||
export default function RankingCountry({ params }: RankingCountryProps) {
|
||||
const page = getPageFromSearchQuery(headers());
|
||||
const country = params.country;
|
||||
|
||||
return <GlobalRanking page={page} country={country} />;
|
||||
}
|
9
src/app/ranking/global/[page]/page.tsx
Normal file
9
src/app/ranking/global/[page]/page.tsx
Normal file
@ -0,0 +1,9 @@
|
||||
import GlobalRanking from "@/components/player/GlobalRanking";
|
||||
|
||||
type Props = {
|
||||
params: { page: string };
|
||||
};
|
||||
|
||||
export default function RankingGlobal({ params: { page } }: Props) {
|
||||
return <GlobalRanking page={Number(page)} />;
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
import GlobalRanking from "@/components/player/GlobalRanking";
|
||||
import { getPageFromSearchQuery } from "@/utils/utils";
|
||||
import { headers } from "next/headers";
|
||||
|
||||
export default function RankingGlobal() {
|
||||
const page = getPageFromSearchQuery(headers());
|
||||
|
||||
return <GlobalRanking page={page} />;
|
||||
}
|
@ -56,7 +56,7 @@ export default function Navbar() {
|
||||
size={32}
|
||||
/>
|
||||
}
|
||||
href={`/player/${settingsStore.player.id}`}
|
||||
href={`/player/${settingsStore.player.id}/top/1`}
|
||||
/>
|
||||
)}
|
||||
|
||||
@ -70,7 +70,7 @@ export default function Navbar() {
|
||||
key={friend.id}
|
||||
className="mt-2 bg-gray-500"
|
||||
text={friend.name}
|
||||
url={`/player/${friend.id}`}
|
||||
url={`/player/${friend.id}/top/1`}
|
||||
icon={
|
||||
<Avatar
|
||||
url={friend.profilePicture}
|
||||
@ -93,7 +93,7 @@ export default function Navbar() {
|
||||
<NavbarButton
|
||||
text="Ranking"
|
||||
icon={<GlobeAltIcon height={20} width={20} />}
|
||||
href="/ranking/global"
|
||||
href="/ranking/global/1"
|
||||
/>
|
||||
|
||||
<div className="m-auto" />
|
||||
|
@ -59,18 +59,11 @@ export default function GlobalRanking({ page, country }: GlobalRankingProps) {
|
||||
loading: false,
|
||||
page: page,
|
||||
});
|
||||
const urlBase = country
|
||||
? `/ranking/country/${country}`
|
||||
: "/ranking/global";
|
||||
if (page > 1) {
|
||||
router.push(`${urlBase}?page=${page}`, {
|
||||
scroll: false,
|
||||
});
|
||||
} else {
|
||||
router.push(`${urlBase}`, {
|
||||
scroll: false,
|
||||
});
|
||||
}
|
||||
router.push(
|
||||
country
|
||||
? `/ranking/country/${country}/${page}`
|
||||
: `/ranking/global/${page}`,
|
||||
);
|
||||
});
|
||||
},
|
||||
[country, pageInfo, router],
|
||||
|
@ -169,9 +169,7 @@ export default function PlayerInfo({ playerData }: PlayerInfoProps) {
|
||||
|
||||
<a
|
||||
className="flex transform-gpu items-center gap-1 transition-all hover:text-blue-500"
|
||||
href={`/ranking/global/?page=${Math.round(
|
||||
playerData.rank / 50,
|
||||
)}`}
|
||||
href={`/ranking/global/${Math.round(playerData.rank / 50)}`}
|
||||
>
|
||||
<p>#{formatNumber(playerData.rank)}</p>
|
||||
</a>
|
||||
@ -181,7 +179,7 @@ export default function PlayerInfo({ playerData }: PlayerInfoProps) {
|
||||
<div className="text-gray-300">
|
||||
<a
|
||||
className="flex transform-gpu items-center gap-1 transition-all hover:text-blue-500"
|
||||
href={`/ranking/country/${playerData.country}?page=${Math.round(
|
||||
href={`/ranking/country/${playerData.country}/${Math.round(
|
||||
playerData.countryRank / 50,
|
||||
)}`}
|
||||
>
|
||||
|
@ -5,12 +5,9 @@ import Container from "@/components/Container";
|
||||
import Spinner from "@/components/Spinner";
|
||||
import Scores from "@/components/player/Scores";
|
||||
import { ScoresaberPlayer } from "@/schemas/scoresaber/player";
|
||||
import { useSettingsStore } from "@/store/settingsStore";
|
||||
import { SortType, SortTypes } from "@/types/SortTypes";
|
||||
import { SortTypes } from "@/types/SortTypes";
|
||||
import { ScoreSaberAPI } from "@/utils/scoresaber/api";
|
||||
import useStore from "@/utils/useStore";
|
||||
import dynamic from "next/dynamic";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
import PlayerInfo from "./PlayerInfo";
|
||||
|
||||
@ -23,14 +20,13 @@ type PlayerInfo = {
|
||||
|
||||
type PlayerPageProps = {
|
||||
id: string;
|
||||
sort: string;
|
||||
page: string;
|
||||
};
|
||||
|
||||
const DEFAULT_SORT_TYPE = SortTypes.top;
|
||||
|
||||
export default function PlayerPage({ id }: PlayerPageProps) {
|
||||
const settingsStore = useStore(useSettingsStore, (store) => store);
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
export default function PlayerPage({ id, sort, page }: PlayerPageProps) {
|
||||
const [mounted, setMounted] = useState(false);
|
||||
const [error, setError] = useState(false);
|
||||
const [errorMessage, setErrorMessage] = useState("");
|
||||
@ -40,21 +36,7 @@ export default function PlayerPage({ id }: PlayerPageProps) {
|
||||
player: undefined,
|
||||
});
|
||||
|
||||
let page;
|
||||
const pageString = searchParams.get("page");
|
||||
if (pageString == null) {
|
||||
page = 1;
|
||||
} else {
|
||||
page = Number.parseInt(pageString) || 1;
|
||||
}
|
||||
|
||||
let sortType: SortType;
|
||||
const sortTypeString = searchParams.get("sort");
|
||||
if (sortTypeString == null) {
|
||||
sortType = settingsStore?.lastUsedSortType || DEFAULT_SORT_TYPE;
|
||||
} else {
|
||||
sortType = SortTypes[sortTypeString] || DEFAULT_SORT_TYPE;
|
||||
}
|
||||
const sortType = SortTypes[sort] || DEFAULT_SORT_TYPE;
|
||||
|
||||
useEffect(() => {
|
||||
setMounted(true);
|
||||
@ -102,7 +84,11 @@ export default function PlayerPage({ id }: PlayerPageProps) {
|
||||
<main>
|
||||
<Container>
|
||||
<PlayerInfo playerData={playerData} />
|
||||
<Scores playerData={playerData} page={page} sortType={sortType} />
|
||||
<Scores
|
||||
playerData={playerData}
|
||||
page={Number(page)}
|
||||
sortType={sortType}
|
||||
/>
|
||||
</Container>
|
||||
</main>
|
||||
);
|
||||
|
@ -66,18 +66,9 @@ export default function Scores({ playerData, page, sortType }: ScoresProps) {
|
||||
});
|
||||
settingsStore?.setLastUsedSortType(sortType);
|
||||
|
||||
if (page > 1) {
|
||||
router.push(
|
||||
`/player/${playerId}?page=${page}&sort=${sortType.value}`,
|
||||
{
|
||||
scroll: false,
|
||||
},
|
||||
);
|
||||
} else {
|
||||
router.push(`/player/${playerId}?sort=${sortType.value}`, {
|
||||
scroll: false,
|
||||
});
|
||||
}
|
||||
router.push(`/player/${playerId}/${sortType.value}/${page}`, {
|
||||
scroll: false,
|
||||
});
|
||||
|
||||
console.log(`Switched page to ${page} with sort ${sortType.value}`);
|
||||
},
|
||||
|
@ -45,7 +45,7 @@ export default function SearchPlayer() {
|
||||
|
||||
// Take the user to the first account
|
||||
if (players.length > 0) {
|
||||
window.location.href = `/player/${players[0].id}`;
|
||||
window.location.href = `/player/${players[0].id}/top/1`;
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ export default function SearchPlayer() {
|
||||
<a
|
||||
key={player.id}
|
||||
className="flex min-w-[14rem] items-center gap-2 rounded-md p-2 transition-all hover:bg-gray-600"
|
||||
href={`/player/${player.id}`}
|
||||
href={`/player/${player.id}/top/1`}
|
||||
>
|
||||
<Avatar label="Account" size={40} url={player.profilePicture} />
|
||||
|
||||
|
@ -9,7 +9,7 @@ export function middleware(request: NextRequest) {
|
||||
if (pathname == "/") {
|
||||
if (playerIdCookie) {
|
||||
return NextResponse.redirect(
|
||||
new URL(`/player/${playerIdCookie.value}`, request.url),
|
||||
new URL(`/player/${playerIdCookie.value}/top/1`, request.url),
|
||||
);
|
||||
} else {
|
||||
return NextResponse.redirect(new URL("/search", request.url));
|
||||
|
Loading…
x
Reference in New Issue
Block a user