-
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
12 changed files
with
441 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { SERVER_ID, CONTENT_TYPE, SERVER_URL } from '../constant'; | ||
import io from 'socket.io-client'; | ||
export const socketLogin = (accessToken: string) => { | ||
const socket = io(`${SERVER_URL}/server`, { | ||
extraHeaders: { | ||
Authorization: `Bearer ${accessToken}`, | ||
serverId: SERVER_ID, | ||
}, | ||
}); | ||
return socket; | ||
}; |
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,54 @@ | ||
import { useEffect } from 'react'; | ||
import { useRecoilState } from 'recoil'; | ||
import { allRoomState } from '../../states/atom'; | ||
import { getAllGameRooms, participateGameRoom } from '../../api'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
const CheckGameRoom = () => { | ||
const token: any = localStorage.getItem('jwt'); | ||
const navigate = useNavigate(); | ||
const [allRooms, setAllRooms] = useRecoilState(allRoomState); | ||
const fetchData = async () => { | ||
try { | ||
const allRoomsData = await getAllGameRooms(token); | ||
setAllRooms(allRoomsData.chats); | ||
} catch (error) { | ||
console.error('데이터 가져오기 오류:', error); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
fetchData(); | ||
}, [allRooms.length]); | ||
|
||
if (allRooms.length === 0) { | ||
return <div>No rooms available or an error occurred.</div>; | ||
} | ||
|
||
const handleParticipate = async (numberOfPeople: number, chatId: any) => { | ||
if (numberOfPeople === 4) { | ||
alert('방이 꽉 찼어요.'); | ||
} else { | ||
await participateGameRoom(chatId, token); | ||
navigate(`/room/${chatId}`); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<button onClick={fetchData}>Refresh Data</button> | ||
{allRooms.map((element, index) => ( | ||
<div | ||
key={index} | ||
onClick={() => handleParticipate(element.users.length, element.id)}> | ||
{element.name} | ||
<div>{element.users.length}</div> | ||
{element.users.length === 4 && <div>Four users in this room</div>} | ||
<div>{element.users[0].id}</div> | ||
</div> | ||
))} | ||
</> | ||
); | ||
}; | ||
|
||
export default CheckGameRoom; |
Oops, something went wrong.