desktop: fechar chat ao encerrar sessao
This commit is contained in:
parent
ce5ea5dad5
commit
5df68c3917
1 changed files with 14 additions and 9 deletions
|
|
@ -242,7 +242,7 @@ export function ChatWidget({ ticketId, ticketRef }: ChatWidgetProps) {
|
||||||
const messagesEndRef = useRef<HTMLDivElement>(null)
|
const messagesEndRef = useRef<HTMLDivElement>(null)
|
||||||
const messagesContainerRef = useRef<HTMLDivElement>(null)
|
const messagesContainerRef = useRef<HTMLDivElement>(null)
|
||||||
const messageElementsRef = useRef<Map<string, HTMLDivElement>>(new Map())
|
const messageElementsRef = useRef<Map<string, HTMLDivElement>>(new Map())
|
||||||
const hadSessionRef = useRef<boolean>(false)
|
const prevHasSessionRef = useRef<boolean>(false)
|
||||||
|
|
||||||
const [isAtBottom, setIsAtBottom] = useState(true)
|
const [isAtBottom, setIsAtBottom] = useState(true)
|
||||||
const isAtBottomRef = useRef(true)
|
const isAtBottomRef = useRef(true)
|
||||||
|
|
@ -279,16 +279,15 @@ export function ChatWidget({ ticketId, ticketRef }: ChatWidgetProps) {
|
||||||
return true
|
return true
|
||||||
}, [updateIsAtBottom])
|
}, [updateIsAtBottom])
|
||||||
|
|
||||||
// Auto-minimizar quando a sessão termina (hasSession muda de true para false)
|
// Quando a sessão termina (hasSession muda de true -> false), fechar a janela para não ficar "Offline" preso
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (hadSessionRef.current && !hasSession) {
|
const prevHasSession = prevHasSessionRef.current
|
||||||
setIsMinimized(true)
|
if (prevHasSession && !hasSession) {
|
||||||
// Redimensionar janela para modo minimizado
|
invoke("close_chat_window", { ticketId }).catch((err) => {
|
||||||
invoke("set_chat_minimized", { ticketId, minimized: true }).catch(err => {
|
console.error("Erro ao fechar janela ao encerrar sessão:", err)
|
||||||
console.error("Erro ao minimizar janela automaticamente:", err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
hadSessionRef.current = hasSession
|
prevHasSessionRef.current = hasSession
|
||||||
}, [hasSession, ticketId])
|
}, [hasSession, ticketId])
|
||||||
|
|
||||||
// Ref para acessar isMinimized dentro do callback sem causar resubscription
|
// Ref para acessar isMinimized dentro do callback sem causar resubscription
|
||||||
|
|
@ -347,7 +346,6 @@ export function ChatWidget({ ticketId, ticketRef }: ChatWidgetProps) {
|
||||||
})
|
})
|
||||||
|
|
||||||
setHasSession(result.hasSession)
|
setHasSession(result.hasSession)
|
||||||
hadSessionRef.current = hadSessionRef.current || result.hasSession
|
|
||||||
setUnreadCount(result.unreadCount ?? 0)
|
setUnreadCount(result.unreadCount ?? 0)
|
||||||
setMessages(result.messages.slice(-MAX_MESSAGES_IN_MEMORY))
|
setMessages(result.messages.slice(-MAX_MESSAGES_IN_MEMORY))
|
||||||
|
|
||||||
|
|
@ -718,6 +716,13 @@ export function ChatWidget({ ticketId, ticketRef }: ChatWidgetProps) {
|
||||||
</span>
|
</span>
|
||||||
<span className="size-2 rounded-full bg-slate-400" />
|
<span className="size-2 rounded-full bg-slate-400" />
|
||||||
<span className="text-xs text-slate-500">Offline</span>
|
<span className="text-xs text-slate-500">Offline</span>
|
||||||
|
<button
|
||||||
|
onClick={handleClose}
|
||||||
|
className="ml-1 rounded-full p-1 text-slate-600 hover:bg-slate-300/60"
|
||||||
|
title="Fechar"
|
||||||
|
>
|
||||||
|
<X className="size-4" />
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue