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 22:44:33 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
cabd5c1c89fd3e96b627ae63c3511ca9a81b154d
cabd5c1c
2 parents
723137f5
a2963379
Merge branch 'feature/rooms-buttons' into develop
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
0 deletions
web/src/components/common/types.ts
web/src/components/rooms/Create.tsx
web/src/components/rooms/Refrsh.tsx
web/src/pages/Rooms.tsx
web/src/components/common/types.ts
View file @
cabd5c1
...
...
@@ -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 @
cabd5c1
import React, { useCallback, useContext, useState } from 'react';
import { useHistory, useLocation } from 'react-router-dom';
import SocketContext from '../../contexts/SocketContext';
import { MessageResponse, MessageType, RawMessage } from '../common/types';
import { RoomData } from '../room/types';
import { Room } from './types';
interface CreateLocation {
state: { username: string }
}
export const Create: React.FC = () => {
const history = useHistory();
const socket = useContext(SocketContext);
const [ roomName, setRoomName ] = useState('');
const location: CreateLocation = useLocation();
const createRooms = useCallback(() => {
const rawMessage: RawMessage = {
type: MessageType.ROOM_LIST_CREATE,
message: { name: roomName }
}
socket.emit('msg', rawMessage, (response: MessageResponse<RoomData>) => {
if (response.ok) {
history.push({
pathname: '/' + response.result!.uuid,
state: {
username: location.state.username,
roomData: response.result!
}
});
} else {
console.log('방 생성 오류');
}
});
}, [roomName]);
return (
<div className="flex items-center">
<input type="text"
placeholder="Room name"
className="h-8 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>
);
}
web/src/components/rooms/Refrsh.tsx
0 → 100644
View file @
cabd5c1
import React from 'react';
interface RefreshProps {
refreshRooms: () => void
}
export const Refresh: React.FC<RefreshProps> = ({ refreshRooms }) => {
return (
<button className="bg-green-500 active:bg-green-600
text-white uppercase text-xl
w-10 h-8 pb-0.5 mr-2 rounded shadow round
outline-none focus:outline-none hover:shadow-md
ease-linear transition-all duration-100"
type="button"
onClick={() => refreshRooms()}>⟳</button>
);
}
web/src/pages/Rooms.tsx
View file @
cabd5c1
...
...
@@ -2,6 +2,8 @@ import React, { useCallback, useContext, useEffect, useState } from 'react';
import { useHistory } from 'react-router';
import { Main } from '../components/common/Main';
import { MessageResponse, MessageType, RawMessage } from '../components/common/types';
import { Create } from '../components/rooms/Create';
import { Refresh } from '../components/rooms/Refrsh';
import { RoomBlock } from '../components/rooms/RoomBlock';
import { Room } from '../components/rooms/types';
import SocketContext from '../contexts/SocketContext';
...
...
@@ -30,6 +32,10 @@ export const Rooms: React.FC = () => {
return (
<Main>
<div className='mt-8 flex'>
<Refresh refreshRooms={refreshRooms}/>
<Create />
</div>
<div className='mt-auto w-screen flex flex-col items-center'>
{rooms.map((room) => (<RoomBlock key={room.uuid} room={room} />))}
</div>
...
...
Please
register
or
login
to post a comment