Skip to content

The Open Standard for Generative UI

fix chat empty condition (#250)

Ankit Dasa39c11662b7a
diff --git a/js/packages/react-ui/package.json b/js/packages/react-ui/package.json
index a52b50d8f..2c28b8a10 100644
--- a/js/packages/react-ui/package.json
+++ b/js/packages/react-ui/package.json
@@ -2,7 +2,7 @@
"type": "module",
"name": "@crayonai/react-ui",
"license": "MIT",
- "version": "0.9.12",
+ "version": "0.9.13",
"description": "Component library for Generative UI SDK",
"main": "dist/index.js",
"types": "dist/index.d.ts",
diff --git a/js/packages/react-ui/src/components/BottomTray/ConversationStarter.tsx b/js/packages/react-ui/src/components/BottomTray/ConversationStarter.tsx
index 267d7da18..345443a79 100644
--- a/js/packages/react-ui/src/components/BottomTray/ConversationStarter.tsx
+++ b/js/packages/react-ui/src/components/BottomTray/ConversationStarter.tsx
@@ -3,6 +3,7 @@ import clsx from "clsx";
import { ArrowUp, Lightbulb } from "lucide-react";
import { Fragment, ReactNode } from "react";
import { ConversationStarterIcon, ConversationStarterProps } from "../../types/ConversationStarter";
+import { isChatEmpty } from "../CrayonChat/utils";
import { Separator } from "../Separator";
export type ConversationStarterVariant = "short" | "long";
@@ -93,7 +94,7 @@ export const ConversationStarter = ({
variant = "short",
}: ConversationStarterContainerProps) => {
const { processMessage } = useThreadActions();
- const { isRunning, messages } = useThreadState();
+ const { isRunning, messages, isLoadingMessages } = useThreadState();
const handleClick = (prompt: string) => {
if (isRunning) return;
@@ -105,7 +106,7 @@ export const ConversationStarter = ({
};
// Only show when there are no messages
- if (messages.length > 0) {
+ if (!isChatEmpty({ isLoadingMessages, messages })) {
return null;
}
diff --git a/js/packages/react-ui/src/components/BottomTray/WelcomeScreen.tsx b/js/packages/react-ui/src/components/BottomTray/WelcomeScreen.tsx
index 8cdb3da24..a1a900a46 100644
--- a/js/packages/react-ui/src/components/BottomTray/WelcomeScreen.tsx
+++ b/js/packages/react-ui/src/components/BottomTray/WelcomeScreen.tsx
@@ -1,6 +1,7 @@
import { useThreadState } from "@crayonai/react-core";
import clsx from "clsx";
import { ReactNode } from "react";
+import { isChatEmpty } from "../CrayonChat/utils";
interface WelcomeScreenBaseProps {
/**
@@ -53,10 +54,10 @@ const isImageUrl = (image: { url: string } | ReactNode): image is { url: string
export const WelcomeScreen = (props: WelcomeScreenProps) => {
const { className } = props;
- const { messages } = useThreadState();
+ const { messages, isLoadingMessages } = useThreadState();
// Only show when there are no messages
- if (messages.length > 0) {
+ if (!isChatEmpty({ isLoadingMessages, messages })) {
return null;
}
diff --git a/js/packages/react-ui/src/components/CopilotShell/ConversationStarter.tsx b/js/packages/react-ui/src/components/CopilotShell/ConversationStarter.tsx
index 5679253af..0587e220d 100644
--- a/js/packages/react-ui/src/components/CopilotShell/ConversationStarter.tsx
+++ b/js/packages/react-ui/src/components/CopilotShell/ConversationStarter.tsx
@@ -3,6 +3,7 @@ import clsx from "clsx";
import { ArrowUp, Lightbulb } from "lucide-react";
import { Fragment, ReactNode } from "react";
import { ConversationStarterIcon, ConversationStarterProps } from "../../types/ConversationStarter";
+import { isChatEmpty } from "../CrayonChat/utils";
import { Separator } from "../Separator";
export type ConversationStarterVariant = "short" | "long";
@@ -93,7 +94,7 @@ export const ConversationStarter = ({
variant = "short",
}: ConversationStarterContainerProps) => {
const { processMessage } = useThreadActions();
- const { isRunning, messages } = useThreadState();
+ const { isRunning, messages, isLoadingMessages } = useThreadState();
const handleClick = (prompt: string) => {
if (isRunning) return;
@@ -105,7 +106,7 @@ export const ConversationStarter = ({
};
// Only show when there are no messages
- if (messages.length > 0) {
+ if (!isChatEmpty({ isLoadingMessages, messages })) {
return null;
}
diff --git a/js/packages/react-ui/src/components/CopilotShell/WelcomeScreen.tsx b/js/packages/react-ui/src/components/CopilotShell/WelcomeScreen.tsx
index b59125eef..cef996027 100644
--- a/js/packages/react-ui/src/components/CopilotShell/WelcomeScreen.tsx
+++ b/js/packages/react-ui/src/components/CopilotShell/WelcomeScreen.tsx
@@ -1,6 +1,7 @@
import { useThreadState } from "@crayonai/react-core";
import clsx from "clsx";
import { ReactNode } from "react";
+import { isChatEmpty } from "../CrayonChat/utils";
interface WelcomeScreenBaseProps {
/**
@@ -53,10 +54,10 @@ const isImageUrl = (image: { url: string } | ReactNode): image is { url: string
export const WelcomeScreen = (props: WelcomeScreenProps) => {
const { className } = props;
- const { messages } = useThreadState();
+ const { messages, isLoadingMessages } = useThreadState();
// Only show when there are no messages
- if (messages.length > 0) {
+ if (!isChatEmpty({ isLoadingMessages, messages })) {
return null;
}
diff --git a/js/packages/react-ui/src/components/CrayonChat/ComposedBottomTray.tsx b/js/packages/react-ui/src/components/CrayonChat/ComposedBottomTray.tsx
index a6f06a2e3..fed9297fb 100644
--- a/js/packages/react-ui/src/components/CrayonChat/ComposedBottomTray.tsx
+++ b/js/packages/react-ui/src/components/CrayonChat/ComposedBottomTray.tsx
@@ -41,7 +41,7 @@ interface ComposedBottomTrayProps {
const WelcomeMessageRenderer = ({ welcomeMessage }: { welcomeMessage?: WelcomeMessageConfig }) => {
const { messages, isLoadingMessages } = useThreadState();
- if (!welcomeMessage || isChatEmpty({ isLoadingMessages, messages })) {
+ if (!welcomeMessage || !isChatEmpty({ isLoadingMessages, messages })) {
return null;
}
@@ -71,7 +71,7 @@ const ConversationStartersRenderer = ({
}) => {
const { messages, isLoadingMessages } = useThreadState();
- if (!conversationStarters || isChatEmpty({ isLoadingMessages, messages })) {
+ if (!conversationStarters || !isChatEmpty({ isLoadingMessages, messages })) {
return null;
}
diff --git a/js/packages/react-ui/src/components/CrayonChat/ComposedCopilot.tsx b/js/packages/react-ui/src/components/CrayonChat/ComposedCopilot.tsx
index 30910f151..9253f7f2f 100644
--- a/js/packages/react-ui/src/components/CrayonChat/ComposedCopilot.tsx
+++ b/js/packages/react-ui/src/components/CrayonChat/ComposedCopilot.tsx
@@ -33,7 +33,7 @@ interface ComposedCopilotProps {
const WelcomeMessageRenderer = ({ welcomeMessage }: { welcomeMessage?: WelcomeMessageConfig }) => {
const { messages, isLoadingMessages } = useThreadState();
- if (!welcomeMessage || isChatEmpty({ isLoadingMessages, messages })) {
+ if (!welcomeMessage || !isChatEmpty({ isLoadingMessages, messages })) {
return null;
}
@@ -63,7 +63,7 @@ const ConversationStartersRenderer = ({
}) => {
const { messages, isLoadingMessages } = useThreadState();
- if (!conversationStarters || isChatEmpty({ isLoadingMessages, messages })) {
+ if (!conversationStarters || !isChatEmpty({ isLoadingMessages, messages })) {
return null;
}
diff --git a/js/packages/react-ui/src/components/CrayonChat/ComposedStandalone.tsx b/js/packages/react-ui/src/components/CrayonChat/ComposedStandalone.tsx
index 61e41b58a..e1815fd05 100644
--- a/js/packages/react-ui/src/components/CrayonChat/ComposedStandalone.tsx
+++ b/js/packages/react-ui/src/components/CrayonChat/ComposedStandalone.tsx
@@ -46,7 +46,7 @@ const WelcomeMessageRenderer = ({
}) => {
const { messages, isLoadingMessages } = useThreadState();
- if (!welcomeMessage || isChatEmpty({ isLoadingMessages, messages })) {
+ if (!welcomeMessage || !isChatEmpty({ isLoadingMessages, messages })) {
return null;
}
@@ -79,7 +79,7 @@ const ConversationStartersRenderer = ({
}) => {
const { messages, isLoadingMessages } = useThreadState();
- if (!conversationStarters || isChatEmpty({ isLoadingMessages, messages })) {
+ if (!conversationStarters || !isChatEmpty({ isLoadingMessages, messages })) {
return null;
}
diff --git a/js/packages/react-ui/src/components/CrayonChat/utils/index.ts b/js/packages/react-ui/src/components/CrayonChat/utils/index.ts
index c0bae27e1..e1abf4b1d 100644
--- a/js/packages/react-ui/src/components/CrayonChat/utils/index.ts
+++ b/js/packages/react-ui/src/components/CrayonChat/utils/index.ts
@@ -33,5 +33,5 @@ export const isChatEmpty = ({
isLoadingMessages: boolean | undefined;
messages: Message[];
}) => {
- return isLoadingMessages || messages.length > 0;
+ return !isLoadingMessages && messages.length === 0;
};
diff --git a/js/packages/react-ui/src/components/Shell/ConversationStarter.tsx b/js/packages/react-ui/src/components/Shell/ConversationStarter.tsx
index 90b9baace..02d463de5 100644
--- a/js/packages/react-ui/src/components/Shell/ConversationStarter.tsx
+++ b/js/packages/react-ui/src/components/Shell/ConversationStarter.tsx
@@ -3,6 +3,7 @@ import clsx from "clsx";
import { ArrowUp, Lightbulb } from "lucide-react";
import { Fragment, ReactNode } from "react";
import { ConversationStarterIcon, ConversationStarterProps } from "../../types/ConversationStarter";
+import { isChatEmpty } from "../CrayonChat/utils";
import { Separator } from "../Separator";
export type ConversationStarterVariant = "short" | "long";
@@ -85,7 +86,7 @@ export const ConversationStarter = ({
variant = "short",
}: ConversationStarterContainerProps) => {
const { processMessage } = useThreadActions();
- const { isRunning, messages } = useThreadState();
+ const { isRunning, messages, isLoadingMessages } = useThreadState();
const handleClick = (prompt: string) => {
if (isRunning) return;
@@ -97,7 +98,7 @@ export const ConversationStarter = ({
};
// Only show when there are no messages
- if (messages.length > 0) {
+ if (!isChatEmpty({ isLoadingMessages, messages })) {
return null;
}
diff --git a/js/packages/react-ui/src/components/Shell/WelcomeScreen.tsx b/js/packages/react-ui/src/components/Shell/WelcomeScreen.tsx
index d02570878..7cc13f1f3 100644
--- a/js/packages/react-ui/src/components/Shell/WelcomeScreen.tsx
+++ b/js/packages/react-ui/src/components/Shell/WelcomeScreen.tsx
@@ -2,6 +2,7 @@ import { useThreadState } from "@crayonai/react-core";
import clsx from "clsx";
import { ReactNode } from "react";
import { ConversationStarterProps } from "../../types/ConversationStarter";
+import { isChatEmpty } from "../CrayonChat/utils";
import { DesktopWelcomeComposer } from "./components";
import { ConversationStarter, ConversationStarterVariant } from "./ConversationStarter";
@@ -66,10 +67,10 @@ const isImageUrl = (image: { url: string } | ReactNode): image is { url: string
export const WelcomeScreen = (props: WelcomeScreenProps) => {
const { className, starters = [], starterVariant = "long" } = props;
- const { messages } = useThreadState();
+ const { messages, isLoadingMessages } = useThreadState();
// Only show when there are no messages
- if (messages.length > 0) {
+ if (!isChatEmpty({ isLoadingMessages, messages })) {
return null;
}