Overnap

메세지 인터페이스 추가

import React, { useContext, useState } from 'react';
import { RouteComponentProps } from 'react-router';
import { Footer } from './Footer';
import { MessageResponse } from './Message';
import SocketContext from './SocketContext';
export const Login: React.FC<RouteComponentProps> = ({ history }) => {
......@@ -8,8 +9,8 @@ export const Login: React.FC<RouteComponentProps> = ({ history }) => {
const [ username, setUsername ] = useState("");
const login = () => {
socket.emit('login', username, ({ ok } : { ok: boolean }) => {
if (ok) {
socket.emit('login', username, (response : MessageResponse<null>) => {
if (response.ok) {
history.push('/rooms');
} else {
console.error('login error!'); // TODO: 팝업 에러?
......
export interface MessageResponse<T> {
ok: boolean;
reason?: string;
result?: T;
}
export class MessageType {
static readonly LOGIN = "login";
static readonly ROOM_LIST_REQUEST = "room_list_request";
static readonly ROOM_JOIN = "room_join";
static readonly ROOM_LEAVE = "room_leave";
static readonly ROOM_USER_UPDATE = "room_user_update";
static readonly ROOM_CHAT = "room_chat";
}