From ea32ab6e24467d8951d2a1c7c56f2dacb574e27b Mon Sep 17 00:00:00 2001 From: Rankin Zheng Date: Wed, 10 May 2023 17:38:24 +0800 Subject: [PATCH] Refactor ChatPanel to handle missing contexts Refactored `ChatPanel` to handle missing contexts by adding conditional rendering for the `Accordion` and `contexts` map. Also, added `pre` tag styling to the message content. --- src/views/ChatPanel.tsx | 123 +++++++++++++++++++++------------------- 1 file changed, 66 insertions(+), 57 deletions(-) diff --git a/src/views/ChatPanel.tsx b/src/views/ChatPanel.tsx index c401f4a..ad56fbf 100644 --- a/src/views/ChatPanel.tsx +++ b/src/views/ChatPanel.tsx @@ -244,6 +244,7 @@ const chatPanel = () => { { paddingLeft: 0, paddingRight: 0, width: 'calc(100% - 62px)', + pre: { + whiteSpace: 'break-spaces' + } }}> - - { - contexts?.map(({ context }, index) => { - return ( - - - - {'command' in context ? context.command : context.path} - - - - { - context.content - ? context.content - :
- No content -
- } + {contexts && + + { + contexts?.map(({ context }, index) => { + return ( + + + + {'command' in context ? context.command : context.path} + + + + { + context.content + ? context.content + :
+ No content +
+ } -
-
- ); - }) - } -
+
+
+ ); + }) + } +
+ } { viewportRef={scrollViewport}> {messageList.length > 0 ? messageList : defaultMessages} - - - { - contexts.map(({ context }, index) => { - return ( - - - - {'command' in context ? context.command : context.path} - - { - contextsHandlers.remove(index); - }}> - - - - - { - context.content - ? context.content - :
- No content -
- } + + {contexts && + + { + contexts.map(({ context }, index) => { + return ( + + + + {'command' in context ? context.command : context.path} + + { + contextsHandlers.remove(index); + }}> + + + + + { + context.content + ? context.content + :
+ No content +
+ } -
-
- ); - }) - } -
+
+
+ ); + }) + } +
+ }