From e1cdce70f0aa893fab1059896de5a088eb9c16f2 Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Fri, 23 May 2025 00:48:16 +0600 Subject: [PATCH] feat: show loading status --- .../RoadmapAIChat/RoadmapAIChat.tsx | 8 ++++-- .../RoadmapAIChat/UserProgressActionList.tsx | 18 +++++++++---- src/lib/render-chat-message.tsx | 25 ++++++++++++++++--- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/components/RoadmapAIChat/RoadmapAIChat.tsx b/src/components/RoadmapAIChat/RoadmapAIChat.tsx index 0f84f8a82..08b0449a7 100644 --- a/src/components/RoadmapAIChat/RoadmapAIChat.tsx +++ b/src/components/RoadmapAIChat/RoadmapAIChat.tsx @@ -220,7 +220,9 @@ export function RoadmapAIChat(props: RoadmapAIChatProps) { return; } - const jsx = await renderMessage(content, renderer); + const jsx = await renderMessage(content, renderer, { + isLoading: true, + }); flushSync(() => { setStreamedMessage(jsx); @@ -233,7 +235,9 @@ export function RoadmapAIChat(props: RoadmapAIChatProps) { return; } - const jsx = await renderMessage(content, renderer); + const jsx = await renderMessage(content, renderer, { + isLoading: false, + }); const newMessages: RoamdapAIChatHistoryType[] = [ ...messages, { diff --git a/src/components/RoadmapAIChat/UserProgressActionList.tsx b/src/components/RoadmapAIChat/UserProgressActionList.tsx index cc84fe22a..3a76c91ce 100644 --- a/src/components/RoadmapAIChat/UserProgressActionList.tsx +++ b/src/components/RoadmapAIChat/UserProgressActionList.tsx @@ -69,10 +69,11 @@ type BulkUpdateResourceProgressResponse = { type UserProgressActionListProps = { roadmapId: string; content: string; + isLoading?: boolean; }; export function UserProgressActionList(props: UserProgressActionListProps) { - const { roadmapId, content } = props; + const { roadmapId, content, isLoading = false } = props; const toast = useToast(); const updateUserProgress = parseUserProgress(content); @@ -157,12 +158,19 @@ export function UserProgressActionList(props: UserProgressActionListProps) {
diff --git a/src/lib/render-chat-message.tsx b/src/lib/render-chat-message.tsx index a4fa9a629..9810e2a74 100644 --- a/src/lib/render-chat-message.tsx +++ b/src/lib/render-chat-message.tsx @@ -10,16 +10,24 @@ type MessagePart = { type MessagePartRendererProps = { content: string; + isLoading?: boolean; }; export type MessagePartRenderer = ( props: MessagePartRendererProps, ) => React.ReactNode | string; +export type MessagePartRendererOptions = { + isLoading?: boolean; +}; + export async function parseMessageParts( content: string, renderer: Record, -): Promise { + options: MessagePartRendererOptions = { + isLoading: false, + }, +) { const parts: MessagePart[] = []; const regex = /<([a-zA-Z0-9\-]+)>(.*?)<\/\1>/gs; @@ -46,7 +54,10 @@ export async function parseMessageParts( }); } - const output = renderer[tag]({ content: innerContent }); + const output = renderer[tag]({ + content: innerContent, + isLoading: options.isLoading, + }); parts.push({ id: nanoid(), type: 'html', @@ -81,7 +92,10 @@ export async function parseMessageParts( } const innerContent = content.slice(openingIndex + openingTag.length); - const output = renderer[tag]({ content: innerContent }); + const output = renderer[tag]({ + content: innerContent, + isLoading: options.isLoading, + }); parts.push({ id: nanoid(), type: 'html', @@ -109,8 +123,11 @@ export async function parseMessageParts( export async function renderMessage( content: string, renderer: Record, + options: MessagePartRendererOptions = { + isLoading: false, + }, ) { - const parts = await parseMessageParts(content, renderer); + const parts = await parseMessageParts(content, renderer, options); return (