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-05-31 03:04:11 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4222f9f1c3b02b84865028e2e7e0164016b9c5c4
4222f9f1
1 parent
052635a7
방 목록 갱신 수정
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
11 deletions
web/src/Rooms.tsx
web/src/Rooms.tsx
View file @
4222f9f
import React, { useContext, useEffect, useState } from 'react';
import { RouteComponentProps } from 'react-router';
import { MessageResponse, MessageType } from './Message';
import SocketContext from './SocketContext';
interface
r
oom {
interface
R
oom {
uuid: string;
name: string;
currentUsers: number;
...
...
@@ -11,19 +12,20 @@ interface room {
export const Rooms: React.FC<RouteComponentProps> = ({ history }) => {
const socket = useContext(SocketContext);
const [ rooms, setRooms ] = useState<
r
oom[]>([]);
const [ rooms, setRooms ] = useState<
R
oom[]>([]);
useEffect(
() => {
socket.emit(
'room_list', ({ ok } : { ok: boolean }
) => {
if (ok) {
history.push('/rooms'
);
const refreshRooms =
() => {
socket.emit(
MessageType.ROOM_LIST_REQUEST, (response: MessageResponse<Room[]>
) => {
if (
response.
ok) {
setRooms(response.result!
);
} else {
console.error('login error!'); // TODO: 팝업 에러?
// TODO: 에러 핸들링
console.log("방 목록을 수신하지 못함");
}
}); // TODO: interval마다 emit하거나 새로고침 버튼을 만들자
});
}
// socket.on('')
}, []);
useEffect(refreshRooms, []);
return (
<div>
...
...
@@ -34,4 +36,4 @@ export const Rooms: React.FC<RouteComponentProps> = ({ history }) => {
<footer>footer footer</footer>
</div>
)
}
\ No newline at end of file
}
...
...
Please
register
or
login
to post a comment