-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
536 additions
and
313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
app/(app)/matches/[matchId]/MatchPlayerInputModal/AnonymousPlayerSelect.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"use client"; | ||
|
||
import { usePathname, useRouter, useSearchParams } from "next/navigation"; | ||
import { useEffect } from "react"; | ||
import { useFormState } from "react-dom"; | ||
import { Avatar } from "~/components/Avatar"; | ||
import { Button } from "~/components/Button"; | ||
import { Input } from "~/components/Input"; | ||
import { NAME_MAX_LENGTH } from "~/lib/utils/schemas"; | ||
import { addAnonymousPlayer } from "./actions"; | ||
|
||
export function AnonymousPlayerSelect({ matchId }: { matchId: string }) { | ||
const searchParams = useSearchParams(); | ||
const pathname = usePathname(); | ||
const router = useRouter(); | ||
|
||
const [{ errors, success }, formAction] = useFormState( | ||
addAnonymousPlayer.bind(null, matchId), | ||
{ | ||
success: false, | ||
}, | ||
); | ||
|
||
// TODO: 見直し。サーバー側でできないか | ||
useEffect(() => { | ||
if (success) { | ||
const params = new URLSearchParams(searchParams); | ||
params.delete("mode"); | ||
router.replace(`${pathname}?${params.toString()}`); | ||
} | ||
}, [pathname, router, searchParams, success]); | ||
|
||
return ( | ||
<form className="pt-1" action={formAction} noValidate> | ||
<div className="flex gap-3"> | ||
<Avatar className="mt-2 shrink-0" /> | ||
<Input | ||
name="name" | ||
type="text" | ||
placeholder="プレイヤー名を入力してください" | ||
maxLength={NAME_MAX_LENGTH} | ||
errorMessage={errors?.name} | ||
/> | ||
</div> | ||
<Button className="mt-4" fullWidth type="submit" color="primary"> | ||
決定 | ||
</Button> | ||
</form> | ||
); | ||
} |
25 changes: 25 additions & 0 deletions
25
app/(app)/matches/[matchId]/MatchPlayerInputModal/ModalController.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"use client"; | ||
|
||
import { usePathname, useRouter, useSearchParams } from "next/navigation"; | ||
import { useCallback } from "react"; | ||
import { Modal, ModalContent } from "~/components/Modal"; | ||
|
||
export function ModalController({ children }: { children: React.ReactNode }) { | ||
const searchParams = useSearchParams(); | ||
const pathname = usePathname(); | ||
const router = useRouter(); | ||
const mode = searchParams.get("mode"); | ||
const isOpen = mode === "player-add"; | ||
|
||
const handleClose = useCallback(() => { | ||
const params = new URLSearchParams(searchParams); | ||
params.delete("mode"); | ||
router.replace(`${pathname}?${params.toString()}`); | ||
}, [pathname, router, searchParams]); | ||
|
||
return ( | ||
<Modal isOpen={isOpen} onClose={handleClose} hideCloseButton> | ||
<ModalContent>{children}</ModalContent> | ||
</Modal> | ||
); | ||
} |
29 changes: 29 additions & 0 deletions
29
app/(app)/matches/[matchId]/MatchPlayerInputModal/Tabs.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"use client"; | ||
|
||
import { Tab, Tabs } from "~/components/Tabs"; | ||
|
||
export function PlayerTypeTabs({ | ||
userTab, | ||
anonymousTab, | ||
}: { | ||
userTab: React.ReactNode; | ||
anonymousTab: React.ReactNode; | ||
}) { | ||
return ( | ||
<Tabs | ||
classNames={{ | ||
panel: "min-h-0", | ||
}} | ||
fullWidth | ||
radius="lg" | ||
aria-label="プレイヤー選択の選択肢" | ||
> | ||
<Tab key="friends" title="ユーザー"> | ||
{userTab} | ||
</Tab> | ||
<Tab key="anonymous" title="一般"> | ||
{anonymousTab} | ||
</Tab> | ||
</Tabs> | ||
); | ||
} |
129 changes: 129 additions & 0 deletions
129
app/(app)/matches/[matchId]/MatchPlayerInputModal/UserSelect.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
"use client"; | ||
|
||
import { usePathname, useRouter, useSearchParams } from "next/navigation"; | ||
import { useCallback, useRef } from "react"; | ||
import { useFormState, useFormStatus } from "react-dom"; | ||
import { useDebouncedCallback } from "use-debounce"; | ||
import { Icon } from "~/components/Icon"; | ||
import { Input } from "~/components/Input"; | ||
import { ScrollShadow } from "~/components/ScrollShadow"; | ||
import { User } from "~/components/User"; | ||
import { addUserPlayer, searchProfiles } from "./actions"; | ||
|
||
export function UserSelect({ | ||
matchId, | ||
friends, | ||
playerIds, | ||
}: { | ||
matchId: string; | ||
friends: { id: string; name: string; janrecoId: string }[]; | ||
playerIds: string[]; | ||
}) { | ||
const searchParams = useSearchParams(); | ||
const pathname = usePathname(); | ||
const router = useRouter(); | ||
const formRef = useRef<HTMLFormElement>(null); | ||
|
||
const selectableFriends = friends.filter( | ||
(friend) => !playerIds.includes(friend.id), | ||
); | ||
|
||
const [{ profiles }, formAction] = useFormState(searchProfiles, {}); | ||
|
||
const handleChange = useDebouncedCallback(() => { | ||
formRef.current?.requestSubmit(); | ||
}, 300); | ||
|
||
const selectUser = useCallback( | ||
(profileId: string) => { | ||
// TODO: await中の表示 | ||
addUserPlayer({ matchId, profileId }); | ||
// TODO: server側でredirectしてもいいかも | ||
const params = new URLSearchParams(searchParams); | ||
params.delete("mode"); | ||
router.replace(`${pathname}?${params.toString()}`); | ||
}, | ||
[matchId, pathname, router, searchParams], | ||
); | ||
|
||
return ( | ||
<form className="flex h-full flex-col" ref={formRef} action={formAction}> | ||
<Input | ||
className="mb-3" | ||
size="sm" | ||
name="text" | ||
placeholder="ユーザーIDもしくは名前で検索" | ||
startContent={<Icon className="size-5 fill-current" name="search" />} | ||
onChange={handleChange} | ||
/> | ||
<ScrollShadow className="min-h-0"> | ||
{!!profiles && ( | ||
<ProfileList profiles={selectableFriends} onSelect={selectUser} /> | ||
)} | ||
{!profiles && !!friends.length && ( | ||
<> | ||
<p className="mb-2 text-small text-foreground-light"> | ||
フレンドから選ぶ | ||
</p> | ||
<ul className="space-y-1"> | ||
{selectableFriends.map((friend) => ( | ||
<li className="py-1" key={friend.id}> | ||
{/* TODO: ripple */} | ||
<button type="button" onClick={() => selectUser(friend.id)}> | ||
<User name={friend.name} janrecoId={friend.janrecoId} /> | ||
</button> | ||
</li> | ||
))} | ||
</ul> | ||
</> | ||
)} | ||
</ScrollShadow> | ||
</form> | ||
); | ||
} | ||
|
||
function ProfileList({ | ||
profiles, | ||
onSelect, | ||
}: { | ||
profiles: { id: string; name: string; janrecoId: string }[]; | ||
onSelect: (profileId: string) => void; | ||
}) { | ||
const { pending } = useFormStatus(); | ||
|
||
if (pending) { | ||
return ( | ||
<ul className="space-y-1"> | ||
{Array.from({ length: 1 }).map((_, i) => ( | ||
<li | ||
key={`search-profiles-${i}`} | ||
className="flex items-center justify-between py-2" | ||
> | ||
<User skeleton /> | ||
</li> | ||
))} | ||
</ul> | ||
); | ||
} | ||
|
||
if (!profiles.length) { | ||
return ( | ||
<p className="mt-10 text-center text-small text-foreground-light"> | ||
見つかりませんでした | ||
</p> | ||
); | ||
} | ||
|
||
return ( | ||
<ul className="space-y-1"> | ||
{profiles.map((profile) => ( | ||
<li key={profile.id} className="py-1"> | ||
{/* TODO: ripple, 共通化, 連打対策 */} | ||
<button type="button" onClick={() => onSelect(profile.id)}> | ||
<User name={profile.name} janrecoId={profile.janrecoId} /> | ||
</button> | ||
</li> | ||
))} | ||
</ul> | ||
); | ||
} |
Oops, something went wrong.