Rooms.tsx 1.02 KB
import React, { useContext, useEffect, useState } from 'react';
import { RouteComponentProps } from 'react-router';
import type { MessageResponse, MessageType } from '../components/common/types';
import SocketContext from '../contexts/SocketContext';

interface Room {
  uuid: string;
  name: string;
  currentUsers: number;
  maxUsers: number;
}

export const Rooms: React.FC<RouteComponentProps> = ({ history }) => {
  const socket = useContext(SocketContext);
  const [ rooms, setRooms ] = useState<Room[]>([]);

  const refreshRooms = () => {
    socket.emit("room_list_request", (response: MessageResponse<Room[]>) => {
      if (response.ok) {
        setRooms(response.result!);
      } else {
        // TODO: 에러 핸들링
        console.log("방 목록을 수신하지 못함");
      }
    });
  }

  useEffect(refreshRooms, []);

  return (
    <div>
      <header>header header</header>
      <div className='flex items-center'>
        <div>room test</div>
      </div>
      <footer>footer footer</footer>
    </div>
  )
}