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 messagesContainerRef = useRef<HTMLDivElement>(null)
|
||||
const messageElementsRef = useRef<Map<string, HTMLDivElement>>(new Map())
|
||||
const hadSessionRef = useRef<boolean>(false)
|
||||
const prevHasSessionRef = useRef<boolean>(false)
|
||||
|
||||
const [isAtBottom, setIsAtBottom] = useState(true)
|
||||
const isAtBottomRef = useRef(true)
|
||||
|
|
@ -279,16 +279,15 @@ export function ChatWidget({ ticketId, ticketRef }: ChatWidgetProps) {
|
|||
return true
|
||||
}, [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(() => {
|
||||
if (hadSessionRef.current && !hasSession) {
|
||||
setIsMinimized(true)
|
||||
// Redimensionar janela para modo minimizado
|
||||
invoke("set_chat_minimized", { ticketId, minimized: true }).catch(err => {
|
||||
console.error("Erro ao minimizar janela automaticamente:", err)
|
||||
const prevHasSession = prevHasSessionRef.current
|
||||
if (prevHasSession && !hasSession) {
|
||||
invoke("close_chat_window", { ticketId }).catch((err) => {
|
||||
console.error("Erro ao fechar janela ao encerrar sessão:", err)
|
||||
})
|
||||
}
|
||||
hadSessionRef.current = hasSession
|
||||
prevHasSessionRef.current = hasSession
|
||||
}, [hasSession, ticketId])
|
||||
|
||||
// Ref para acessar isMinimized dentro do callback sem causar resubscription
|
||||
|
|
@ -347,7 +346,6 @@ export function ChatWidget({ ticketId, ticketRef }: ChatWidgetProps) {
|
|||
})
|
||||
|
||||
setHasSession(result.hasSession)
|
||||
hadSessionRef.current = hadSessionRef.current || result.hasSession
|
||||
setUnreadCount(result.unreadCount ?? 0)
|
||||
setMessages(result.messages.slice(-MAX_MESSAGES_IN_MEMORY))
|
||||
|
||||
|
|
@ -718,6 +716,13 @@ export function ChatWidget({ ticketId, ticketRef }: ChatWidgetProps) {
|
|||
</span>
|
||||
<span className="size-2 rounded-full bg-slate-400" />
|
||||
<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>
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue