mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-05 05:50:19 +08:00
Add loading to chat box
This commit is contained in:
@ -13,8 +13,9 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import React from "react";
|
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 {CopyOutlined, DislikeOutlined, LikeOutlined, SendOutlined} from "@ant-design/icons";
|
||||||
|
import i18next from "i18next";
|
||||||
|
|
||||||
const {TextArea} = Input;
|
const {TextArea} = Input;
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ class ChatBox extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
if (prevProps.messages !== this.props.messages) {
|
if (prevProps.messages !== this.props.messages && this.props.messages !== null) {
|
||||||
this.scrollToListItem(this.props.messages.length);
|
this.scrollToListItem(this.props.messages.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,11 +75,19 @@ class ChatBox extends React.Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
renderList() {
|
renderList() {
|
||||||
|
if (this.props.messages === undefined || this.props.messages === null) {
|
||||||
|
return (
|
||||||
|
<div style={{display: "flex", justifyContent: "center", alignItems: "center"}}>
|
||||||
|
<Spin size="large" tip={i18next.t("login:Loading")} style={{paddingTop: "20%"}} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={this.listContainerRef} style={{position: "relative", maxHeight: "calc(100vh - 140px)", overflowY: "auto"}}>
|
<div ref={this.listContainerRef} style={{position: "relative", maxHeight: "calc(100vh - 140px)", overflowY: "auto"}}>
|
||||||
<List
|
<List
|
||||||
itemLayout="horizontal"
|
itemLayout="horizontal"
|
||||||
dataSource={this.props.messages === undefined ? undefined : [...this.props.messages, {}]}
|
dataSource={[...this.props.messages, {}]}
|
||||||
renderItem={(item, index) => {
|
renderItem={(item, index) => {
|
||||||
if (Object.keys(item).length === 0 && item.constructor === Object) {
|
if (Object.keys(item).length === 0 && item.constructor === Object) {
|
||||||
return <List.Item id={`chatbox-list-item-${index}`} style={{
|
return <List.Item id={`chatbox-list-item-${index}`} style={{
|
||||||
|
@ -122,16 +122,19 @@ class ChatPage extends BaseListPage {
|
|||||||
<div style={{width: "250px", height: "100%", backgroundColor: "white", borderRight: "1px solid rgb(245,245,245)"}}>
|
<div style={{width: "250px", height: "100%", backgroundColor: "white", borderRight: "1px solid rgb(245,245,245)"}}>
|
||||||
<ChatMenu chats={chats} onSelect={(i) => {
|
<ChatMenu chats={chats} onSelect={(i) => {
|
||||||
const chat = chats[i];
|
const chat = chats[i];
|
||||||
this.getMessages(chat.name);
|
|
||||||
this.setState({
|
this.setState({
|
||||||
chatName: chat.name,
|
chatName: chat.name,
|
||||||
|
messages: null,
|
||||||
});
|
});
|
||||||
|
this.getMessages(chat.name);
|
||||||
}} />
|
}} />
|
||||||
</div>
|
</div>
|
||||||
<div style={{flex: 1, height: "100%", backgroundColor: "white", position: "relative"}}>
|
<div style={{flex: 1, height: "100%", backgroundColor: "white", position: "relative"}}>
|
||||||
|
{
|
||||||
|
this.state.messages === null ? null : (
|
||||||
<div style={{
|
<div style={{
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
top: 0,
|
top: -50,
|
||||||
left: 0,
|
left: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
@ -144,6 +147,8 @@ class ChatPage extends BaseListPage {
|
|||||||
opacity: 0.5,
|
opacity: 0.5,
|
||||||
}}>
|
}}>
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
<ChatBox messages={this.state.messages} sendMessage={(text) => {this.sendMessage(text);}} account={this.props.account} />
|
<ChatBox messages={this.state.messages} sendMessage={(text) => {this.sendMessage(text);}} account={this.props.account} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user