mirror of
https://github.com/langgenius/dify.git
synced 2025-12-08 00:42:03 +00:00
Signed-off-by: NeatGuyCoding <15627489+NeatGuyCoding@users.noreply.github.com> Signed-off-by: lyzno1 <yuanyouhuilyz@gmail.com> Signed-off-by: kenwoodjw <blackxin55+@gmail.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Yunlu Wen <wylswz@163.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: GareArc <chen4851@purdue.edu> Co-authored-by: NFish <douxc512@gmail.com> Co-authored-by: Davide Delbianco <davide.delbianco@outlook.com> Co-authored-by: minglu7 <1347866672@qq.com> Co-authored-by: Ponder <ruan.lj@foxmail.com> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: heyszt <270985384@qq.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org> Co-authored-by: Guangdong Liu <liugddx@gmail.com> Co-authored-by: Eric Guo <eric.guocz@gmail.com> Co-authored-by: NeatGuyCoding <15627489+NeatGuyCoding@users.noreply.github.com> Co-authored-by: XlKsyt <caixuesen@outlook.com> Co-authored-by: Dhruv Gorasiya <80987415+DhruvGorasiya@users.noreply.github.com> Co-authored-by: crazywoola <427733928@qq.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: lyzno1 <92089059+lyzno1@users.noreply.github.com> Co-authored-by: hj24 <mambahj24@gmail.com> Co-authored-by: GuanMu <ballmanjq@gmail.com> Co-authored-by: 非法操作 <hjlarry@163.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Tonlo <123lzs123@gmail.com> Co-authored-by: Yusuke Yamada <yamachu.dev@gmail.com> Co-authored-by: Novice <novice12185727@gmail.com> Co-authored-by: kenwoodjw <blackxin55+@gmail.com> Co-authored-by: Ademílson Tonato <ademilsonft@outlook.com> Co-authored-by: znn <jubinkumarsoni@gmail.com> Co-authored-by: yangzheli <43645580+yangzheli@users.noreply.github.com>
210 lines
5.6 KiB
TypeScript
210 lines
5.6 KiB
TypeScript
'use client'
|
|
import type { FC } from 'react'
|
|
import {
|
|
useEffect,
|
|
useState,
|
|
} from 'react'
|
|
import { useThemeContext } from '../embedded-chatbot/theme/theme-context'
|
|
import {
|
|
ChatWithHistoryContext,
|
|
useChatWithHistoryContext,
|
|
} from './context'
|
|
import { useChatWithHistory } from './hooks'
|
|
import Sidebar from './sidebar'
|
|
import Header from './header'
|
|
import HeaderInMobile from './header-in-mobile'
|
|
import ChatWrapper from './chat-wrapper'
|
|
import type { InstalledApp } from '@/models/explore'
|
|
import Loading from '@/app/components/base/loading'
|
|
import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
|
|
import cn from '@/utils/classnames'
|
|
import useDocumentTitle from '@/hooks/use-document-title'
|
|
|
|
type ChatWithHistoryProps = {
|
|
className?: string
|
|
}
|
|
const ChatWithHistory: FC<ChatWithHistoryProps> = ({
|
|
className,
|
|
}) => {
|
|
const {
|
|
appData,
|
|
appChatListDataLoading,
|
|
chatShouldReloadKey,
|
|
isMobile,
|
|
themeBuilder,
|
|
sidebarCollapseState,
|
|
} = useChatWithHistoryContext()
|
|
const isSidebarCollapsed = sidebarCollapseState
|
|
const customConfig = appData?.custom_config
|
|
const site = appData?.site
|
|
|
|
const [showSidePanel, setShowSidePanel] = useState(false)
|
|
|
|
useEffect(() => {
|
|
themeBuilder?.buildTheme(site?.chat_color_theme, site?.chat_color_theme_inverted)
|
|
}, [site, customConfig, themeBuilder])
|
|
|
|
useEffect(() => {
|
|
if (!isSidebarCollapsed)
|
|
setShowSidePanel(false)
|
|
}, [isSidebarCollapsed])
|
|
|
|
useDocumentTitle(site?.title || 'Chat')
|
|
|
|
return (
|
|
<div className={cn(
|
|
'flex h-full bg-background-default-burn',
|
|
isMobile && 'flex-col',
|
|
className,
|
|
)}>
|
|
{!isMobile && (
|
|
<div className={cn(
|
|
'flex w-[236px] flex-col p-1 pr-0 transition-all duration-200 ease-in-out',
|
|
isSidebarCollapsed && 'w-0 overflow-hidden !p-0',
|
|
)}>
|
|
<Sidebar />
|
|
</div>
|
|
)}
|
|
{isMobile && (
|
|
<HeaderInMobile />
|
|
)}
|
|
<div className={cn('relative grow p-2', isMobile && 'h-[calc(100%_-_56px)] p-0')}>
|
|
{isSidebarCollapsed && (
|
|
<div
|
|
className={cn(
|
|
'absolute top-0 z-20 flex h-full w-[256px] flex-col p-2 transition-all duration-500 ease-in-out',
|
|
showSidePanel ? 'left-0' : 'left-[-248px]',
|
|
)}
|
|
onMouseEnter={() => setShowSidePanel(true)}
|
|
onMouseLeave={() => setShowSidePanel(false)}
|
|
>
|
|
<Sidebar isPanel panelVisible={showSidePanel} />
|
|
</div>
|
|
)}
|
|
<div className={cn('flex h-full flex-col overflow-hidden border-[0,5px] border-components-panel-border-subtle bg-chatbot-bg', isMobile ? 'rounded-t-2xl' : 'rounded-2xl')}>
|
|
{!isMobile && <Header />}
|
|
{appChatListDataLoading && (
|
|
<Loading type='app' />
|
|
)}
|
|
{!appChatListDataLoading && (
|
|
<ChatWrapper key={chatShouldReloadKey} />
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export type ChatWithHistoryWrapProps = {
|
|
installedAppInfo?: InstalledApp
|
|
className?: string
|
|
}
|
|
const ChatWithHistoryWrap: FC<ChatWithHistoryWrapProps> = ({
|
|
installedAppInfo,
|
|
className,
|
|
}) => {
|
|
const media = useBreakpoints()
|
|
const isMobile = media === MediaType.mobile
|
|
const themeBuilder = useThemeContext()
|
|
|
|
const {
|
|
appData,
|
|
appParams,
|
|
appMeta,
|
|
appChatListDataLoading,
|
|
currentConversationId,
|
|
currentConversationItem,
|
|
appPrevChatTree,
|
|
pinnedConversationList,
|
|
conversationList,
|
|
newConversationInputs,
|
|
newConversationInputsRef,
|
|
handleNewConversationInputsChange,
|
|
inputsForms,
|
|
handleNewConversation,
|
|
handleStartChat,
|
|
handleChangeConversation,
|
|
handlePinConversation,
|
|
handleUnpinConversation,
|
|
handleDeleteConversation,
|
|
conversationRenaming,
|
|
handleRenameConversation,
|
|
handleNewConversationCompleted,
|
|
chatShouldReloadKey,
|
|
isInstalledApp,
|
|
appId,
|
|
handleFeedback,
|
|
currentChatInstanceRef,
|
|
sidebarCollapseState,
|
|
handleSidebarCollapse,
|
|
clearChatList,
|
|
setClearChatList,
|
|
isResponding,
|
|
setIsResponding,
|
|
currentConversationInputs,
|
|
setCurrentConversationInputs,
|
|
allInputsHidden,
|
|
initUserVariables,
|
|
} = useChatWithHistory(installedAppInfo)
|
|
|
|
return (
|
|
<ChatWithHistoryContext.Provider value={{
|
|
appData,
|
|
appParams,
|
|
appMeta,
|
|
appChatListDataLoading,
|
|
currentConversationId,
|
|
currentConversationItem,
|
|
appPrevChatTree,
|
|
pinnedConversationList,
|
|
conversationList,
|
|
newConversationInputs,
|
|
newConversationInputsRef,
|
|
handleNewConversationInputsChange,
|
|
inputsForms,
|
|
handleNewConversation,
|
|
handleStartChat,
|
|
handleChangeConversation,
|
|
handlePinConversation,
|
|
handleUnpinConversation,
|
|
handleDeleteConversation,
|
|
conversationRenaming,
|
|
handleRenameConversation,
|
|
handleNewConversationCompleted,
|
|
chatShouldReloadKey,
|
|
isMobile,
|
|
isInstalledApp,
|
|
appId,
|
|
handleFeedback,
|
|
currentChatInstanceRef,
|
|
themeBuilder,
|
|
sidebarCollapseState,
|
|
handleSidebarCollapse,
|
|
clearChatList,
|
|
setClearChatList,
|
|
isResponding,
|
|
setIsResponding,
|
|
currentConversationInputs,
|
|
setCurrentConversationInputs,
|
|
allInputsHidden,
|
|
initUserVariables,
|
|
}}>
|
|
<ChatWithHistory className={className} />
|
|
</ChatWithHistoryContext.Provider>
|
|
)
|
|
}
|
|
|
|
const ChatWithHistoryWrapWithCheckToken: FC<ChatWithHistoryWrapProps> = ({
|
|
installedAppInfo,
|
|
className,
|
|
}) => {
|
|
return (
|
|
<ChatWithHistoryWrap
|
|
installedAppInfo={installedAppInfo}
|
|
className={className}
|
|
/>
|
|
)
|
|
}
|
|
|
|
export default ChatWithHistoryWrapWithCheckToken
|