Sincroniza minimização pelo tamanho da janela e zera badge ao ler
This commit is contained in:
parent
15a6b5ca87
commit
06b09f3da8
1 changed files with 23 additions and 3 deletions
|
|
@ -127,6 +127,28 @@ export function ChatWidget({ ticketId, ticketRef }: ChatWidgetProps) {
|
||||||
}
|
}
|
||||||
}, [ticketId, isMinimized])
|
}, [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
|
// Selecionar arquivo para anexar
|
||||||
const handleAttach = async () => {
|
const handleAttach = async () => {
|
||||||
if (isUploading || isSending) return
|
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)
|
const unreadIds = messages.filter(m => !m.isFromMachine).map(m => m.id as string)
|
||||||
if (unreadIds.length > 0) {
|
if (unreadIds.length > 0) {
|
||||||
markMachineMessagesRead(ticketId, unreadIds).catch(err => console.error("mark read falhou", err))
|
markMachineMessagesRead(ticketId, unreadIds).catch(err => console.error("mark read falhou", err))
|
||||||
setUnreadCount(0)
|
|
||||||
} else {
|
|
||||||
setUnreadCount(0)
|
|
||||||
}
|
}
|
||||||
|
setUnreadCount(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue