채팅: 가리기 삭제, 100줄이 찬 뒤에도 맨 아래 고정(+새 메시지 수), 이름 줄과 말풍선으로 이름·내용 구분
- 공통 ChatMessage(이름 줄 + 말풍선, 내 말은 오른쪽, 이어 말하면 이름 한 번) — 방 채팅·마피아·라이어 게임, 그림 맞히기 이름 표시 - useStickToBottom: 개수 대신 목록 내용 변화를 보고 맨 아래 유지, 위로 올려 읽는 중엔 그대로, 보내면 다시 맨 아래 - 휴대폰 채팅 버튼의 새 메시지 수도 100줄 뒤에 0이 되던 문제(마지막 본 id 기준으로) - e2e/chat.e2e.ts: PC 대기실·게임 옆 칸·휴대폰 시트 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,8 @@ import type { PublicUser } from '@bg/shared/lite';
|
||||
import { Avatar } from '../../components/ui';
|
||||
import { useServerNow } from '../../components/TurnTimer';
|
||||
import { haptic, sounds } from '../../lib/feedback';
|
||||
import { ChatMessage, sameRun } from '../../components/ChatMessage';
|
||||
import { useStickToBottom } from '../../lib/useStickToBottom';
|
||||
import type { BoardProps, GameUI, OptionsProps } from '../types';
|
||||
import { helpNow } from './help';
|
||||
import { quickStart } from './quick';
|
||||
@@ -117,9 +119,6 @@ button.mf-tile { cursor: pointer; }
|
||||
.mf-tab[data-ch='lovers'][aria-selected='true'] { background: #fce7f3; color: #831843; box-shadow: inset 0 -3px 0 #db2777; }
|
||||
.mf-tab .n { display: inline-block; margin-left: 4px; min-width: 1.4em; border-radius: 999px; background: #dc2626; color: #fff; font-size: .72rem; padding: 0 5px; }
|
||||
.mf-msgs { flex: 1; min-height: 160px; overflow-y: auto; padding: 8px 10px; display: flex; flex-direction: column; gap: 5px; }
|
||||
.mf-msg { line-height: 1.4; overflow-wrap: anywhere; }
|
||||
.mf-msg strong { margin-right: 6px; }
|
||||
.mf-msg.mine strong { color: var(--primary); }
|
||||
.mf-msg.sys { font-size: .86rem; font-weight: 700; color: var(--text-sub); background: var(--surface-2); border-radius: 8px; padding: 3px 8px; }
|
||||
.mf-msg.sys.hot { color: var(--danger); }
|
||||
.mf-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--border); flex-wrap: nowrap; }
|
||||
@@ -391,6 +390,7 @@ function Players({ v, players, me, pick, pending }: { v: MafiaView; players: Rec
|
||||
// ---------------------------------------------------------------- chat
|
||||
|
||||
type Line = ({ k: 'chat'; m: ChatView } | { k: 'sys'; e: PublicEvent }) & { at: number };
|
||||
const runKey = (l: Line | undefined) => l && { from: l.k === 'chat' ? l.m.from : null, at: l.at };
|
||||
|
||||
function ChatBox({ v, players, me, act }: { v: MafiaView; players: Record<string, PublicUser>; me: string | null; act: (a: unknown) => void }) {
|
||||
const tabs = useMemo(() => {
|
||||
@@ -400,7 +400,7 @@ function ChatBox({ v, players, me, act }: { v: MafiaView; players: Record<string
|
||||
const [tab, setTab] = useState<Channel>('day');
|
||||
const [text, setText] = useState('');
|
||||
const [seen, setSeen] = useState<Record<string, number>>({});
|
||||
const listRef = useRef<HTMLDivElement>(null);
|
||||
const { ref: listRef, pin } = useStickToBottom<HTMLDivElement>();
|
||||
const cur: Channel = tabs.includes(tab) ? tab : 'day';
|
||||
// Day → 전체; night → the first private channel I may write in (only on my own screen).
|
||||
const phaseKey = `${v.day}-${v.phase.kind}`;
|
||||
@@ -420,8 +420,8 @@ function ChatBox({ v, players, me, act }: { v: MafiaView; players: Record<string
|
||||
}, [v.chat, v.events, cur]);
|
||||
useEffect(() => {
|
||||
setSeen((s) => ({ ...s, [cur]: count(cur) }));
|
||||
listRef.current?.scrollTo({ top: listRef.current.scrollHeight });
|
||||
}, [cur, v.chat.length, v.events.length]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
useEffect(pin, [cur, pin]);
|
||||
const ch = v.channels.find((c) => c.channel === cur);
|
||||
const canWrite = !!ch?.canWrite;
|
||||
const why = ch ? ch.why : me ? '이 채팅은 읽기만 할 수 있어요.' : '관전 중에는 채팅을 쓸 수 없어요.';
|
||||
@@ -458,16 +458,15 @@ function ChatBox({ v, players, me, act }: { v: MafiaView; players: Record<string
|
||||
</div>
|
||||
<div ref={listRef} className="mf-msgs" role="tabpanel" aria-label={`${CHANNEL_KO[cur]} 채팅 내용`} aria-live="polite" data-channel={cur}>
|
||||
{lines.length === 0 && <p className="muted small" style={{ margin: 0 }}>아직 메시지가 없어요.</p>}
|
||||
{lines.map((l) =>
|
||||
{lines.map((l, i) =>
|
||||
l.k === 'sys' ? (
|
||||
<div key={`e${l.e.n}`} className={`mf-msg sys${l.e.t === 'death' || l.e.t === 'end' ? ' hot' : ''}`}>
|
||||
📢 {eventText(l.e, players)}
|
||||
</div>
|
||||
) : (
|
||||
<div key={l.m.key} className={`mf-msg${l.m.from === me ? ' mine' : ''}`}>
|
||||
<strong>{nick(players, l.m.from)}</strong>
|
||||
<ChatMessage key={l.m.key} className="mf-msg" from={l.m.from} name={nick(players, l.m.from)} mine={l.m.from === me} cont={sameRun(runKey(lines[i - 1]), runKey(l))}>
|
||||
{l.m.text}
|
||||
</div>
|
||||
</ChatMessage>
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
@@ -480,6 +479,7 @@ function ChatBox({ v, players, me, act }: { v: MafiaView; players: Record<string
|
||||
if (!t) return;
|
||||
act({ type: 'chat', channel: cur, text: t.slice(0, 200) });
|
||||
setText('');
|
||||
pin();
|
||||
}}
|
||||
>
|
||||
<input
|
||||
|
||||
Reference in New Issue
Block a user