Skip to content

Commit

Permalink
🐛 fix: fix rsc layout
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Oct 9, 2023
1 parent bd48121 commit d73f13f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/app/settings/(mobile)/layout.mobile.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { PropsWithChildren, memo } from 'react';
import { Flexbox } from 'react-layout-kit';

Expand Down
5 changes: 2 additions & 3 deletions src/app/settings/common/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ import { useSwitchSideBarOnInit } from '@/store/global/hooks/useSwitchSettingsOn
import { SettingsTabs } from '@/store/global/initialState';
import { genSiteHeadTitle } from '@/utils/genSiteHeadTitle';

import Layout from '../layout.responsive';
import Common from './Common';

export default memo(() => {
useSwitchSideBarOnInit(SettingsTabs.Common);
const { t } = useTranslation('setting');
const pageTitle = genSiteHeadTitle(t('header.global'));
return (
<Layout>
<>
<PageTitle title={pageTitle} />
<Common />
</Layout>
</>
);
});
1 change: 1 addition & 0 deletions src/app/settings/common/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '../layout.responsive';
16 changes: 15 additions & 1 deletion src/layout/GlobalLayout/StoreHydration.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { useResponsive } from 'antd-style';
import { useRouter } from 'next/navigation';
import { memo, useEffect } from 'react';

import { useGlobalStore } from '@/store/global';
import { usePluginStore } from '@/store/plugin';
import { useOnFinishHydrationSession, useSessionStore } from '@/store/session';
import {
useEffectAfterSessionHydrated,
useOnFinishHydrationSession,
useSessionStore,
} from '@/store/session';

const StoreHydration = memo(() => {
const router = useRouter();
Expand All @@ -22,6 +27,15 @@ const StoreHydration = memo(() => {
store.setState({ router });
});

const { mobile } = useResponsive();

useEffectAfterSessionHydrated(
(store) => {
store.setState({ isMobile: mobile });
},
[mobile],
);

return null;
});

Expand Down
9 changes: 5 additions & 4 deletions src/store/session/slices/session/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,13 @@ export const createSessionSlice: StateCreator<
router?.push(SESSION_CHAT_URL(id, get().isMobile));
},
switchSession: (sessionId = INBOX_SESSION_ID) => {
const { router } = get();

if (get().activeId === sessionId) return;
const { isMobile, router } = get();
// mobile also should switch session due to chat mobile route is different
// fix https://github.com/lobehub/lobe-chat/issues/163
if (!isMobile && get().activeId === sessionId) return;

get().activeSession(sessionId);

router?.push(SESSION_CHAT_URL(sessionId, true));
router?.push(SESSION_CHAT_URL(sessionId, isMobile));
},
});

0 comments on commit d73f13f

Please sign in to comment.