fix: remove fullChat local state, use activeChat directly to prevent desync
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Search, Edit, Settings, Shield, Wifi, WifiOff, MessageCircle } from 'lucide-react';
|
||||
import { useStore } from '../store';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { wsClient } from '../api/ws';
|
||||
import api from '../api/client';
|
||||
import Avatar from '../components/Avatar';
|
||||
@@ -17,7 +16,6 @@ import { Chat } from '../types';
|
||||
|
||||
export default function MainLayout() {
|
||||
const { user, chats, activeChat, setActiveChat, connected, onlineUsers, updateChat, setChats } = useStore();
|
||||
const navigate = useNavigate();
|
||||
const [search, setSearch] = useState('');
|
||||
const [searchUsers, setSearchUsers] = useState<any[]>([]);
|
||||
const [showNew, setShowNew] = useState(false);
|
||||
@@ -25,7 +23,6 @@ export default function MainLayout() {
|
||||
const [showInfo, setShowInfo] = useState(false);
|
||||
const [showProfile, setShowProfile] = useState(false);
|
||||
const [mobileChatOpen, setMobileChatOpen] = useState(false);
|
||||
const [fullChat, setFullChat] = useState<Chat | null>(null);
|
||||
|
||||
usePushNotifications(!!user);
|
||||
|
||||
@@ -58,12 +55,10 @@ export default function MainLayout() {
|
||||
const { data } = await api.get(`/api/chats/${chat.id}`);
|
||||
const merged = { ...chat, ...data };
|
||||
setActiveChat(merged);
|
||||
setFullChat(merged);
|
||||
updateChat({ id: chat.id, unreadCount: 0 });
|
||||
wsClient.send('read_messages', { chatId: chat.id });
|
||||
} catch {
|
||||
setActiveChat(chat);
|
||||
setFullChat(chat);
|
||||
setActiveChat({ ...chat, myRole: chat.myRole || chat.role });
|
||||
}
|
||||
setMobileChatOpen(true);
|
||||
setShowInfo(false);
|
||||
@@ -99,7 +94,6 @@ export default function MainLayout() {
|
||||
// fallback: open by direct API call
|
||||
const { data: fullChatData } = await api.get(`/api/chats/${chatData.id}`);
|
||||
setActiveChat(fullChatData);
|
||||
setFullChat(fullChatData);
|
||||
setMobileChatOpen(true);
|
||||
setShowInfo(false);
|
||||
}
|
||||
@@ -212,12 +206,12 @@ export default function MainLayout() {
|
||||
|
||||
{/* Main Chat Area */}
|
||||
<div className={`flex-1 flex flex-col ${!mobileChatOpen ? 'hidden md:flex' : 'flex'}`}>
|
||||
{activeChat && fullChat ? (
|
||||
{activeChat ? (
|
||||
<>
|
||||
<div className="flex flex-1 overflow-hidden">
|
||||
<div className="flex-1 flex flex-col min-w-0">
|
||||
<ChatHeader
|
||||
chat={fullChat}
|
||||
chat={activeChat}
|
||||
onBack={() => { setMobileChatOpen(false); setActiveChat(null); }}
|
||||
onRefresh={() => openChat(activeChat)}
|
||||
onShowInfo={() => setShowInfo(!showInfo)}
|
||||
@@ -234,7 +228,7 @@ export default function MainLayout() {
|
||||
{/* Info Panel */}
|
||||
{showInfo && (
|
||||
<ChatInfoPanel
|
||||
chat={fullChat}
|
||||
chat={activeChat}
|
||||
onClose={() => setShowInfo(false)}
|
||||
onRefresh={() => openChat(activeChat)}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user