From 06b09f3da8a1cc9821d81e7f46bd0f6dd3456be8 Mon Sep 17 00:00:00 2001 From: esdrasrenan Date: Wed, 10 Dec 2025 21:58:28 -0300 Subject: [PATCH] =?UTF-8?q?Sincroniza=20minimiza=C3=A7=C3=A3o=20pelo=20tam?= =?UTF-8?q?anho=20da=20janela=20e=20zera=20badge=20ao=20ler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/desktop/src/chat/ChatWidget.tsx | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/chat/ChatWidget.tsx b/apps/desktop/src/chat/ChatWidget.tsx index 8441c0d..aaa5c9a 100644 --- a/apps/desktop/src/chat/ChatWidget.tsx +++ b/apps/desktop/src/chat/ChatWidget.tsx @@ -127,6 +127,28 @@ export function ChatWidget({ ticketId, ticketRef }: ChatWidgetProps) { } }, [ticketId, isMinimized]) + // Sincroniza estado de minimizado com o tamanho da janela (Tauri pode alterar por fora) + useEffect(() => { + const handler = () => { + const h = window.innerHeight + // thresholds alinhados com set_chat_minimized (52px minimizado, 520px expandido) + setIsMinimized(h < 100) + } + window.addEventListener("resize", handler) + handler() + return () => window.removeEventListener("resize", handler) + }, []) + + // Quando expandir, marcar mensagens como lidas e limpar badge + useEffect(() => { + if (isMinimized) return + const unreadIds = messages.filter(m => !m.isFromMachine).map(m => m.id as string) + if (unreadIds.length > 0) { + markMachineMessagesRead(ticketId, unreadIds).catch(err => console.error("mark read falhou", err)) + } + setUnreadCount(0) + }, [isMinimized, messages, ticketId]) + // Selecionar arquivo para anexar const handleAttach = async () => { if (isUploading || isSending) return @@ -231,10 +253,8 @@ export function ChatWidget({ ticketId, ticketRef }: ChatWidgetProps) { const unreadIds = messages.filter(m => !m.isFromMachine).map(m => m.id as string) if (unreadIds.length > 0) { markMachineMessagesRead(ticketId, unreadIds).catch(err => console.error("mark read falhou", err)) - setUnreadCount(0) - } else { - setUnreadCount(0) } + setUnreadCount(0) } const handleClose = () => {