Toggle navigation
Toggle navigation
This project
Loading...
Sign in
강동현
/
nodejs-game
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Overnap
2021-06-01 20:50:57 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
69b57319b23b61fc090132805a154797bfcc0bf6
69b57319
1 parent
d5a402e5
방 접속 구현
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
4 deletions
web/src/components/rooms/RoomInfo.tsx
web/src/components/rooms/RoomInfo.tsx
View file @
69b5731
import React from 'react';
import React, { useContext } from 'react';
import { useHistory } from 'react-router';
import SocketContext from '../../contexts/SocketContext';
import { MessageResponse, MessageType } from '../common/types';
import { RoomData } from '../room/types';
import { Room } from './types';
interface RoomProps {
...
...
@@ -6,16 +10,37 @@ interface RoomProps {
}
export const RoomInfo: React.FC<RoomProps> = ({ room }) => {
const history = useHistory();
const socket = useContext(SocketContext);
const joinRoom = () => {
if (room.currentUsers < room.maxUsers) {
socket.emit(MessageType.ROOM_JOIN, (response: MessageResponse<RoomData>) => {
if (response.ok) {
history.push({
pathname: '/' + room.uuid,
state: {roomData: response.result!}
});
} else {
//TODO: 에러 MODAL을 어케띄우지? 하위컴포넌트에서 훅을 쓰면 어떻게 되는지 확인
}
})
} else {
//TODO: 자리 꽉찼다는 MODAL
}
}
return (
<
div
className={`flex items-center place-content-between m-2 w-5/6
<
button
className={`flex items-center place-content-between m-2 w-5/6
${room.currentUsers < room.maxUsers ?
'bg-white active:bg-green-100' :
'bg-gray-200 active:bg-gray-200'}
rounded shadow hover:shadow-md`}>
rounded shadow hover:shadow-md
outline-none focus:outline-none`}
onClick={joinRoom}>
<span className='mt-2 mb-2 ml-3 text-gray-600 text-lg'>{room.name}</span>
<span className='mt-2 mb-2 mr-3 text-gray-500 text-right'>
{room.currentUsers}/{room.maxUsers}
</span>
</
div
>
</
button
>
);
}
...
...
Please
register
or
login
to post a comment