Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
feat: ✨ update default tab
Browse files Browse the repository at this point in the history
  • Loading branch information
AruSeito committed Apr 30, 2024
1 parent 8ba6fdd commit 9deef9a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion apps/agent/src/Layout/Workspace/pc/modules/Menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ const PCWorkspaceMenu: FC = () => {
className="divider"
/>
</div>
{recentTabInfos.length > 1 && (
{recentTabInfos.length > 0 && (
<div
css={closeAllContainerStyle}
onClick={handleClickCloseAll}
Expand Down
3 changes: 2 additions & 1 deletion apps/agent/src/page/WorkSpace/Chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { FC, lazy, useEffect } from "react"
import { useParams } from "react-router-dom"
import { LayoutAutoChange } from "@illa-public/layout-auto-change"
import { TipisWebSocketProvider } from "@/components/PreviewChat/TipisWebscoketContext"
import { DEFAULT_CHAT_ID } from "@/redux/ui/recentTab/state"
import { useAddChatTab } from "@/utils/recentTabs/hook"
import { ChatWSProvider } from "./context"

Expand All @@ -13,7 +14,7 @@ const ChatPage: FC = () => {
const addChatTab = useAddChatTab()

useEffect(() => {
if (chatID) {
if (chatID && chatID !== DEFAULT_CHAT_ID) {
addChatTab(chatID)
}
}, [addChatTab, chatID])
Expand Down
12 changes: 11 additions & 1 deletion apps/agent/src/page/WorkSpace/Chat/module/chatHistory.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FC, useCallback, useContext, useEffect, useMemo } from "react"
import { useParams } from "react-router-dom"
import { TextSignal } from "@/api/ws/textSignal"
import { PreviewChat } from "@/components/PreviewChat"
import { PreviewChatUseProvider } from "@/components/PreviewChat/PreviewChatUseContext"
Expand All @@ -8,17 +9,23 @@ import {
ChatMessage,
ChatSendRequestPayload,
} from "@/components/PreviewChat/interface"
import { DEFAULT_CHAT_ID } from "@/redux/ui/recentTab/state"
import { useAddChatTab } from "@/utils/recentTabs/hook"
import { ChatContext } from "../../AI/components/ChatContext"
import { ChatStableWSContext, ChatUnStableWSContext } from "../context"
import { INIT_CHAT_CONFIG } from "./constants"
import { rightPanelContainerStyle } from "./style"

export const ChatHistory: FC = () => {
const { chatID } = useParams()

const { connect, leaveRoom, sendMessage } = useContext(ChatStableWSContext)

const { getReadyState, isRunning, chatMessages, isReceiving, inRoomUsers } =
useContext(ChatUnStableWSContext)

const addChatTab = useAddChatTab()

const wsContext = useMemo(
() => ({
getReadyState,
Expand All @@ -32,6 +39,9 @@ export const ChatHistory: FC = () => {

const onSendMessage = useCallback(
(message: ChatMessage) => {
if (DEFAULT_CHAT_ID === chatID) {
addChatTab(DEFAULT_CHAT_ID)
}
sendMessage(
{
threadID: message.threadID,
Expand All @@ -47,7 +57,7 @@ export const ChatHistory: FC = () => {
},
)
},
[sendMessage],
[addChatTab, chatID, sendMessage],
)

useEffect(() => {
Expand Down
5 changes: 2 additions & 3 deletions apps/agent/src/redux/ui/recentTab/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { CaseReducer, PayloadAction } from "@reduxjs/toolkit"
import { IRecentTabState, ITabInfo } from "./interface"
import { DEFAULT_CHAT_ID, INIT_TABS } from "./state"

export const setRecentTabReducer: CaseReducer<
IRecentTabState,
Expand Down Expand Up @@ -67,8 +66,8 @@ export const deleteRecentTabByCacheIDReducer: CaseReducer<
export const deleteAllRecentTabReducer: CaseReducer<IRecentTabState> = (
state,
) => {
state.tabs = INIT_TABS
state.currentTabID = DEFAULT_CHAT_ID
state.tabs = []
state.currentTabID = ""
}

export const updateRecentTabReducer: CaseReducer<
Expand Down
14 changes: 2 additions & 12 deletions apps/agent/src/redux/ui/recentTab/state.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import { IRecentTabState, ITabInfo, TAB_TYPE } from "./interface"
import { IRecentTabState } from "./interface"

export const DEFAULT_CHAT_ID = "DEFAULT_CHAT"

export const INIT_TABS: ITabInfo[] = [
{
tabName: "",
tabIcon: "",
tabType: TAB_TYPE.CHAT,
tabID: DEFAULT_CHAT_ID,
cacheID: DEFAULT_CHAT_ID,
},
]

export const recentTabInitState: IRecentTabState = {
currentTabID: DEFAULT_CHAT_ID,
tabs: INIT_TABS,
tabs: [],
}
9 changes: 4 additions & 5 deletions apps/agent/src/utils/localForage/recentTab.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { klona } from "klona/json"
import { ITabInfo } from "@/redux/ui/recentTab/interface"
import { DEFAULT_CHAT_ID, INIT_TABS } from "@/redux/ui/recentTab/state"
import { DEFAULT_CHAT_ID } from "@/redux/ui/recentTab/state"
import { ITeamData } from "./interface"
import { getTeamDataByTeamID, setTeamDataByTeamID } from "./teamData"

export const getRecentTabs = async (teamID: string) => {
const teamData = await getTeamDataByTeamID(teamID)
if (!teamData) {
await setRecentTabs(teamID, INIT_TABS)
return INIT_TABS
return []
}
const tabsInfo = teamData.tabsInfo ?? INIT_TABS
const tabsInfo = teamData.tabsInfo ?? []
return tabsInfo
}

Expand Down Expand Up @@ -70,7 +69,7 @@ export const removeAllRecentTabsAndCacheData = async (teamID: string) => {
if (!teamData) return
const newTeamData = klona(teamData)
const defaultCache = teamData.uiHistory?.[DEFAULT_CHAT_ID] ?? {}
newTeamData.tabsInfo = INIT_TABS
newTeamData.tabsInfo = []
newTeamData.uiHistory = {
[DEFAULT_CHAT_ID]: defaultCache,
}
Expand Down

0 comments on commit 9deef9a

Please sign in to comment.