Skip to content

Commit 4b5fe07

Browse files
authored
feat: support hiding the left chat menu (casibase#1293)
1 parent d88e82a commit 4b5fe07

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

web/src/ChatPage.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import React from "react";
1616
import {Button, Drawer, Modal, Spin} from "antd";
17-
import {BarsOutlined, CloseCircleFilled} from "@ant-design/icons";
17+
import {BarsOutlined, CloseCircleFilled, MenuFoldOutlined, MenuUnfoldOutlined} from "@ant-design/icons";
1818
import moment from "moment";
1919
import * as StoreBackend from "./backend/StoreBackend";
2020
import ChatMenu from "./ChatMenu";
@@ -39,6 +39,9 @@ class ChatPage extends BaseListPage {
3939
}
4040

4141
UNSAFE_componentWillMount() {
42+
const savedCollapsedState = localStorage.getItem("chatMenuCollapsed");
43+
const chatMenuCollapsed = savedCollapsedState ? JSON.parse(savedCollapsedState) : false;
44+
4245
this.setState({
4346
loading: true,
4447
disableInput: false,
@@ -47,6 +50,7 @@ class ChatPage extends BaseListPage {
4750
messageError: false,
4851
autoRead: false,
4952
chatMenuVisible: false,
53+
chatMenuCollapsed: chatMenuCollapsed,
5054
defaultStore: null,
5155
filteredStores: [],
5256
paneCount: 1,
@@ -85,6 +89,14 @@ class ChatPage extends BaseListPage {
8589
});
8690
};
8791

92+
toggleChatMenuCollapse = () => {
93+
const newCollapsedState = !this.state.chatMenuCollapsed;
94+
this.setState({
95+
chatMenuCollapsed: newCollapsedState,
96+
});
97+
localStorage.setItem("chatMenuCollapsed", JSON.stringify(newCollapsedState));
98+
};
99+
88100
getGlobalStores() {
89101
StoreBackend.getGlobalStores("", "", "", "", "", "").then((res) => {
90102
if (res.status === "ok") {
@@ -642,7 +654,7 @@ class ChatPage extends BaseListPage {
642654
this.renderUnsafePasswordModal()
643655
}
644656
{
645-
!(Setting.isMobile() || Setting.getUrlParam("isRaw") !== null) && (
657+
!(Setting.isMobile() || Setting.getUrlParam("isRaw") !== null) && !this.state.chatMenuCollapsed && (
646658
<div style={{width: "250px", height: "100%", backgroundColor: "white", marginRight: "2px"}}>
647659
<ChatMenu ref={this.menu} chats={chats} chatName={this.getChat()} onSelectChat={onSelectChat} onAddChat={onAddChat} onDeleteChat={onDeleteChat} onUpdateChatName={onUpdateChatName} stores={this.state.stores} />
648660
</div>
@@ -658,10 +670,13 @@ class ChatPage extends BaseListPage {
658670

659671
<div style={{flex: 1, height: "100%", backgroundColor: "white", position: "relative", display: "flex", flexDirection: "column"}}>
660672
{this.state.chat && this.state.paneCount === 1 && (
661-
<div style={{display: "flex", alignItems: "center"}}>
673+
<div style={{display: "flex", alignItems: "center", marginLeft: "15px"}}>
662674
{Setting.isMobile() && (
663675
<Button type="text" icon={<BarsOutlined />} onClick={this.toggleChatMenu} style={{marginRight: "8px"}} />
664676
)}
677+
{!(Setting.isMobile() || Setting.getUrlParam("isRaw") !== null) && (
678+
<Button type="text" icon={this.state.chatMenuCollapsed ? <MenuUnfoldOutlined /> : <MenuFoldOutlined />} onClick={this.toggleChatMenuCollapse} style={{marginRight: "8px"}} />
679+
)}
665680
<div style={{flex: 1}}>
666681
<StoreInfoTitle chat={this.state.chat} stores={this.state.stores} autoRead={this.state.autoRead} onUpdateAutoRead={(checked) => this.setState({autoRead: checked})} account={this.props.account} paneCount={this.state.paneCount} onPaneCountChange={(count) => this.setState({paneCount: count})} showPaneControls={true} />
667682
</div>

web/src/StoreInfoTitle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ const StoreInfoTitle = (props) => {
318318

319319
{showPaneControls && canManagePanes && (
320320
<div style={{display: "flex", alignItems: "center", gap: "8px"}}>
321-
<span style={{fontSize: "12px", color: "#666"}}>Panes: {paneCount}</span>
321+
<span style={{fontSize: "12px", color: "#666", marginLeft: "20px", marginRight: "10px"}}>{i18next.t("chat:Panes")}: {paneCount}</span>
322322
<Button size="small" icon={<PlusOutlined />} onClick={addPane} />
323323
<Button size="small" icon={<MinusOutlined />} onClick={deletePane} disabled={paneCount <= 1} />
324324
</div>

0 commit comments

Comments
 (0)