refactor: move round table helper to utils and clean GroupMember

- extract getRoundTable into src/utils.ts as a reusable generic helper
- update GroupMember to import getRoundTable from utils
- remove round pairing debug log from GroupMember
This commit is contained in:
kyuuseiryuu 2026-02-16 15:03:14 +09:00
parent a9b7113173
commit a4fc0d0031
2 changed files with 22 additions and 22 deletions

View File

@ -1,6 +1,7 @@
import { useMemo, useState } from "react";
import { Button, Card, Divider, Drawer, Flex, Space, Table } from "antd"; import { Button, Card, Divider, Drawer, Flex, Space, Table } from "antd";
import type { BasePlayer } from "../types"; import type { BasePlayer } from "../types";
import { useMemo, useState } from "react"; import { getRoundTable } from "../utils";
import User from "./User"; import User from "./User";
interface Props { interface Props {
@ -65,7 +66,6 @@ function BattleTable({ nameList }: {
<Flex vertical gap={12} justify="center" align="center"> <Flex vertical gap={12} justify="center" align="center">
{new Array(list.length - 1).fill(0).map((_, i) => { {new Array(list.length - 1).fill(0).map((_, i) => {
const [left, right] = getRoundTable(list, i); const [left, right] = getRoundTable(list, i);
console.debug({ left, right });
return ( return (
<Card size="small" key={`round-${i}`} title={`Round: ${i + 1}`}> <Card size="small" key={`round-${i}`} title={`Round: ${i + 1}`}>
{left?.map((e, r) => { {left?.map((e, r) => {
@ -86,23 +86,3 @@ function BattleTable({ nameList }: {
</Flex> </Flex>
); );
} }
function getRoundTable(nameList: string[], round: number) {
const list = [...nameList];
const half = list.length / 2;
if (round > list.length - 1) {
const left = [...list].slice(0, half);
const right = [...list].slice(half);
return [left, right];
}
const sliceStart = (list.length) - round;
const slice = list.slice(sliceStart);
// console.debug(JSON.stringify({ list }));
list.splice(sliceStart);
const [first, ...others] = list;
const newList = [first, ...slice, ...others].filter(Boolean);
// console.debug(JSON.stringify({ sliceStart, len: list.length, first, others, slice, newList }));
const left = [...newList].slice(0, half);
const right = [...newList].slice(half).reverse();
return [left, right];
}

View File

@ -119,4 +119,24 @@ export function sneckGroup(size: number, groupLen: number) {
export enum SEX { export enum SEX {
'男' = 1, '男' = 1,
'女' = 2, '女' = 2,
}
export function getRoundTable<T>(nameList: T[], round: number) {
const list = [...nameList];
const half = list.length / 2;
if (round > list.length - 1) {
const left = [...list].slice(0, half);
const right = [...list].slice(half);
return [left, right];
}
const sliceStart = (list.length) - round;
const slice = list.slice(sliceStart);
// console.debug(JSON.stringify({ list }));
list.splice(sliceStart);
const [first, ...others] = list;
const newList = [first, ...slice, ...others].filter(Boolean);
// console.debug(JSON.stringify({ sliceStart, len: list.length, first, others, slice, newList }));
const left = [...newList].slice(0, half);
const right = [...newList].slice(half).reverse();
return [left, right];
} }