mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 12:09:51 +02:00
feat: page turning in current season
This commit is contained in:
1 parent
286936131d
commit
64253d0120
2 files changed
+26
-13
No files matched your search
@@ -5,10 +5,10 @@ import { useEffect, useRef } from 'react';
|
|||||||
interface PageTurnerProps {
|
interface PageTurnerProps {
|
||||||
page: number;
|
page: number;
|
||||||
pages: number;
|
pages: number;
|
||||||
setPage: (page: number | ((page: number) => number)) => void;
|
onPageChange: (page: number) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PageTurner({ page, setPage, pages }: PageTurnerProps) {
|
export function PageTurner({ page, onPageChange, pages }: PageTurnerProps) {
|
||||||
const pageInput = useRef<HTMLInputElement>(null);
|
const pageInput = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -20,7 +20,7 @@ export function PageTurner({ page, setPage, pages }: PageTurnerProps) {
|
|||||||
<Flex gap="2">
|
<Flex gap="2">
|
||||||
<Button
|
<Button
|
||||||
variant="soft"
|
variant="soft"
|
||||||
onClick={() => setPage((page) => Math.max(page - 1, 0))}
|
onClick={() => onPageChange(Math.max(page - 1, 0))}
|
||||||
disabled={page === 0}
|
disabled={page === 0}
|
||||||
>
|
>
|
||||||
<CaretLeftIcon />
|
<CaretLeftIcon />
|
||||||
@@ -32,7 +32,7 @@ export function PageTurner({ page, setPage, pages }: PageTurnerProps) {
|
|||||||
ref={pageInput}
|
ref={pageInput}
|
||||||
style={{ width: 64, textAlign: 'center' }}
|
style={{ width: 64, textAlign: 'center' }}
|
||||||
onBlur={(event) => {
|
onBlur={(event) => {
|
||||||
setPage(
|
onPageChange(
|
||||||
Math.max(
|
Math.max(
|
||||||
0,
|
0,
|
||||||
Math.min(pages - 1, event.target.valueAsNumber - 1),
|
Math.min(pages - 1, event.target.valueAsNumber - 1),
|
||||||
@@ -50,7 +50,7 @@ export function PageTurner({ page, setPage, pages }: PageTurnerProps) {
|
|||||||
<Button
|
<Button
|
||||||
variant="soft"
|
variant="soft"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setPage((page) => Math.min(page + 1, pages - 1));
|
onPageChange(Math.min(page + 1, pages - 1));
|
||||||
}}
|
}}
|
||||||
disabled={page === pages - 1}
|
disabled={page === pages - 1}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -290,13 +290,12 @@ export default function Page() {
|
|||||||
return neighbors;
|
return neighbors;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleJumpToPosition() {
|
async function jumpToPosition(position: number) {
|
||||||
if (!ratingsInfo || ratingsInfo?.detail) return;
|
if (!ratingsInfo || ratingsInfo?.detail) return;
|
||||||
|
|
||||||
const rawPosition = positionInput.current!.valueAsNumber - 1;
|
|
||||||
const targetPosition = Math.max(
|
const targetPosition = Math.max(
|
||||||
0,
|
0,
|
||||||
Math.min(rawPosition, ratingsInfo.count - 1),
|
Math.min(position, ratingsInfo.count - 1),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (season === 0) {
|
if (season === 0) {
|
||||||
@@ -557,7 +556,7 @@ export default function Page() {
|
|||||||
placeholder="Type a position..."
|
placeholder="Type a position..."
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
if (event.key === 'Enter') {
|
if (event.key === 'Enter') {
|
||||||
handleJumpToPosition();
|
jumpToPosition(positionInput.current!.valueAsNumber - 1);
|
||||||
setJumpToPositionOpen(false);
|
setJumpToPositionOpen(false);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
@@ -568,7 +567,13 @@ export default function Page() {
|
|||||||
<Button color="red">Cancel</Button>
|
<Button color="red">Cancel</Button>
|
||||||
</Dialog.Close>
|
</Dialog.Close>
|
||||||
<Dialog.Close>
|
<Dialog.Close>
|
||||||
<Button onClick={handleJumpToPosition}>Jump</Button>
|
<Button
|
||||||
|
onClick={() =>
|
||||||
|
jumpToPosition(positionInput.current!.valueAsNumber - 1)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Jump
|
||||||
|
</Button>
|
||||||
</Dialog.Close>
|
</Dialog.Close>
|
||||||
</Flex>
|
</Flex>
|
||||||
</Flex>
|
</Flex>
|
||||||
@@ -854,7 +859,11 @@ export default function Page() {
|
|||||||
</Flex>
|
</Flex>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
<PageTurner page={page} pages={pages} setPage={setPage} />
|
<PageTurner
|
||||||
|
page={page}
|
||||||
|
pages={pages}
|
||||||
|
onPageChange={(page) => jumpToPosition(page * ROWS_PER_PAGE)}
|
||||||
|
/>
|
||||||
|
|
||||||
<Leaderboard.Root>
|
<Leaderboard.Root>
|
||||||
{players === null ? (
|
{players === null ? (
|
||||||
@@ -893,7 +902,11 @@ export default function Page() {
|
|||||||
)}
|
)}
|
||||||
</Leaderboard.Root>
|
</Leaderboard.Root>
|
||||||
|
|
||||||
<PageTurner page={page} pages={pages} setPage={setPage} />
|
<PageTurner
|
||||||
|
page={page}
|
||||||
|
pages={pages}
|
||||||
|
onPageChange={(page) => jumpToPosition(page * ROWS_PER_PAGE)}
|
||||||
|
/>
|
||||||
|
|
||||||
{loadingProgress !== null && (
|
{loadingProgress !== null && (
|
||||||
<Flex
|
<Flex
|
||||||
@@ -930,7 +943,7 @@ export default function Page() {
|
|||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
height: '100%',
|
height: '100%',
|
||||||
transitionDuration: '200ms',
|
transitionDuration: '10s',
|
||||||
width: `${Math.round(
|
width: `${Math.round(
|
||||||
(loadingProgress[0] / loadingProgress[1]) * 100,
|
(loadingProgress[0] / loadingProgress[1]) * 100,
|
||||||
)}%`,
|
)}%`,
|
||||||
|
|||||||
Reference in new issue
Block a user