Add empty list item and expand menu by default

This commit is contained in:
Yang Luo
2023-04-10 01:57:53 +08:00
parent ebe8ad8669
commit 0db61dd658
3 changed files with 50 additions and 32 deletions

View File

@ -49,8 +49,18 @@ class ChatBox extends React.Component {
<List <List
style={{maxHeight: "calc(100vh - 140px)", overflowY: "auto"}} style={{maxHeight: "calc(100vh - 140px)", overflowY: "auto"}}
itemLayout="horizontal" itemLayout="horizontal"
dataSource={this.props.messages} dataSource={this.props.messages === undefined ? undefined : [...this.props.messages, {}]}
renderItem={(item, index) => ( renderItem={(item, index) => {
if (Object.keys(item).length === 0 && item.constructor === Object) {
return <List.Item style={{
height: "160px",
backgroundColor: index % 2 === 0 ? "white" : "rgb(247,247,248)",
borderBottom: "1px solid rgb(229, 229, 229)",
position: "relative",
}} />;
}
return (
<List.Item style={{ <List.Item style={{
backgroundColor: index % 2 === 0 ? "white" : "rgb(247,247,248)", backgroundColor: index % 2 === 0 ? "white" : "rgb(247,247,248)",
borderBottom: "1px solid rgb(229, 229, 229)", borderBottom: "1px solid rgb(229, 229, 229)",
@ -69,7 +79,8 @@ class ChatBox extends React.Component {
</div> </div>
</div> </div>
</List.Item> </List.Item>
)} );
}}
/> />
<div style={{ <div style={{
position: "absolute", position: "absolute",

View File

@ -19,8 +19,12 @@ import {LayoutOutlined} from "@ant-design/icons";
class ChatMenu extends React.Component { class ChatMenu extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
const items = this.chatsToItems(this.props.chats);
const openKeys = items.map((item) => item.key);
this.state = { this.state = {
openKeys: ["0"], openKeys: openKeys,
selectedKeys: ["0-0"], selectedKeys: ["0-0"],
}; };
} }

View File

@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
import React from "react"; import React from "react";
import {Spin} from "antd";
import moment from "moment"; import moment from "moment";
import ChatMenu from "./ChatMenu"; import ChatMenu from "./ChatMenu";
import ChatBox from "./ChatBox"; import ChatBox from "./ChatBox";
@ -76,10 +77,11 @@ class ChatPage extends BaseListPage {
} }
renderTable(chats) { renderTable(chats) {
return ( return (this.state.loading) ? <Spin size="large" style={{marginLeft: "50%", marginTop: "10%"}} /> : (
(
<div style={{display: "flex", height: "calc(100vh - 140px)"}}> <div style={{display: "flex", height: "calc(100vh - 140px)"}}>
<div style={{width: "250px", height: "100%", backgroundColor: "lightblue"}}> <div style={{width: "250px", height: "100%", backgroundColor: "lightblue"}}>
<ChatMenu chats={this.state.data} onSelect={(i) => { <ChatMenu chats={chats} onSelect={(i) => {
const chat = chats[i]; const chat = chats[i];
this.getMessages(chat.name); this.getMessages(chat.name);
}} /> }} />
@ -88,6 +90,7 @@ class ChatPage extends BaseListPage {
<ChatBox messages={this.state.messages} account={this.props.account} /> <ChatBox messages={this.state.messages} account={this.props.account} />
</div> </div>
</div> </div>
)
); );
} }