-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
14 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 10 additions & 45 deletions
55
packages/paste-website/src/components/assistant/LoadingMessage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,20 @@ | ||
/* eslint-disable camelcase */ | ||
import { Box } from "@twilio-paste/box"; | ||
import { ChatBubble, ChatMessage, ChatMessageMeta, ChatMessageMetaItem } from "@twilio-paste/chat-log"; | ||
import { SkeletonLoader } from "@twilio-paste/skeleton-loader"; | ||
import { useUID } from "@twilio-paste/uid-library"; | ||
import { AIChatMessage, AIChatMessageAuthor, AIChatMessageBody, AIChatMessageLoading } from "@twilio-paste/ai-chat-log"; | ||
import * as React from "react"; | ||
|
||
import { Logo } from "../../assets/Logo"; | ||
import { useAssistantRunStore } from "../../stores/assistantRunStore"; | ||
import { formatTimestamp } from "../../utils/formatTimestamp"; | ||
|
||
const getRandomNumber = (max: number): number => { | ||
return Math.floor(Math.random() * max); | ||
}; | ||
|
||
const STATUS_MAP = { | ||
queued: "Queued...", | ||
in_progress: "Researching...", | ||
requires_action: "Researching...", | ||
cancelling: "Concelling...", | ||
cancelled: "Cancelled.", | ||
failed: "Failed.", | ||
completed: "Finished.", | ||
expired: "Expired.", | ||
}; | ||
|
||
export const LoadingMessage: React.FC<{ maxWidth: number }> = ({ maxWidth }) => { | ||
const activeRun = useAssistantRunStore((state) => state.activeRun); | ||
|
||
export const LoadingMessage: React.FC = () => { | ||
const newDateTime = new Date(); | ||
const timestamp = Math.floor(newDateTime.getTime() / 1000); | ||
|
||
const randomWidths = React.useMemo(() => { | ||
return Array.from({ length: 3 }, () => getRandomNumber(maxWidth)); | ||
}, [maxWidth]); | ||
|
||
return ( | ||
<ChatMessage variant="inbound"> | ||
<ChatBubble> | ||
<Box display="grid" rowGap="space30"> | ||
{randomWidths.map((width) => ( | ||
<SkeletonLoader key={useUID()} height="20px" width={`${width}px`} /> | ||
))} | ||
</Box> | ||
</ChatBubble> | ||
<ChatMessageMeta aria-label={`said by the assistant at ${formatTimestamp(timestamp)}`}> | ||
<ChatMessageMetaItem> | ||
<Logo size={20} /> | ||
PasteBot ・ {activeRun?.status ? STATUS_MAP[activeRun?.status] : "Thinking..."} | ||
</ChatMessageMetaItem> | ||
</ChatMessageMeta> | ||
</ChatMessage> | ||
<AIChatMessage variant="bot"> | ||
<AIChatMessageAuthor aria-label={`said by paste assistant at ${formatTimestamp(timestamp)}`}> | ||
PasteBot | ||
</AIChatMessageAuthor> | ||
<AIChatMessageBody> | ||
<AIChatMessageLoading /> | ||
</AIChatMessageBody> | ||
</AIChatMessage> | ||
); | ||
}; | ||
/* eslint-enable camelcase */ |