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-10 06:55:34 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e06fef5408677c3f1aaeb185135e8c91151b7b8f
e06fef54
1 parent
ba5b75f8
UserRole 컴포넌트 추가
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
0 deletions
web/src/components/room/UserRole.tsx
web/src/components/room/UserRole.tsx
0 → 100644
View file @
e06fef5
import React, { useCallback, useContext, useEffect, useState } from 'react';
import SocketContext from '../../contexts/SocketContext';
import { MessageType, RawMessage } from '../common/types';
import { RoleData, RoundData } from './types';
interface UserRoleProps {
isInGame: boolean;
}
export const UserRole: React.FC<UserRoleProps> = ({ isInGame }) => {
const socket = useContext(SocketContext);
const [ roles, setRoles ] = useState<RoleData[]>([]);
const handleRole = useCallback((rawMessage: RawMessage) => {
if (rawMessage.type === MessageType.GAME_START) {
const { roles } = rawMessage.message as RoundData;
setRoles(roles);
}
}, []);
useEffect(() => {
socket.on('msg', handleRole);
return () => {
socket.off('msg', handleRole);
}
}, []);
return (
<div className={`w-40 h-144 rounded shadow flex flex-col items-center ${isInGame ? '' : 'hidden'}`}>
<div className='mt-3' />
{roles.map(x => (
<div key={x.username} className={`my-5 ease-linear transition-all duration-100
${x.role === 'drawer' ? 'text-blue-500'
: x.role === 'winner' ? 'text-green-500'
: 'text-black'}`}>
{x.nickname} {x.role === 'drawer' ? '🖌️' : x.role === 'spectator' ? '👻' : ''}
</div>
))}
</div>
);
}
Please
register
or
login
to post a comment