From a4fc0d0031fe6e8234b06d2270bc38335dfe5fe8 Mon Sep 17 00:00:00 2001 From: kyuuseiryuu Date: Mon, 16 Feb 2026 15:03:14 +0900 Subject: [PATCH] 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 --- src/components/GroupMember.tsx | 24 ++---------------------- src/utils.ts | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/components/GroupMember.tsx b/src/components/GroupMember.tsx index 11d1610..55d4260 100644 --- a/src/components/GroupMember.tsx +++ b/src/components/GroupMember.tsx @@ -1,6 +1,7 @@ +import { useMemo, useState } from "react"; import { Button, Card, Divider, Drawer, Flex, Space, Table } from "antd"; import type { BasePlayer } from "../types"; -import { useMemo, useState } from "react"; +import { getRoundTable } from "../utils"; import User from "./User"; interface Props { @@ -65,7 +66,6 @@ function BattleTable({ nameList }: { {new Array(list.length - 1).fill(0).map((_, i) => { const [left, right] = getRoundTable(list, i); - console.debug({ left, right }); return ( {left?.map((e, r) => { @@ -86,23 +86,3 @@ function BattleTable({ nameList }: { ); } - -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]; -} \ No newline at end of file diff --git a/src/utils.ts b/src/utils.ts index 552f6c9..e1bf7a6 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -119,4 +119,24 @@ export function sneckGroup(size: number, groupLen: number) { export enum SEX { '男' = 1, '女' = 2, +} + +export function getRoundTable(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]; } \ No newline at end of file