diff --git a/main.wasp b/main.wasp index 43bdf22..2c81180 100644 --- a/main.wasp +++ b/main.wasp @@ -124,6 +124,7 @@ entity Chat {=psl team_id Int? team_name String? team_status String? + showLoader Boolean @default(false) user User? @relation(fields: [userId], references: [id]) userId Int? name String? diff --git a/migrations/20231218111917_add_show_loader_column_to_chat_model/migration.sql b/migrations/20231218111917_add_show_loader_column_to_chat_model/migration.sql new file mode 100644 index 0000000..be19786 --- /dev/null +++ b/migrations/20231218111917_add_show_loader_column_to_chat_model/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "Chat" ADD COLUMN "showLoader" BOOLEAN NOT NULL DEFAULT false; diff --git a/src/client/components/ConversationWrapper.tsx b/src/client/components/ConversationWrapper.tsx index e777a5b..b177f2f 100644 --- a/src/client/components/ConversationWrapper.tsx +++ b/src/client/components/ConversationWrapper.tsx @@ -7,6 +7,7 @@ import { useQuery } from "@wasp/queries"; import getConversations from "@wasp/queries/getConversations"; import getChat from "@wasp/queries/getChat"; import { useSocket, useSocketListener } from "@wasp/webSocket"; +import updateExistingChat from "@wasp/actions/updateExistingChat"; import ConversationsList from "./ConversationList"; import Loader from "./Loader"; @@ -26,9 +27,13 @@ export default function ConversationWrapper() { const { data: currentChatDetails, refetch: refetchChat, - }: { data: any; refetch: any } = useQuery(getChat, { - chatId: Number(id), - }); + }: { data: any; refetch: any } = useQuery( + getChat, + { + chatId: Number(id), + }, + { enabled: !!id } + ); const [isSubmitButtonDisabled, setIsSubmitButtonDisabled] = useState(false); const { data: conversations, refetch } = useQuery( getConversations, @@ -53,6 +58,7 @@ export default function ConversationWrapper() { setIsSubmitButtonDisabled( currentChatDetails?.team_status === "inprogress" ); + setIsLoading(currentChatDetails.showLoader); } }, [currentChatDetails]); @@ -85,7 +91,8 @@ export default function ConversationWrapper() { Number(id), userQuery ); - setIsLoading(true); + // setIsLoading(true); + await updateExistingChat({ chat_id: Number(id), showLoader: true }); const teamId = googleRedirectLoginMsg ? Number(id) : // @ts-ignore @@ -100,9 +107,11 @@ export default function ConversationWrapper() { socket.emit("newConversationAdded", response.chat_id); } - setIsLoading(false); + // setIsLoading(false); + await updateExistingChat({ chat_id: Number(id), showLoader: false }); } catch (err: any) { - setIsLoading(false); + // setIsLoading(false); + await updateExistingChat({ chat_id: Number(id), showLoader: false }); console.log("Error: " + err.message); window.alert("Error: Something went wrong. Please try again later."); } diff --git a/src/server/actions.ts b/src/server/actions.ts index ffc715b..359f8b8 100644 --- a/src/server/actions.ts +++ b/src/server/actions.ts @@ -137,9 +137,10 @@ export const addNewConversationToChat: AddNewConversationToChat< type UpdateExistingChatPayload = { chat_id: number; - team_name: string; - team_id: number; - team_status: boolean; + team_name?: string; + team_id?: number; + team_status?: boolean; + showLoader?: boolean; }; export const updateExistingChat: UpdateExistingChat< @@ -149,16 +150,27 @@ export const updateExistingChat: UpdateExistingChat< if (!context.user) { throw new HttpError(401); } - await context.entities.Chat.update({ - where: { - id: args.chat_id, - }, - data: { - team_id: args.team_id, - team_name: args.team_name, - team_status: args.team_status, - }, - }); + if (args.showLoader === true || args.showLoader === false) { + await context.entities.Chat.update({ + where: { + id: args.chat_id, + }, + data: { + showLoader: args.showLoader, + }, + }); + } else { + await context.entities.Chat.update({ + where: { + id: args.chat_id, + }, + data: { + team_id: args.team_id, + team_name: args.team_name, + team_status: args.team_status, + }, + }); + } }; type AgentPayload = {