22
33import { Box , List , Typography } from "@mui/material" ;
44import type { RoomOverview } from "common/types" ;
5- import { useState } from "react" ;
6- // import { useRouter } from "next/navigation";
5+ import { useRouter , useSearchParams } from "next/navigation" ;
76import { HumanListItem } from "~/components/human/humanListItem" ;
87import RoomPage from "./RoomPage" ;
98
@@ -13,14 +12,12 @@ type RoomListProps = {
1312
1413export function RoomList ( props : RoomListProps ) {
1514 const { roomsData } = props ;
16- // const router = useRouter();
17-
18- const [ friendId , setFriendId ] = useState < number | null > ( null ) ;
15+ const router = useRouter ( ) ;
16+ const searchParams = useSearchParams ( ) ;
17+ const friendId = searchParams . get ( "friendId" ) ;
1918
2019 const openRoom = ( room : Extract < RoomOverview , { isDM : true } > ) => {
21- // TODO: room いらん
22- setFriendId ( room . friendId ) ;
23- // router.push(`/chat/${room.friendId}`);
20+ router . push ( `/chat?friendId=${ room . friendId } ` ) ;
2421 } ;
2522
2623 return (
@@ -87,7 +84,6 @@ export function RoomList(props: RoomListProps) {
8784 </ Box >
8885 ) ;
8986 }
90- // if (room.matchingStatus === "matched")
9187 return (
9288 < Box
9389 key = { room . friendId }
@@ -115,17 +111,7 @@ export function RoomList(props: RoomListProps) {
115111 } ) }
116112 </ List >
117113 ) : (
118- < div className = "h-screen w-screen bg-gray-200" >
119- < button
120- type = "button"
121- onClick = { ( ) => {
122- setFriendId ( null ) ;
123- } }
124- >
125- x
126- </ button >
127- < RoomPage id = { friendId } />
128- </ div >
114+ < RoomPage id = { Number . parseInt ( friendId ) } />
129115 ) }
130116 </ >
131117 ) ;
0 commit comments