mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-05 16:02:19 +00:00
Share: sync
This commit is contained in:
parent
72d10a0823
commit
e2dc5a8faf
1 changed files with 15 additions and 2 deletions
|
|
@ -30,7 +30,7 @@ export default function App() {
|
|||
setConnectionStatus("Error: API URL not found")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
let reconnectTimer: number | undefined
|
||||
let socket: WebSocket | null = null
|
||||
|
||||
|
|
@ -62,7 +62,20 @@ export default function App() {
|
|||
console.log("WebSocket message received")
|
||||
try {
|
||||
const data = JSON.parse(event.data) as Message
|
||||
setMessages((prev) => [...prev, data])
|
||||
setMessages((prev) => {
|
||||
// Check if message with this key already exists
|
||||
const existingIndex = prev.findIndex(msg => msg.key === data.key)
|
||||
|
||||
if (existingIndex >= 0) {
|
||||
// Update existing message
|
||||
const updated = [...prev]
|
||||
updated[existingIndex] = data
|
||||
return updated
|
||||
} else {
|
||||
// Add new message
|
||||
return [...prev, data]
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
console.error("Error parsing WebSocket message:", error)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue