Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
edlouth committed Nov 7, 2023
1 parent 814a93e commit 98e0757
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions grai-frontend/src/components/chat/WebsocketChat.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useState } from "react"
import React, { useCallback, useEffect } from "react"
import { useApolloClient } from "@apollo/client"
import { baseURL } from "client"
import useWebSocket from "react-use-websocket"
Expand Down Expand Up @@ -36,8 +36,6 @@ type WebsocketChatProps = {
}

const WebsocketChat: React.FC<WebsocketChatProps> = ({ workspace, chat }) => {
const [savedLastMessage, setSavedLastMessage] = useState<number | null>(null)

const { cache } = useApolloClient()

const socketUrl = `${socketURL}/ws/chat/${workspace.id}/`
Expand Down Expand Up @@ -69,17 +67,13 @@ const WebsocketChat: React.FC<WebsocketChatProps> = ({ workspace, chat }) => {
)

useEffect(() => {
if (lastMessage !== null) {
const message = lastMessage.timeStamp
if (message !== savedLastMessage) {
addMessage({
message: JSON.parse(lastMessage.data).message,
role: "system",
})
setSavedLastMessage(message)
}
if (lastMessage) {
addMessage({
message: JSON.parse(lastMessage.data).message,
role: "system",
})
}
}, [lastMessage, addMessage, savedLastMessage])
}, [lastMessage, addMessage])

const handleInput = (message: string) => {
const msg = {
Expand Down

0 comments on commit 98e0757

Please sign in to comment.