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-09 18:53:19 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d05606007f56e45a707bbaf77edf397b2742acbe
d0560600
1 parent
e8f0289c
Ready 컴포넌트와 관련 타입 추가
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
0 deletions
web/src/components/common/types.ts
web/src/components/room/Ready.tsx
web/src/components/common/types.ts
View file @
d056060
...
...
@@ -16,4 +16,6 @@ export const MessageType = {
ROOM_LEAVE
:
"leaveRoom"
,
ROOM_USER_UPDATE
:
"updateRoomUser"
,
ROOM_CHAT
:
"chat"
,
ROOM_READY
:
"ready"
,
ROOM_START
:
"startGame"
}
as
const
\ No newline at end of file
...
...
web/src/components/room/Ready.tsx
0 → 100644
View file @
d056060
import React, { useCallback, useContext } from 'react';
import SocketContext from '../../contexts/SocketContext';
import { MessageType, RawMessage } from '../common/types';
interface ReadyProps {
isReady: boolean;
isAdmin: boolean;
isAllReady: boolean;
}
export const Ready: React.FC<ReadyProps> = ({ isReady, isAdmin, isAllReady }) => {
const socket = useContext(SocketContext);
const handleReady = useCallback(() => {
if (isAdmin && isAllReady) {
const rawMessage: RawMessage = {
type: MessageType.ROOM_READY,
message: {}
}
socket.emit('msg', rawMessage, () => {});
} else {
const rawMessage: RawMessage = {
type: MessageType.ROOM_READY,
message: { ready: !isReady }
}
socket.emit('msg', rawMessage, () => {});
}
}, []);
return (
<button className={`${isAdmin ? isAllReady ? 'bg-green-500' : 'bg-gray-400'
: isReady ? 'bg-green-600'
: 'bg-green-500 active:bg-green-600'}
text-white font-bold uppercase text-sm
px-5 py-2 ml-3 rounded shadow
outline-none focus:outline-none hover:shadow-md
ease-linear transition-all duration-100`}
type="button"
onClick={() => {}}>{isAdmin ? 'Start' : 'Ready'}</button>
);
}
Please
register
or
login
to post a comment