Skip to content

Commit

Permalink
🐛 fix: fix redirect to welcome problem when there are topics in inbox (
Browse files Browse the repository at this point in the history
…#422)

* 🐛 fix: fix home redirect when is new user

* 🎨 chore: improve code
  • Loading branch information
arvinxx authored Nov 7, 2023
1 parent 9af165c commit 3d2588a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { PluginRequestPayload } from '@lobehub/chat-plugin-sdk';
import { Skeleton } from 'antd';
import { memo, useRef, useState } from 'react';

import { useOnPluginSettingsUpdate } from '@/app/chat/features/Conversation/ChatList/Plugins/Render/utils/pluginSettings';
import { useOnPluginStateUpdate } from '@/app/chat/features/Conversation/ChatList/Plugins/Render/utils/pluginState';
import { pluginSelectors, usePluginStore } from '@/store/plugin';
import { useSessionStore } from '@/store/session';
import { chatSelectors } from '@/store/session/selectors';
Expand All @@ -15,6 +13,8 @@ import {
useOnPluginFetchPluginState,
useOnPluginFillContent,
} from '../utils/listenToPlugin';
import { useOnPluginSettingsUpdate } from '../utils/pluginSettings';
import { useOnPluginStateUpdate } from '../utils/pluginState';
import {
sendMessageContentToPlugin,
sendPayloadToPlugin,
Expand Down
4 changes: 2 additions & 2 deletions src/app/home/Redirect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const Redirect = memo(() => {
useEffect(() => {
useSessionStore.persist.onFinishHydration(() => {
const store = useSessionStore.getState();
const hasSession = sessionSelectors.hasSessionList(store);
const hasConversion = sessionSelectors.hasConversion(store);

if (hasSession) {
if (hasConversion) {
router.push('/chat');
store.switchSession();
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/store/session/hooks/useSessionHydrated.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useState } from 'react';

import { sessionSelectors } from '../selectors';
import { useSessionStore } from '../store';
import { useEffectAfterSessionHydrated } from './useEffectAfterHydrated';

export const useSessionHydrated = () => {
// 根据 sessions 是否有值来判断是否已经初始化
const hasInited = !!Object.values(useSessionStore.getState().sessions).length;
const hasInited = sessionSelectors.hasConversion(useSessionStore.getState());

const [isInit, setInit] = useState(hasInited);

Expand Down
2 changes: 2 additions & 0 deletions src/store/session/slices/session/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
currentSessionSafe,
getSessionById,
getSessionMetaById,
hasConversion,
hasPinnedSessionList,
hasSessionList,
pinnedSessionList,
Expand All @@ -24,6 +25,7 @@ export const sessionSelectors = {
getExportAgent,
getSessionById,
getSessionMetaById,
hasConversion,
hasPinnedSessionList,
hasSessionList,
isInboxSession,
Expand Down
7 changes: 7 additions & 0 deletions src/store/session/slices/session/selectors/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,10 @@ export const getSessionMetaById =
//
// return sessionTree;
// };

export const hasConversion = (s: SessionStore) => {
const hasCustomAgents = !!Object.keys(s.sessions).length;
const hasMessageInInbox = !!Object.keys(s.inbox.chats).length;

return hasCustomAgents || hasMessageInInbox;
};

0 comments on commit 3d2588a

Please sign in to comment.