Showing
2 changed files
with
42 additions
and
0 deletions
| ... | @@ -12,6 +12,7 @@ export interface RawMessage { | ... | @@ -12,6 +12,7 @@ export interface RawMessage { |
| 12 | export const MessageType = { | 12 | export const MessageType = { |
| 13 | LOGIN: "login", | 13 | LOGIN: "login", |
| 14 | ROOM_LIST_REQUEST: "roomList", | 14 | ROOM_LIST_REQUEST: "roomList", |
| 15 | + ROOM_LIST_CREATE: "createRoom", | ||
| 15 | ROOM_JOIN: "joinRoom", | 16 | ROOM_JOIN: "joinRoom", |
| 16 | ROOM_LEAVE: "leaveRoom", | 17 | ROOM_LEAVE: "leaveRoom", |
| 17 | ROOM_USER_UPDATE: "updateRoomUser", | 18 | ROOM_USER_UPDATE: "updateRoomUser", | ... | ... |
web/src/components/rooms/Create.tsx
0 → 100644
| 1 | +import React, { useCallback, useContext, useState } from 'react'; | ||
| 2 | +import SocketContext from '../../contexts/SocketContext'; | ||
| 3 | +import { MessageResponse, MessageType, RawMessage } from '../common/types'; | ||
| 4 | +import { Room } from './types'; | ||
| 5 | + | ||
| 6 | +export const Create: React.FC = () => { | ||
| 7 | + const socket = useContext(SocketContext); | ||
| 8 | + const [ roomName, setRoomName ] = useState(''); | ||
| 9 | + | ||
| 10 | + const createRooms = useCallback(() => { | ||
| 11 | + const rawMessage: RawMessage = { | ||
| 12 | + type: MessageType.ROOM_LIST_CREATE, | ||
| 13 | + message: { name: roomName } | ||
| 14 | + } | ||
| 15 | + socket.emit('msg', rawMessage, (response: MessageResponse<Room[]>) => { | ||
| 16 | + if (response.ok) { | ||
| 17 | + // HOW? | ||
| 18 | + } | ||
| 19 | + }); | ||
| 20 | + }, [roomName]); | ||
| 21 | + | ||
| 22 | + return ( | ||
| 23 | + <div> | ||
| 24 | + <input type="text" | ||
| 25 | + placeholder="Username" | ||
| 26 | + className="px-3 py-1.5 bg-white | ||
| 27 | + placeholder-gray-400 text-gray-700 text-sm | ||
| 28 | + rounded shadow outline-none focus:outline-none" | ||
| 29 | + value={roomName} | ||
| 30 | + onChange={e => setRoomName(e.target.value)} | ||
| 31 | + /> | ||
| 32 | + <button className="bg-green-500 active:bg-green-600 | ||
| 33 | + text-white uppercase text-xl | ||
| 34 | + w-10 h-8 pb-0.5 ml-3 rounded shadow round | ||
| 35 | + outline-none focus:outline-none hover:shadow-md | ||
| 36 | + ease-linear transition-all duration-100" | ||
| 37 | + type="button" | ||
| 38 | + onClick={() => createRooms()}>+</button> | ||
| 39 | + </div> | ||
| 40 | + ); | ||
| 41 | +} |
-
Please register or login to post a comment