This commit is contained in:
parent
39efca8fb7
commit
4d6ece7a3b
@ -5,6 +5,7 @@ import { ScoreSaberAPI } from "@/utils/scoresaber/api";
|
||||
import { normalizedRegionName } from "@/utils/utils";
|
||||
import dynamic from "next/dynamic";
|
||||
import Link from "next/link";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import Card from "../Card";
|
||||
import Container from "../Container";
|
||||
@ -29,6 +30,10 @@ type GlobalRankingProps = {
|
||||
};
|
||||
|
||||
export default function GlobalRanking({ page, country }: GlobalRankingProps) {
|
||||
const router = useRouter();
|
||||
const searchQuery = useSearchParams();
|
||||
const isMobile = searchQuery.get("mobile") == "true";
|
||||
|
||||
const [error, setError] = useState(false);
|
||||
const [errorMessage, setErrorMessage] = useState("");
|
||||
|
||||
@ -41,6 +46,13 @@ export default function GlobalRanking({ page, country }: GlobalRankingProps) {
|
||||
|
||||
const updatePage = useCallback(
|
||||
(page: any) => {
|
||||
const windowSize = document.documentElement.clientWidth;
|
||||
if (windowSize < 768 && !isMobile) {
|
||||
router.push(`/ranking/global/${page}?mobile=true`);
|
||||
router.refresh();
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Switching page to", page);
|
||||
ScoreSaberAPI.fetchTopPlayers(page, country).then((response) => {
|
||||
if (!response) {
|
||||
@ -65,7 +77,7 @@ export default function GlobalRanking({ page, country }: GlobalRankingProps) {
|
||||
);
|
||||
});
|
||||
},
|
||||
[country, pageInfo],
|
||||
[country, isMobile, pageInfo, router],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@ -117,7 +129,8 @@ export default function GlobalRanking({ page, country }: GlobalRankingProps) {
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<table className="hidden w-full table-auto border-spacing-2 border-none text-left md:table">
|
||||
{!isMobile && (
|
||||
<table className="table w-full table-auto border-spacing-2 border-none text-left">
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="px-4 py-2">Rank</th>
|
||||
@ -130,7 +143,10 @@ export default function GlobalRanking({ page, country }: GlobalRankingProps) {
|
||||
</thead>
|
||||
<tbody className="border-none">
|
||||
{players.map((player) => (
|
||||
<tr key={player.rank} className="border-b border-gray-700">
|
||||
<tr
|
||||
key={player.rank}
|
||||
className="border-b border-gray-700"
|
||||
>
|
||||
<PlayerRanking
|
||||
showCountryFlag={country ? false : true}
|
||||
player={player}
|
||||
@ -139,8 +155,10 @@ export default function GlobalRanking({ page, country }: GlobalRankingProps) {
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
|
||||
<div className="flex flex-col gap-2 md:hidden">
|
||||
{isMobile && (
|
||||
<div className="flex flex-col gap-2">
|
||||
{players.map((player) => (
|
||||
<div
|
||||
key={player.rank}
|
||||
@ -152,6 +170,7 @@ export default function GlobalRanking({ page, country }: GlobalRankingProps) {
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Pagination */}
|
||||
<div className="flex w-full flex-row justify-center rounded-md bg-gray-800 md:flex-col">
|
||||
|
Loading…
Reference in New Issue
Block a user