diff --git a/src/client/components/ConversationWrapper.tsx b/src/client/components/ConversationWrapper.tsx index a640ae6..dc9f7af 100644 --- a/src/client/components/ConversationWrapper.tsx +++ b/src/client/components/ConversationWrapper.tsx @@ -7,7 +7,6 @@ import { useQuery } from "@wasp/queries"; import updateConversation from "@wasp/actions/updateConversation"; import getAgentResponse from "@wasp/actions/getAgentResponse"; import getConversations from "@wasp/queries/getConversations"; -import { useSocket, useSocketListener } from "@wasp/webSocket"; import ConversationsList from "./ConversationList"; import Loader from "./Loader"; @@ -42,16 +41,8 @@ export default function ConversationWrapper() { // @ts-ignore const { id } = useParams(); const [isLoading, setIsLoading] = useState(false); - // const { socket, isConnected } = useSocket(); - // const { refreshChatUI, setRefreshChatUI } = useState(false); const chatContainerRef = useRef(null); - // useSocketListener("updateChatUI", updateChatUI); - - // function updateChatUI() { - // setRefreshChatUI(true); - // } - const loginMsgQuery: any = getQueryParam("msg"); const formInputRef = useCallback( (node: any) => { @@ -80,7 +71,7 @@ export default function ConversationWrapper() { { chatId: Number(id), }, - { enabled: !!id } + { enabled: !!id, refetchInterval: 1000 } ); useEffect(() => { diff --git a/src/server/actions.ts b/src/server/actions.ts index add01ad..d56c030 100644 --- a/src/server/actions.ts +++ b/src/server/actions.ts @@ -13,6 +13,8 @@ import type { import type { StripePaymentResult, OpenAIResponse } from "./types"; import Stripe from "stripe"; +import { ADS_SERVER_URL } from "./config.js"; + const stripe = new Stripe(process.env.STRIPE_KEY!, { apiVersion: "2022-11-15", }); @@ -20,9 +22,6 @@ const stripe = new Stripe(process.env.STRIPE_KEY!, { // WASP_WEB_CLIENT_URL will be set up by Wasp when deploying to production: https://wasp-lang.dev/docs/deploying const DOMAIN = process.env.WASP_WEB_CLIENT_URL || "http://localhost:3000"; -// Python ADS_SERVER_URL -const ADS_SERVER_URL = process.env.ADS_SERVER_URL || "http://127.0.0.1:9000"; - export const stripePayment: StripePayment = async ( _args, context diff --git a/src/server/config.js b/src/server/config.js new file mode 100644 index 0000000..80ad453 --- /dev/null +++ b/src/server/config.js @@ -0,0 +1,2 @@ +export const ADS_SERVER_URL = + process.env.ADS_SERVER_URL || "http://127.0.0.1:9000"; diff --git a/src/server/webSocket.js b/src/server/webSocket.js index eef1350..05b25ae 100644 --- a/src/server/webSocket.js +++ b/src/server/webSocket.js @@ -1,6 +1,6 @@ import HttpError from "@wasp/core/HttpError.js"; -const ADS_SERVER_URL = process.env.ADS_SERVER_URL || "http://127.0.0.1:9000"; +import { ADS_SERVER_URL } from "./config.js"; export const webSocketFn = (io, context) => { io.on("connection", async (socket) => { @@ -9,9 +9,9 @@ export const webSocketFn = (io, context) => { console.log("========"); console.log("a user connected: ", userEmail); - // Check for updates every 5 seconds + // Check for updates every 3 seconds const updateInterval = setInterval(async () => { - console.log("Check for inprogress tasks update"); + console.log("Checking database for inprogress tasks"); const conversations = await context.entities.Conversation.findMany({ where: { userId: socket.data.user.id, status: "inprogress" }, }); @@ -57,14 +57,12 @@ export const webSocketFn = (io, context) => { status: conversation_status, }, }); - - // io.emit("updateChatUI"); } } catch (error) { throw new HttpError(500, error); } }); - }, 5000); + }, 3000); } }); };