diff --git a/app/(main)/(routes)/matches/(components)/CreateMatchButton/actions.ts b/app/(main)/(routes)/matches/(components)/CreateMatchButton/actions.ts index 93d9623..81175bb 100644 --- a/app/(main)/(routes)/matches/(components)/CreateMatchButton/actions.ts +++ b/app/(main)/(routes)/matches/(components)/CreateMatchButton/actions.ts @@ -5,7 +5,6 @@ import { redirect } from "next/navigation"; import { z } from "zod"; import { serverServices } from "@/lib/services/server"; import { schema } from "@/lib/utils/schema"; -import { matchPlayerInputModalKey } from "../../(routes)/[matchId]/(components)/MatchPlayerInputModal/hooks"; type State = { errors?: { @@ -82,6 +81,5 @@ export async function createMatch( }); revalidatePath("/matches"); - // TODO: refactor - redirect(`/matches/${id}?${matchPlayerInputModalKey}=true`); + redirect(`/matches/${id}`); } diff --git a/app/(main)/(routes)/matches/(routes)/[matchId]/(components)/ChipInputModal/hooks.ts b/app/(main)/(routes)/matches/(routes)/[matchId]/(components)/ChipInputModal/hooks.ts index 5ae2b9e..8e68e77 100644 --- a/app/(main)/(routes)/matches/(routes)/[matchId]/(components)/ChipInputModal/hooks.ts +++ b/app/(main)/(routes)/matches/(routes)/[matchId]/(components)/ChipInputModal/hooks.ts @@ -1,5 +1,5 @@ -import { useQueryControlledModal } from "@/components/Modal"; +import { useDisclosure } from "@/components/Modal"; export const useChipInputModal = () => { - return useQueryControlledModal("chip-input"); + return useDisclosure(); }; diff --git a/app/(main)/(routes)/matches/(routes)/[matchId]/(components)/GameInputModal/hooks.ts b/app/(main)/(routes)/matches/(routes)/[matchId]/(components)/GameInputModal/hooks.ts index 61a4e8f..27e98c7 100644 --- a/app/(main)/(routes)/matches/(routes)/[matchId]/(components)/GameInputModal/hooks.ts +++ b/app/(main)/(routes)/matches/(routes)/[matchId]/(components)/GameInputModal/hooks.ts @@ -1,5 +1,5 @@ -import { useQueryControlledModal } from "@/components/Modal"; +import { useDisclosure } from "@/components/Modal"; export const useGameInputModal = () => { - return useQueryControlledModal("game-input"); + return useDisclosure(); }; diff --git a/app/(main)/(routes)/matches/(routes)/[matchId]/(components)/MatchPlayerInputButton/index.tsx b/app/(main)/(routes)/matches/(routes)/[matchId]/(components)/MatchPlayerInputButton/index.tsx index 1e6cd56..da303e2 100644 --- a/app/(main)/(routes)/matches/(routes)/[matchId]/(components)/MatchPlayerInputButton/index.tsx +++ b/app/(main)/(routes)/matches/(routes)/[matchId]/(components)/MatchPlayerInputButton/index.tsx @@ -1,9 +1,9 @@ "use client"; import { Button, ButtonProps } from "@/components/Button"; -import { useMatchPlayerInputModal } from "../MatchPlayerInputModal/hooks"; +import { useDisclosure } from "@/components/Modal"; export function MatchPlayerInputButton(props: Omit) { - const { onOpen } = useMatchPlayerInputModal(); + const { onOpen } = useDisclosure(); return ; } diff --git a/app/(main)/(routes)/matches/(routes)/[matchId]/(components)/RuleModal/index.tsx b/app/(main)/(routes)/matches/(routes)/[matchId]/(components)/RuleModal/index.tsx index e0a4b26..30b9c3b 100644 --- a/app/(main)/(routes)/matches/(routes)/[matchId]/(components)/RuleModal/index.tsx +++ b/app/(main)/(routes)/matches/(routes)/[matchId]/(components)/RuleModal/index.tsx @@ -7,13 +7,13 @@ import { ModalContent, ModalFooter, ModalHeader, - useQueryControlledModal, + useDisclosure, } from "@/components/Modal"; import { calcMethodLabel, chipRateLabel, rateLabel } from "@/lib/config"; import { Rule } from "@/lib/type"; export const useRuleModal = () => { - return useQueryControlledModal("rule"); + return useDisclosure(); }; export function RuleModal({ rule }: { rule: Rule }) { diff --git a/app/(main)/(routes)/matches/(routes)/[matchId]/page.tsx b/app/(main)/(routes)/matches/(routes)/[matchId]/page.tsx index 29bf16e..4d1dace 100644 --- a/app/(main)/(routes)/matches/(routes)/[matchId]/page.tsx +++ b/app/(main)/(routes)/matches/(routes)/[matchId]/page.tsx @@ -18,7 +18,7 @@ export default async function Match({ params: { matchId: string }; }) { const { getMatch } = serverServices(); - const [match] = await Promise.all([getMatch({ matchId })]); + const match = await getMatch({ matchId }); const { createdAt } = match; @@ -29,6 +29,9 @@ export default async function Match({ ? dayjs(createdAt).format("M/D") : dayjs(createdAt).format("YYYY/M/D"); + // プレイヤー入力モーダルを初期状態で開くかどうか + const isMatchPlayerInputModalDefaultOpen = match.players.length <= 1; + return (
@@ -54,7 +57,10 @@ export default async function Match({ - + diff --git a/components/Modal/index.tsx b/components/Modal/index.tsx index cd2564a..f100a10 100644 --- a/components/Modal/index.tsx +++ b/components/Modal/index.tsx @@ -1,8 +1,3 @@ -"use client"; - -import { usePathname, useRouter, useSearchParams } from "next/navigation"; -import { useCallback } from "react"; - export { Modal, ModalContent, @@ -12,27 +7,28 @@ export { useDisclosure, } from "@nextui-org/react"; -export const useQueryControlledModal = (key: string) => { - const searchParams = useSearchParams(); - const pathname = usePathname(); - const router = useRouter(); - const isOpen = searchParams.get(key) === "true"; +// パフォーマンスが悪いので使わない +// export const useQueryControlledModal = (key: string) => { +// const searchParams = useSearchParams(); +// const pathname = usePathname(); +// const router = useRouter(); +// const isOpen = searchParams.get(key) === "true"; - const onOpen = useCallback(() => { - const params = new URLSearchParams(searchParams); - params.set(key, "true"); - router.push(`${pathname}?${params.toString()}`); - }, [key, pathname, router, searchParams]); +// const onOpen = useCallback(() => { +// const params = new URLSearchParams(searchParams); +// params.set(key, "true"); +// router.push(`${pathname}?${params.toString()}`); +// }, [key, pathname, router, searchParams]); - const onClose = useCallback(() => { - const params = new URLSearchParams(searchParams); - params.delete(key); - router.push(`${pathname}?${params.toString()}`); - }, [key, pathname, router, searchParams]); +// const onClose = useCallback(() => { +// const params = new URLSearchParams(searchParams); +// params.delete(key); +// router.push(`${pathname}?${params.toString()}`); +// }, [key, pathname, router, searchParams]); - return { - isOpen, - onOpen, - onClose, - }; -}; +// return { +// isOpen, +// onOpen, +// onClose, +// }; +// };