From c1cf15a67c49a90cecab94a09f31d45c969ad78a Mon Sep 17 00:00:00 2001 From: Ai Date: Fri, 22 May 2026 12:58:26 +0300 Subject: [PATCH] fix: remove fullChat local state, use activeChat directly to prevent desync Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/pages/MainLayout.tsx | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/frontend/src/pages/MainLayout.tsx b/frontend/src/pages/MainLayout.tsx index 157a073..9d2c595 100644 --- a/frontend/src/pages/MainLayout.tsx +++ b/frontend/src/pages/MainLayout.tsx @@ -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([]); 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(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 */}
- {activeChat && fullChat ? ( + {activeChat ? ( <>
{ setMobileChatOpen(false); setActiveChat(null); }} onRefresh={() => openChat(activeChat)} onShowInfo={() => setShowInfo(!showInfo)} @@ -234,7 +228,7 @@ export default function MainLayout() { {/* Info Panel */} {showInfo && ( setShowInfo(false)} onRefresh={() => openChat(activeChat)} />