From 0ee98e25824d3d84ef748733eaf07fab256da1f9 Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Sun, 23 Apr 2023 00:25:09 +0800 Subject: [PATCH] Add loading to chat box --- web/src/ChatBox.js | 15 ++++++++++++--- web/src/ChatPage.js | 37 +++++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/web/src/ChatBox.js b/web/src/ChatBox.js index 6b631c68..cb0e0cc4 100644 --- a/web/src/ChatBox.js +++ b/web/src/ChatBox.js @@ -13,8 +13,9 @@ // limitations under the License. import React from "react"; -import {Avatar, Input, List} from "antd"; +import {Avatar, Input, List, Spin} from "antd"; import {CopyOutlined, DislikeOutlined, LikeOutlined, SendOutlined} from "@ant-design/icons"; +import i18next from "i18next"; const {TextArea} = Input; @@ -29,7 +30,7 @@ class ChatBox extends React.Component { } componentDidUpdate(prevProps) { - if (prevProps.messages !== this.props.messages) { + if (prevProps.messages !== this.props.messages && this.props.messages !== null) { this.scrollToListItem(this.props.messages.length); } } @@ -74,11 +75,19 @@ class ChatBox extends React.Component { }; renderList() { + if (this.props.messages === undefined || this.props.messages === null) { + return ( +
+ +
+ ); + } + return (
{ if (Object.keys(item).length === 0 && item.constructor === Object) { return { const chat = chats[i]; - this.getMessages(chat.name); this.setState({ chatName: chat.name, + messages: null, }); + this.getMessages(chat.name); }} />
-
-
+ { + this.state.messages === null ? null : ( +
+
+ ) + } {this.sendMessage(text);}} account={this.props.account} />