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 21:43:09 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4f33df40bf9147050fddc8f5d0e7916382cf0447
4f33df40
1 parent
ef87b297
Create 컴포넌트 및 관련 타입 추가
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/rooms/Create.tsx
web/src/components/common/types.ts
View file @
4f33df4
...
...
@@ -12,6 +12,7 @@ export interface RawMessage {
export
const
MessageType
=
{
LOGIN
:
"login"
,
ROOM_LIST_REQUEST
:
"roomList"
,
ROOM_LIST_CREATE
:
"createRoom"
,
ROOM_JOIN
:
"joinRoom"
,
ROOM_LEAVE
:
"leaveRoom"
,
ROOM_USER_UPDATE
:
"updateRoomUser"
,
...
...
web/src/components/rooms/Create.tsx
0 → 100644
View file @
4f33df4
import React, { useCallback, useContext, useState } from 'react';
import SocketContext from '../../contexts/SocketContext';
import { MessageResponse, MessageType, RawMessage } from '../common/types';
import { Room } from './types';
export const Create: React.FC = () => {
const socket = useContext(SocketContext);
const [ roomName, setRoomName ] = useState('');
const createRooms = useCallback(() => {
const rawMessage: RawMessage = {
type: MessageType.ROOM_LIST_CREATE,
message: { name: roomName }
}
socket.emit('msg', rawMessage, (response: MessageResponse<Room[]>) => {
if (response.ok) {
// HOW?
}
});
}, [roomName]);
return (
<div>
<input type="text"
placeholder="Username"
className="px-3 py-1.5 bg-white
placeholder-gray-400 text-gray-700 text-sm
rounded shadow outline-none focus:outline-none"
value={roomName}
onChange={e => setRoomName(e.target.value)}
/>
<button className="bg-green-500 active:bg-green-600
text-white uppercase text-xl
w-10 h-8 pb-0.5 ml-3 rounded shadow round
outline-none focus:outline-none hover:shadow-md
ease-linear transition-all duration-100"
type="button"
onClick={() => createRooms()}>+</button>
</div>
);
}
Please
register
or
login
to post a comment