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-06 01:39:57 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5dc8bb3004681189ffcb524634d31fc90b65504c
5dc8bb30
1 parent
7cf85a7e
RoomBlock 컴포넌트 리팩터 (useCallback, 프로토콜 규격)
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
6 deletions
web/src/components/common/types.ts
web/src/components/rooms/RoomBlock.tsx
web/src/components/common/types.ts
View file @
5dc8bb3
...
...
@@ -12,7 +12,7 @@ export interface RawMessage {
export
const
MessageType
=
{
LOGIN
:
"login"
,
ROOM_LIST_REQUEST
:
"roomList"
,
ROOM_JOIN
:
"
room_join
"
,
ROOM_JOIN
:
"
joinRoom
"
,
ROOM_LEAVE
:
"room_leave"
,
ROOM_USER_UPDATE
:
"room_user_update"
,
ROOM_CHAT
:
"room_chat"
,
...
...
web/src/components/rooms/RoomBlock.tsx
View file @
5dc8bb3
import React, { useContext } from 'react';
import React, { useC
allback, useC
ontext } from 'react';
import { useHistory } from 'react-router';
import SocketContext from '../../contexts/SocketContext';
import { MessageResponse, MessageType } from '../common/types';
import { MessageResponse, MessageType
, RawMessage
} from '../common/types';
import { RoomData } from '../room/types';
import { Room } from './types';
...
...
@@ -12,9 +12,13 @@ interface RoomBlockProps {
export const RoomBlock: React.FC<RoomBlockProps> = ({ room }) => {
const history = useHistory();
const socket = useContext(SocketContext);
const joinRoom = () => {
const joinRoom =
useCallback(
() => {
if (room.currentUsers < room.maxUsers) {
socket.emit(MessageType.ROOM_JOIN, (response: MessageResponse<RoomData>) => {
const rawMessage: RawMessage = {
type: MessageType.ROOM_JOIN,
message: { uuid: room.uuid }
}
socket.emit('msg', rawMessage, (response: MessageResponse<RoomData>) => {
if (response.ok) {
history.push({
pathname: '/' + room.uuid,
...
...
@@ -27,7 +31,7 @@ export const RoomBlock: React.FC<RoomBlockProps> = ({ room }) => {
} else {
//TODO: 자리 꽉찼다는 MODAL
}
}
}
, []);
return (
<button className={`flex items-center place-content-between m-2 w-5/6
...
...
Please
register
or
login
to post a comment