@lobehub/chat 0.127.1 → 0.127.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 0.127.2](https://github.com/lobehub/lobe-chat/compare/v0.127.1...v0.127.2)
6
+
7
+ <sup>Released on **2024-02-14**</sup>
8
+
9
+ #### ♻ Code Refactoring
10
+
11
+ - **misc**: Refactor the sidebar to fix first render state.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### Code refactoring
19
+
20
+ - **misc**: Refactor the sidebar to fix first render state, closes [#1301](https://github.com/lobehub/lobe-chat/issues/1301) ([c477491](https://github.com/lobehub/lobe-chat/commit/c477491))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
5
30
  ### [Version 0.127.1](https://github.com/lobehub/lobe-chat/compare/v0.127.0...v0.127.1)
6
31
 
7
32
  <sup>Released on **2024-02-14**</sup>
package/README.md CHANGED
@@ -225,14 +225,14 @@ Our marketplace is not just a showcase platform but also a collaborative space.
225
225
 
226
226
  <!-- AGENT LIST -->
227
227
 
228
- | Recent Submits | Description |
229
- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
230
- | [Product Review](https://chat-preview.lobehub.com/market?agent=product-reviews)<br/><sup>By **[pllz7](https://github.com/pllz7)** on **2024-02-11**</sup> | Expert in creating persuasive product testimonials highlighting the benefits and value proposition of \[your product/service].<br/>`ecommerce` |
231
- | [Tarot Reader](https://chat-preview.lobehub.com/market?agent=augur)<br/><sup>By **[CLOT-LIU](https://github.com/CLOT-LIU)** on **2024-02-10**</sup> | Specializes in tarot reading and interpreting tarot cards<br/>`tarot-reading` `interpretation` `advice` |
232
- | [Happy Loong Year](https://chat-preview.lobehub.com/market?agent=happy-loong-year)<br/><sup>By **[canisminor1990](https://github.com/canisminor1990)** on **2024-02-10**</sup> | Loong Year's Assistant combines traditional and modern elements to create interesting New Year blessings.<br/>`new-years-greetings` `creativity` `copywriting` `dragon-year` |
233
- | [Vocabulary Wizard](https://chat-preview.lobehub.com/market?agent=awl-vocab-wizard)<br/><sup>By **[bentwnghk](https://github.com/bentwnghk)** on **2024-02-09**</sup> | Expert in generating vocabulary lists and MCQ tests<br/>`vocabulary` `academic-word-list` `language-learning` `testing` |
234
-
235
- > 📊 Total agents: [<kbd>**173**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
228
+ | Recent Submits | Description |
229
+ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
230
+ | [Product Copywriting](https://chat-preview.lobehub.com/market?agent=copywriting)<br/><sup>By **[pllz7](https://github.com/pllz7)** on **2024-02-14**</sup> | Expert in persuasive copywriting and consumer psychology<br/>`ecommerce` |
231
+ | [Private Domain Operations Expert](https://chat-preview.lobehub.com/market?agent=gl-syyy)<br/><sup>By **[guling-io](https://github.com/guling-io)** on **2024-02-14**</sup> | Specializing in private domain operations, traffic acquisition, user retention, conversion, and content planning. Familiar with marketing theories and related classic works.<br/>`private-domain-operations` `traffic-acquisition` `user-retention` `conversion` `content-planning` |
232
+ | [Self-Media Operation Expert](https://chat-preview.lobehub.com/market?agent=gl-zmtyy)<br/><sup>By **[guling-io](https://github.com/guling-io)** on **2024-02-14**</sup> | Specialized in self-media operation and content creation<br/>`self-media-operation` `social-media` `content-creation` `fan-growth` `brand-promotion` |
233
+ | [Product Description](https://chat-preview.lobehub.com/market?agent=product-description)<br/><sup>By **[pllz7](https://github.com/pllz7)** on **2024-02-14**</sup> | Craft compelling product descriptions that boost e-commerce sales<br/>`ecommerce` |
234
+
235
+ > 📊 Total agents: [<kbd>**177**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
236
236
 
237
237
  <!-- AGENT LIST -->
238
238
 
package/README.zh-CN.md CHANGED
@@ -205,14 +205,14 @@ LobeChat 的插件生态系统是其核心功能的重要扩展,它极大地
205
205
 
206
206
  <!-- AGENT LIST -->
207
207
 
208
- | 最近新增 | 助手说明 |
209
- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
210
- | [产品评价](https://chat-preview.lobehub.com/market?agent=product-reviews)<br/><sup>By **[pllz7](https://github.com/pllz7)** on **2024-02-11**</sup> | 擅长撰写有说服力的产品推荐,突出 \[您的产品 / 服务] 的优势和价值主张。<br/>`电子商务` |
211
- | [塔罗占卜师](https://chat-preview.lobehub.com/market?agent=augur)<br/><sup>By **[CLOT-LIU](https://github.com/CLOT-LIU)** on **2024-02-10**</sup> | 擅长塔罗占卜,会对塔罗牌进行解读<br/>`塔罗占卜` `解读` `建议` |
212
- | [新年快乐](https://chat-preview.lobehub.com/market?agent=happy-loong-year)<br/><sup>By **[canisminor1990](https://github.com/canisminor1990)** on **2024-02-10**</sup> | 龙年拜年小助手,结合传统与现代元素,创造有趣的龙年祝福语。<br/>`拜年祝福` `创意` `文案` `龙年` |
213
- | [词汇大师](https://chat-preview.lobehub.com/market?agent=awl-vocab-wizard)<br/><sup>By **[bentwnghk](https://github.com/bentwnghk)** on **2024-02-09**</sup> | 擅长生成词汇列表和多项选择测试<br/>`词汇` `学术词汇表` `语言学习` `测试` |
214
-
215
- > 📊 Total agents: [<kbd>**173**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
208
+ | 最近新增 | 助手说明 |
209
+ | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
210
+ | [产品文案撰写](https://chat-preview.lobehub.com/market?agent=copywriting)<br/><sup>By **[pllz7](https://github.com/pllz7)** on **2024-02-14**</sup> | 精通有说服力的文案撰写和消费者心理学<br/>`电子商务` |
211
+ | [私域运营专家](https://chat-preview.lobehub.com/market?agent=gl-syyy)<br/><sup>By **[guling-io](https://github.com/guling-io)** on **2024-02-14**</sup> | 擅长私域运营、引流、承接、转化和内容策划,熟悉营销理论和相关经典著作。<br/>`私域运营` `引流` `承接` `转化` `内容策划` |
212
+ | [自媒体运营专家](https://chat-preview.lobehub.com/market?agent=gl-zmtyy)<br/><sup>By **[guling-io](https://github.com/guling-io)** on **2024-02-14**</sup> | 擅长自媒体运营与内容创作<br/>`自媒体运营` `社交媒体` `内容创作` `粉丝增长` `品牌推广` |
213
+ | [产品描述](https://chat-preview.lobehub.com/market?agent=product-description)<br/><sup>By **[pllz7](https://github.com/pllz7)** on **2024-02-14**</sup> | 打造引人入胜的产品描述,提升电子商务销售业绩<br/>`电子商务` |
214
+
215
+ > 📊 Total agents: [<kbd>**177**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
216
216
 
217
217
  <!-- AGENT LIST -->
218
218
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.127.1",
3
+ "version": "0.127.2",
4
4
  "description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
5
5
  "keywords": [
6
6
  "framework",
@@ -4,15 +4,13 @@ import { PropsWithChildren, memo } from 'react';
4
4
  import { Flexbox } from 'react-layout-kit';
5
5
 
6
6
  import AppLayoutDesktop from '@/layout/AppLayout.desktop';
7
- import { useSwitchSideBarOnInit } from '@/store/global';
8
7
  import { SidebarTabKey } from '@/store/global/initialState';
9
8
 
10
9
  import ResponsiveSessionList from './features/SessionList';
11
10
 
12
11
  export default memo(({ children }: PropsWithChildren) => {
13
- useSwitchSideBarOnInit(SidebarTabKey.Chat);
14
12
  return (
15
- <AppLayoutDesktop>
13
+ <AppLayoutDesktop sidebarKey={SidebarTabKey.Chat}>
16
14
  <ResponsiveSessionList />
17
15
  <Flexbox
18
16
  flex={1}
@@ -4,16 +4,13 @@ import { useRouter } from 'next/navigation';
4
4
  import { memo, useEffect } from 'react';
5
5
 
6
6
  import AppLayoutMobile from '@/layout/AppLayout.mobile';
7
- import { useSwitchSideBarOnInit } from '@/store/global';
8
- import { SidebarTabKey } from '@/store/global/slices/common/initialState';
7
+ import { SidebarTabKey } from '@/store/global/initialState';
9
8
 
10
9
  import PageTitle from '../features/PageTitle';
11
10
  import SessionHeader from './features/SessionHeader';
12
11
  import SessionList from './features/SessionList';
13
12
 
14
13
  const ChatMobilePage = memo(() => {
15
- useSwitchSideBarOnInit(SidebarTabKey.Chat);
16
-
17
14
  const router = useRouter();
18
15
  useEffect(() => {
19
16
  router.prefetch('/chat/mobile');
@@ -21,7 +18,7 @@ const ChatMobilePage = memo(() => {
21
18
  }, []);
22
19
 
23
20
  return (
24
- <AppLayoutMobile navBar={<SessionHeader />} showTabBar>
21
+ <AppLayoutMobile navBar={<SessionHeader />} showTabBar tabBarKey={SidebarTabKey.Chat}>
25
22
  <PageTitle />
26
23
  <SessionList />
27
24
  </AppLayoutMobile>
@@ -6,7 +6,7 @@ import { useTranslation } from 'react-i18next';
6
6
 
7
7
  import { DESKTOP_HEADER_ICON_SIZE, MOBILE_HEADER_ICON_SIZE } from '@/const/layoutTokens';
8
8
  import { useGlobalStore } from '@/store/global';
9
- import { SidebarTabKey } from '@/store/global/slices/common/initialState';
9
+ import { SidebarTabKey } from '@/store/global/initialState';
10
10
  import { useSessionStore } from '@/store/session';
11
11
  import { sessionSelectors } from '@/store/session/selectors';
12
12
  import { pathString } from '@/utils/url';
@@ -5,8 +5,6 @@ import { memo, useEffect } from 'react';
5
5
 
6
6
  import { messageService } from '@/services/message';
7
7
  import { sessionService } from '@/services/session';
8
- import { useGlobalStore } from '@/store/global';
9
- import { SidebarTabKey } from '@/store/global/initialState';
10
8
  import { useSessionStore } from '@/store/session';
11
9
 
12
10
  const checkHasConversation = async () => {
@@ -21,8 +19,6 @@ const Redirect = memo(() => {
21
19
 
22
20
  useEffect(() => {
23
21
  checkHasConversation().then((hasData) => {
24
- useGlobalStore.getState().switchSideBar(SidebarTabKey.Chat);
25
-
26
22
  if (hasData) {
27
23
  router.replace('/chat');
28
24
 
@@ -7,7 +7,6 @@ import { Center, Flexbox } from 'react-layout-kit';
7
7
  import SafeSpacing from '@/components/SafeSpacing';
8
8
  import { MAX_WIDTH } from '@/const/layoutTokens';
9
9
  import AppLayoutDesktop from '@/layout/AppLayout.desktop';
10
- import { useSwitchSideBarOnInit } from '@/store/global';
11
10
  import { SidebarTabKey } from '@/store/global/initialState';
12
11
 
13
12
  import Header from './features/Header';
@@ -30,10 +29,8 @@ const useStyles = createStyles(({ css }) => ({
30
29
  const MarketLayout = memo<PropsWithChildren>(({ children }) => {
31
30
  const { theme, styles } = useStyles();
32
31
 
33
- useSwitchSideBarOnInit(SidebarTabKey.Market);
34
-
35
32
  return (
36
- <AppLayoutDesktop>
33
+ <AppLayoutDesktop sidebarKey={SidebarTabKey.Market}>
37
34
  <Flexbox
38
35
  flex={1}
39
36
  height={'100%'}
@@ -5,7 +5,6 @@ import { PropsWithChildren } from 'react';
5
5
  import { Flexbox } from 'react-layout-kit';
6
6
 
7
7
  import AppLayoutMobile from '@/layout/AppLayout.mobile';
8
- import { useSwitchSideBarOnInit } from '@/store/global';
9
8
  import { SidebarTabKey } from '@/store/global/initialState';
10
9
 
11
10
  import Header from './features/Header';
@@ -13,10 +12,8 @@ import Header from './features/Header';
13
12
  const DetailModal = dynamic(() => import('./features/AgentDetail'));
14
13
 
15
14
  const MarketLayout = ({ children }: PropsWithChildren) => {
16
- useSwitchSideBarOnInit(SidebarTabKey.Market);
17
-
18
15
  return (
19
- <AppLayoutMobile navBar={<Header />} showTabBar>
16
+ <AppLayoutMobile navBar={<Header />} showTabBar tabBarKey={SidebarTabKey.Market}>
20
17
  <Flexbox flex={1} gap={16} style={{ padding: 16 }}>
21
18
  {children}
22
19
  </Flexbox>
@@ -5,8 +5,6 @@ import { memo } from 'react';
5
5
  import { useTranslation } from 'react-i18next';
6
6
  import { Center } from 'react-layout-kit';
7
7
 
8
- import { useGlobalStore } from '@/store/global';
9
- import { SidebarTabKey } from '@/store/global/initialState';
10
8
  import { agentMarketSelectors, useMarketStore } from '@/store/market';
11
9
  import { useSessionStore } from '@/store/session';
12
10
 
@@ -18,7 +16,6 @@ const Header = memo(() => {
18
16
  const { t } = useTranslation('market');
19
17
  const { styles, theme } = useStyles();
20
18
  const createSession = useSessionStore((s) => s.createSession);
21
- const switchSideBar = useGlobalStore((s) => s.switchSideBar);
22
19
  const agentItem = useMarketStore(agentMarketSelectors.currentAgentItem);
23
20
  const { message } = App.useApp();
24
21
 
@@ -56,7 +53,6 @@ const Header = memo(() => {
56
53
  if (!agentItem) return;
57
54
 
58
55
  createSession({ config, meta });
59
- switchSideBar(SidebarTabKey.Chat);
60
56
  }}
61
57
  type={'primary'}
62
58
  >
@@ -5,7 +5,6 @@ import { Center, Flexbox } from 'react-layout-kit';
5
5
 
6
6
  import SafeSpacing from '@/components/SafeSpacing';
7
7
  import AppLayoutDesktop from '@/layout/AppLayout.desktop';
8
- import { useSwitchSideBarOnInit } from '@/store/global';
9
8
  import { SettingsTabs, SidebarTabKey } from '@/store/global/initialState';
10
9
 
11
10
  import Header from './features/Header';
@@ -17,10 +16,8 @@ export interface DesktopLayoutProps {
17
16
  }
18
17
 
19
18
  const DesktopLayout = memo<DesktopLayoutProps>(({ children, activeTab }) => {
20
- useSwitchSideBarOnInit(SidebarTabKey.Setting);
21
-
22
19
  return (
23
- <AppLayoutDesktop>
20
+ <AppLayoutDesktop sidebarKey={SidebarTabKey.Setting}>
24
21
  <SideBar activeTab={activeTab} />
25
22
  <Flexbox flex={1} height={'100%'} style={{ position: 'relative' }}>
26
23
  <Header activeTab={activeTab} />
@@ -4,7 +4,6 @@ import { ReactNode, memo } from 'react';
4
4
  import { Flexbox } from 'react-layout-kit';
5
5
 
6
6
  import AppLayoutMobile from '@/layout/AppLayout.mobile';
7
- import { useSwitchSideBarOnInit } from '@/store/global';
8
7
  import { SettingsTabs, SidebarTabKey } from '@/store/global/initialState';
9
8
 
10
9
  import Header from './features/Header';
@@ -14,9 +13,8 @@ export interface SettingLayoutProps {
14
13
  children: ReactNode;
15
14
  }
16
15
  export default memo(({ children, activeTab }: SettingLayoutProps) => {
17
- useSwitchSideBarOnInit(SidebarTabKey.Setting);
18
16
  return (
19
- <AppLayoutMobile navBar={<Header activeTab={activeTab} />}>
17
+ <AppLayoutMobile navBar={<Header activeTab={activeTab} />} tabBarKey={SidebarTabKey.Setting}>
20
18
  <Flexbox style={{ overflow: 'auto' }}>{children}</Flexbox>
21
19
  </AppLayoutMobile>
22
20
  );
@@ -6,7 +6,6 @@ import { rgba } from 'polished';
6
6
  import { memo, useMemo } from 'react';
7
7
  import { useTranslation } from 'react-i18next';
8
8
 
9
- import { useGlobalStore } from '@/store/global';
10
9
  import { SidebarTabKey } from '@/store/global/initialState';
11
10
 
12
11
  const useStyles = createStyles(({ css, token }) => ({
@@ -17,8 +16,12 @@ const useStyles = createStyles(({ css, token }) => ({
17
16
  `,
18
17
  }));
19
18
 
20
- export default memo<{ className?: string }>(({ className }) => {
21
- const [tab, setTab] = useGlobalStore((s) => [s.sidebarKey, s.switchSideBar]);
19
+ interface Props {
20
+ className?: string;
21
+ tabBarKey?: SidebarTabKey;
22
+ }
23
+
24
+ export default memo<Props>(({ className, tabBarKey }) => {
22
25
  const { t } = useTranslation('common');
23
26
  const { styles } = useStyles();
24
27
  const router = useRouter();
@@ -30,7 +33,6 @@ export default memo<{ className?: string }>(({ className }) => {
30
33
  ),
31
34
  key: SidebarTabKey.Chat,
32
35
  onClick: () => {
33
- setTab(SidebarTabKey.Chat);
34
36
  router.push('/chat');
35
37
  },
36
38
  title: t('tab.chat'),
@@ -39,7 +41,6 @@ export default memo<{ className?: string }>(({ className }) => {
39
41
  icon: (active) => <Icon className={active ? styles.active : undefined} icon={Bot} />,
40
42
  key: SidebarTabKey.Market,
41
43
  onClick: () => {
42
- setTab(SidebarTabKey.Market);
43
44
  router.push('/market');
44
45
  },
45
46
  title: t('tab.market'),
@@ -48,7 +49,6 @@ export default memo<{ className?: string }>(({ className }) => {
48
49
  icon: (active) => <Icon className={active ? styles.active : undefined} icon={User} />,
49
50
  key: SidebarTabKey.Setting,
50
51
  onClick: () => {
51
- setTab(SidebarTabKey.Setting);
52
52
  router.push('/settings');
53
53
  },
54
54
  title: t('tab.setting'),
@@ -56,12 +56,5 @@ export default memo<{ className?: string }>(({ className }) => {
56
56
  ],
57
57
  [t],
58
58
  );
59
- return (
60
- <MobileTabBar
61
- activeKey={tab}
62
- className={className}
63
- items={items}
64
- onChange={(key) => setTab(key as any)}
65
- />
66
- );
59
+ return <MobileTabBar activeKey={tabBarKey} className={className} items={items} />;
67
60
  });
@@ -23,11 +23,10 @@ import { GlobalStore, useGlobalStore } from '@/store/global';
23
23
  import { SidebarTabKey } from '@/store/global/initialState';
24
24
 
25
25
  export interface BottomActionProps {
26
- setTab: GlobalStore['switchSideBar'];
27
- tab: GlobalStore['sidebarKey'];
26
+ tab?: GlobalStore['sidebarKey'];
28
27
  }
29
28
 
30
- const BottomActions = memo<BottomActionProps>(({ tab, setTab }) => {
29
+ const BottomActions = memo<BottomActionProps>(({ tab }) => {
31
30
  const router = useRouter();
32
31
  const { t } = useTranslation('common');
33
32
 
@@ -113,10 +112,6 @@ const BottomActions = memo<BottomActionProps>(({ tab, setTab }) => {
113
112
  </Flexbox>
114
113
  ),
115
114
  onClick: () => {
116
- setTab(SidebarTabKey.Setting);
117
- useGlobalStore.setState({
118
- sidebarKey: SidebarTabKey.Setting,
119
- });
120
115
  router.push('/settings/common');
121
116
  },
122
117
  },
@@ -9,11 +9,10 @@ import { SidebarTabKey } from '@/store/global/initialState';
9
9
  import { useSessionStore } from '@/store/session';
10
10
 
11
11
  export interface TopActionProps {
12
- setTab: GlobalStore['switchSideBar'];
13
- tab: GlobalStore['sidebarKey'];
12
+ tab?: GlobalStore['sidebarKey'];
14
13
  }
15
14
 
16
- const TopActions = memo<TopActionProps>(({ tab, setTab }) => {
15
+ const TopActions = memo<TopActionProps>(({ tab }) => {
17
16
  const { t } = useTranslation('common');
18
17
  const switchBackToChat = useGlobalStore((s) => s.switchBackToChat);
19
18
 
@@ -24,7 +23,6 @@ const TopActions = memo<TopActionProps>(({ tab, setTab }) => {
24
23
  onClick={(e) => {
25
24
  e.preventDefault();
26
25
  switchBackToChat(useSessionStore.getState().activeId);
27
- setTab(SidebarTabKey.Chat);
28
26
  }}
29
27
  >
30
28
  <ActionIcon
@@ -39,9 +37,6 @@ const TopActions = memo<TopActionProps>(({ tab, setTab }) => {
39
37
  <ActionIcon
40
38
  active={tab === SidebarTabKey.Market}
41
39
  icon={Compass}
42
- onClick={() => {
43
- setTab(SidebarTabKey.Market);
44
- }}
45
40
  placement={'right'}
46
41
  size="large"
47
42
  title={t('tab.market')}
@@ -2,20 +2,22 @@ import { SideNav } from '@lobehub/ui';
2
2
  import { memo } from 'react';
3
3
 
4
4
  import AvatarWithUpload from '@/features/AvatarWithUpload';
5
- import { useGlobalStore } from '@/store/global';
5
+ import { SidebarTabKey } from '@/store/global/initialState';
6
6
 
7
7
  import BottomActions from './BottomActions';
8
8
  import TopActions from './TopActions';
9
9
 
10
- export default memo(() => {
11
- const [tab, setTab] = useGlobalStore((s) => [s.sidebarKey, s.switchSideBar]);
10
+ interface Props {
11
+ sidebarKey?: SidebarTabKey;
12
+ }
12
13
 
14
+ export default memo<Props>(({ sidebarKey }) => {
13
15
  return (
14
16
  <SideNav
15
17
  avatar={<AvatarWithUpload id={'avatar'} />}
16
- bottomActions={<BottomActions setTab={setTab} tab={tab} />}
18
+ bottomActions={<BottomActions tab={sidebarKey} />}
17
19
  style={{ height: '100%' }}
18
- topActions={<TopActions setTab={setTab} tab={tab} />}
20
+ topActions={<TopActions tab={sidebarKey} />}
19
21
  />
20
22
  );
21
23
  });
@@ -1,11 +1,16 @@
1
1
  import { useTheme } from 'antd-style';
2
- import { PropsWithChildren, memo } from 'react';
2
+ import { ReactNode, memo } from 'react';
3
3
  import { Flexbox } from 'react-layout-kit';
4
4
 
5
5
  import SideBar from '@/features/SideBar';
6
6
  import { useIsPWA } from '@/hooks/useIsPWA';
7
+ import { SidebarTabKey } from '@/store/global/initialState';
7
8
 
8
- const AppLayoutDesktop = memo<PropsWithChildren>(({ children }) => {
9
+ interface AppLayoutDesktopProps {
10
+ children: ReactNode;
11
+ sidebarKey?: SidebarTabKey;
12
+ }
13
+ const AppLayoutDesktop = memo<AppLayoutDesktopProps>(({ children, sidebarKey }) => {
9
14
  const isPWA = useIsPWA();
10
15
  const theme = useTheme();
11
16
 
@@ -16,7 +21,7 @@ const AppLayoutDesktop = memo<PropsWithChildren>(({ children }) => {
16
21
  style={isPWA ? { borderTop: `1px solid ${theme.colorBorder}` } : {}}
17
22
  width={'100%'}
18
23
  >
19
- <SideBar />
24
+ <SideBar sidebarKey={sidebarKey} />
20
25
  {children}
21
26
  </Flexbox>
22
27
  );
@@ -5,6 +5,7 @@ import { CSSProperties, PropsWithChildren, ReactNode, memo } from 'react';
5
5
  import { Flexbox } from 'react-layout-kit';
6
6
 
7
7
  import SafeSpacing from '@/components/SafeSpacing';
8
+ import { SidebarTabKey } from '@/store/global/slices/common/initialState';
8
9
 
9
10
  const MobileTabBar = dynamic(() => import('@/features/MobileTabBar'));
10
11
 
@@ -39,11 +40,12 @@ interface AppMobileLayoutProps extends PropsWithChildren {
39
40
  navBar?: ReactNode;
40
41
  showTabBar?: boolean;
41
42
  style?: CSSProperties;
43
+ tabBarKey?: SidebarTabKey;
42
44
  title?: MobileNavBarTitleProps;
43
45
  }
44
46
 
45
47
  const AppLayoutMobile = memo<AppMobileLayoutProps>(
46
- ({ children, showTabBar, navBar, style, className }) => {
48
+ ({ children, showTabBar, tabBarKey, navBar, style, className }) => {
47
49
  const { styles, cx } = useStyles();
48
50
 
49
51
  return (
@@ -58,7 +60,7 @@ const AppLayoutMobile = memo<AppMobileLayoutProps>(
58
60
  {showTabBar && (
59
61
  <>
60
62
  <SafeSpacing mobile position={'bottom'} />
61
- <MobileTabBar className={styles.mobileTabBar} />
63
+ <MobileTabBar className={styles.mobileTabBar} tabBarKey={tabBarKey} />
62
64
  </>
63
65
  )}
64
66
  </Flexbox>
@@ -1,3 +1,3 @@
1
1
  export * from './useEffectAfterHydrated';
2
2
  export * from './useOnFinishHydrationGlobal';
3
- export * from './useSwitchSideBarOnInit';
3
+
@@ -38,16 +38,4 @@ describe('createCommonSlice', () => {
38
38
  expect(router.push).toHaveBeenCalledWith('/chat?session=session-id');
39
39
  });
40
40
  });
41
-
42
- describe('switchSideBar', () => {
43
- it('should switch sidebar', () => {
44
- const { result } = renderHook(() => useGlobalStore());
45
-
46
- act(() => {
47
- result.current.switchSideBar(SidebarTabKey.Market);
48
- });
49
-
50
- expect(result.current.sidebarKey).toEqual(SidebarTabKey.Market);
51
- });
52
- });
53
41
  });
@@ -13,8 +13,6 @@ import type { GlobalServerConfig, GlobalSettings } from '@/types/settings';
13
13
  import { merge } from '@/utils/merge';
14
14
  import { setNamespace } from '@/utils/storeDebug';
15
15
 
16
- import type { SidebarTabKey } from './initialState';
17
-
18
16
  const n = setNamespace('common');
19
17
 
20
18
  /**
@@ -23,7 +21,6 @@ const n = setNamespace('common');
23
21
  export interface CommonAction {
24
22
  refreshUserConfig: () => Promise<void>;
25
23
  switchBackToChat: (sessionId?: string) => void;
26
- switchSideBar: (key: SidebarTabKey) => void;
27
24
  updateAvatar: (avatar: string) => Promise<void>;
28
25
  useCheckLatestVersion: () => SWRResponse<string>;
29
26
  useFetchServerConfig: () => SWRResponse;
@@ -44,9 +41,7 @@ export const createCommonSlice: StateCreator<
44
41
  switchBackToChat: (sessionId) => {
45
42
  get().router?.push(SESSION_CHAT_URL(sessionId || INBOX_SESSION_ID, get().isMobile));
46
43
  },
47
- switchSideBar: (key) => {
48
- set({ sidebarKey: key }, false, n('switchSideBar', key));
49
- },
44
+
50
45
  updateAvatar: async (avatar) => {
51
46
  await userService.updateAvatar(avatar);
52
47
  await get().refreshUserConfig();
@@ -1,13 +0,0 @@
1
- import { SidebarTabKey } from '../initialState';
2
- import { useGlobalStore } from '../store';
3
- import { useOnFinishHydrationGlobal } from './useOnFinishHydrationGlobal';
4
-
5
- /**
6
- * 切换侧边栏选项
7
- * @desc 只会在应用初始化时(且水合后)执行一次
8
- */
9
- export const useSwitchSideBarOnInit = (key: SidebarTabKey) => {
10
- useOnFinishHydrationGlobal(() => {
11
- useGlobalStore.getState().switchSideBar(key);
12
- });
13
- };