Skip to content

Commit

Permalink
feat: 채팅에서 직업 찾아서 보여주기
Browse files Browse the repository at this point in the history
  • Loading branch information
cheonjiyun committed Dec 15, 2024
1 parent 5df76c5 commit 231aa5f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/chat/ChatGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/** @jsxImportSource @emotion/react */
import { css } from '@emotion/react';
import { forwardRef } from 'react';
import { useRecoilState } from 'recoil';

import { roomInfoState } from '../../recoil/roominfo/atom';
import { VariablesCSS } from '../../styles/VariablesCSS';
import { Chat } from '../../type';
import { getPlayerJob } from '../../util/job';
import PlayerChat from '../player/PlayerChat';
import ChatMessage from './ChatMessage';

Expand All @@ -15,9 +18,11 @@ interface PropsType {
export default forwardRef(function ChatGroup(props: PropsType, ref: any) {
const { chats } = props;

const [roomInfo] = useRecoilState(roomInfoState);

return (
<div ref={ref} css={container(props)}>
<PlayerChat job={chats[0].job} />
<PlayerChat job={getPlayerJob(roomInfo.players, chats[0].name)} />
<div css={right(props)}>
<p css={nameText}>{chats[0].name}</p>
{chats.map((chat, idx) => (
Expand Down
5 changes: 5 additions & 0 deletions src/util/job.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Job, Player } from '../type';

export const getPlayerJob = (players: Player[], name: string): Job => {
return players.find(el => el.name == name)?.job || null;
};

0 comments on commit 231aa5f

Please sign in to comment.