fix(web): code review round 1 -- messaging UI critical/high findings
- CRITICAL: draft text and voice-recording state were never isolated per conversation. ConversationView is one long-lived instance reused across every topic (`:topicId` route param change doesn't remount it), so a single `draft` string leaked one conversation's unsent text into whatever conversation was opened next -- and, far more seriously, starting a voice recording in conversation A and then switching to conversation B before hitting send would publish that recording into B: VoiceRecorder keeps its own MediaRecorder running across the switch, but the onSend callback passed to it is a fresh closure over whatever topic is CURRENT when it finally fires. Fixed by keying drafts per topicId and force- resetting `recording` (unmounting VoiceRecorder, which stops its stream) whenever topicId changes. - CRITICAL: the detail/settings panel was completely unreachable below 960px -- it only ever rendered inside `lg:block` (>=1280px, docked) or `md:block lg:hidden` (960-1279px, drawer) wrappers, so tapping the header "i" button below 960px flipped internal state and fired its data queries with zero visible effect. Added the README §1.4-mandated <960px full-page overlay tier, and a small new useMediaQuery hook so the header's "i" button highlight reflects whether the panel is ACTUALLY visible right now instead of being hardcoded to a breakpoint (it was previously always blue at 960-1279px regardless of the drawer's real open state, and always grey at >=1280px despite the panel being permanently docked open there). - CRITICAL (visually confirmed against 1a-desktop-chat.png): messages you send never showed an avatar at all (just an empty spacer) -- every reference screenshot shows your own "我" avatar beside your bubbles the same as the other party's. MessageRow now takes myUserId and renders it. While in there, also moved the failed-send error icon beside the bubble (README: "气泡左侧") instead of below it with the retry text. - CRITICAL: ChatListColumn's search box had no value/onChange at all -- typing into it did nothing. Now filters by contact name; added the search_off/"未找到相关会话" and forum/"暂无会话" empty states README §2.1 calls for, neither of which existed before. - MEDIUM (real Tailwind cascade bug): the selected chat-list row's highlight was being overridden by the unconditional `hover:bg-[...]` class on the same element -- Tailwind emits hover-variant rules after base rules regardless of source order, so hovering an already-selected row visually un-selected it until the mouse moved away. Scoped the hover class to the non-selected branch only. - NavRail: inactive icons used the wrong color token (icon-default #555c65 instead of the spec's #656b74, this app's text-secondary); the unread badge prop was never actually supplied by AppShell, so the badge's otherwise-pixel-correct rendering never appeared in the running app. Fixed both, and gave BottomTabBar's 消息 tab the same real badge (computed once in AppShell from useChatList(), passed to both). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
569f266390
commit
a7da4dc079
@@ -24,6 +24,12 @@ import { useSessionStore } from '@/stores/session';
|
||||
|
||||
interface OutletCtx {
|
||||
onToggleDetail: () => void;
|
||||
/** Whether the detail panel is CURRENTLY shown -- true always at >=1280px (docked, no close
|
||||
* affordance), true/false at 960-1279px depending on the drawer's open state. Drives the header
|
||||
* "i" button's highlight; previously hardcoded to the breakpoint itself (always blue at
|
||||
* 960-1279px regardless of the drawer's real state, always grey at >=1280px despite the panel
|
||||
* being permanently open there) rather than this actual state. */
|
||||
detailVisible: boolean;
|
||||
}
|
||||
|
||||
interface ContextMenuState {
|
||||
@@ -34,14 +40,22 @@ interface ContextMenuState {
|
||||
|
||||
export function ConversationView() {
|
||||
const { topicId } = useParams();
|
||||
const { onToggleDetail } = useOutletContext<OutletCtx>();
|
||||
const { onToggleDetail, detailVisible } = useOutletContext<OutletCtx>();
|
||||
const myUserId = useSessionStore((s) => s.myUserId);
|
||||
const tinode = useTinode();
|
||||
const contacts = useChatList();
|
||||
const contact = contacts.find((c) => c.topic === topicId);
|
||||
const messages = useTopicMessages(topicId);
|
||||
const bootstrap = useBootstrap();
|
||||
const [draft, setDraft] = useState('');
|
||||
// Keyed by topicId, not a single string -- ConversationView is one long-lived instance reused
|
||||
// across every conversation (the route is `:topicId`, React Router doesn't remount on param
|
||||
// change), so a plain single draft leaks the PREVIOUS conversation's unsent text into whichever
|
||||
// one you open next.
|
||||
const [draftByTopic, setDraftByTopic] = useState<Record<string, string>>({});
|
||||
const draft = (topicId && draftByTopic[topicId]) || '';
|
||||
const setDraft = (value: string) => {
|
||||
if (topicId) setDraftByTopic((prev) => ({ ...prev, [topicId]: value }));
|
||||
};
|
||||
const [menu, setMenu] = useState<ContextMenuState | null>(null);
|
||||
const [selectMode, setSelectMode] = useState(false);
|
||||
const [selectedSeqs, setSelectedSeqs] = useState<Set<number>>(new Set());
|
||||
@@ -65,6 +79,14 @@ export function ConversationView() {
|
||||
setSelectedSeqs(new Set());
|
||||
setMenu(null);
|
||||
setReplyTo(null);
|
||||
setForwardMsg(null);
|
||||
setBulkForwardOpen(false);
|
||||
setEmojiOpen(false);
|
||||
// Unmounting VoiceRecorder stops its media stream via its own cleanup effect -- without this,
|
||||
// a recording started in conversation A silently keeps going after navigating to B, and its
|
||||
// onSend callback (re-created every render off the CURRENT topicId) would publish the eventual
|
||||
// recording into B instead of the conversation the user was actually recording in.
|
||||
setRecording(false);
|
||||
}, [topicId]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -263,7 +285,7 @@ export function ConversationView() {
|
||||
<button
|
||||
type="button"
|
||||
onClick={onToggleDetail}
|
||||
className="grid h-9.5 w-9.5 place-items-center rounded-lg text-text-tertiary-1 md:bg-accent-soft-bg md:text-accent lg:bg-transparent lg:text-text-tertiary-1"
|
||||
className={`grid h-9.5 w-9.5 place-items-center rounded-lg ${detailVisible ? 'bg-accent-soft-bg text-accent' : 'text-text-tertiary-1'}`}
|
||||
>
|
||||
<Icon name="info" />
|
||||
</button>
|
||||
@@ -282,6 +304,7 @@ export function ConversationView() {
|
||||
mine={!!myUserId && msg.from === myUserId}
|
||||
isGroup={isGroup}
|
||||
peerName={peerName}
|
||||
myUserId={myUserId}
|
||||
selectMode={selectMode}
|
||||
selected={typeof msg.seq === 'number' && selectedSeqs.has(msg.seq)}
|
||||
onToggleSelect={toggleSelect}
|
||||
@@ -339,7 +362,7 @@ export function ConversationView() {
|
||||
<div className="absolute bottom-full left-0 z-20 mb-2">
|
||||
<EmojiPanel
|
||||
onPick={(emoji) => {
|
||||
setDraft((d) => d + emoji);
|
||||
setDraft(draft + emoji);
|
||||
setEmojiOpen(false);
|
||||
}}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user