Sincroniza minimização pelo tamanho da janela e zera badge ao ler

This commit is contained in:
esdrasrenan 2025-12-10 21:58:28 -03:00
parent 15a6b5ca87
commit 06b09f3da8

View file

@ -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 = () => {