mirror of
https://github.com/langgenius/dify.git
synced 2026-04-05 10:25:48 +08:00
fix: resolve chat sidebar UI bugs for hover panel and dropdown menu (#25813)
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@@ -230,4 +230,8 @@ api/.env.backup
|
|||||||
|
|
||||||
# Benchmark
|
# Benchmark
|
||||||
scripts/stress-test/setup/config/
|
scripts/stress-test/setup/config/
|
||||||
scripts/stress-test/reports/
|
scripts/stress-test/reports/
|
||||||
|
|
||||||
|
# mcp
|
||||||
|
.playwright-mcp/
|
||||||
|
.serena/
|
||||||
@@ -122,19 +122,31 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => {
|
|||||||
setLocaleFromProps()
|
setLocaleFromProps()
|
||||||
}, [appData])
|
}, [appData])
|
||||||
|
|
||||||
const [sidebarCollapseState, setSidebarCollapseState] = useState<boolean>(false)
|
const [sidebarCollapseState, setSidebarCollapseState] = useState<boolean>(() => {
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
try {
|
||||||
|
const localState = localStorage.getItem('webappSidebarCollapse')
|
||||||
|
return localState === 'collapsed'
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
// localStorage may be disabled in private browsing mode or by security settings
|
||||||
|
// fallback to default value
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
})
|
||||||
const handleSidebarCollapse = useCallback((state: boolean) => {
|
const handleSidebarCollapse = useCallback((state: boolean) => {
|
||||||
if (appId) {
|
if (appId) {
|
||||||
setSidebarCollapseState(state)
|
setSidebarCollapseState(state)
|
||||||
localStorage.setItem('webappSidebarCollapse', state ? 'collapsed' : 'expanded')
|
try {
|
||||||
|
localStorage.setItem('webappSidebarCollapse', state ? 'collapsed' : 'expanded')
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
// localStorage may be disabled, continue without persisting state
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [appId, setSidebarCollapseState])
|
}, [appId, setSidebarCollapseState])
|
||||||
useEffect(() => {
|
|
||||||
if (appId) {
|
|
||||||
const localState = localStorage.getItem('webappSidebarCollapse')
|
|
||||||
setSidebarCollapseState(localState === 'collapsed')
|
|
||||||
}
|
|
||||||
}, [appId])
|
|
||||||
const [conversationIdInfo, setConversationIdInfo] = useLocalStorageState<Record<string, Record<string, string>>>(CONVERSATION_ID_INFO, {
|
const [conversationIdInfo, setConversationIdInfo] = useLocalStorageState<Record<string, Record<string, string>>>(CONVERSATION_ID_INFO, {
|
||||||
defaultValue: {},
|
defaultValue: {},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -47,6 +47,11 @@ const ChatWithHistory: FC<ChatWithHistoryProps> = ({
|
|||||||
themeBuilder?.buildTheme(site?.chat_color_theme, site?.chat_color_theme_inverted)
|
themeBuilder?.buildTheme(site?.chat_color_theme, site?.chat_color_theme_inverted)
|
||||||
}, [site, customConfig, themeBuilder])
|
}, [site, customConfig, themeBuilder])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isSidebarCollapsed)
|
||||||
|
setShowSidePanel(false)
|
||||||
|
}, [isSidebarCollapsed])
|
||||||
|
|
||||||
useDocumentTitle(site?.title || 'Chat')
|
useDocumentTitle(site?.title || 'Chat')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -76,7 +81,7 @@ const ChatWithHistory: FC<ChatWithHistoryProps> = ({
|
|||||||
onMouseEnter={() => setShowSidePanel(true)}
|
onMouseEnter={() => setShowSidePanel(true)}
|
||||||
onMouseLeave={() => setShowSidePanel(false)}
|
onMouseLeave={() => setShowSidePanel(false)}
|
||||||
>
|
>
|
||||||
<Sidebar isPanel />
|
<Sidebar isPanel panelVisible={showSidePanel} />
|
||||||
</div>
|
</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')}>
|
<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')}>
|
||||||
|
|||||||
@@ -23,9 +23,10 @@ import { useGlobalPublicStore } from '@/context/global-public-context'
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
isPanel?: boolean
|
isPanel?: boolean
|
||||||
|
panelVisible?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const Sidebar = ({ isPanel }: Props) => {
|
const Sidebar = ({ isPanel, panelVisible }: Props) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const {
|
const {
|
||||||
isInstalledApp,
|
isInstalledApp,
|
||||||
@@ -138,7 +139,12 @@ const Sidebar = ({ isPanel }: Props) => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className='flex shrink-0 items-center justify-between p-3'>
|
<div className='flex shrink-0 items-center justify-between p-3'>
|
||||||
<MenuDropdown hideLogout={isInstalledApp} placement='top-start' data={appData?.site} />
|
<MenuDropdown
|
||||||
|
hideLogout={isInstalledApp}
|
||||||
|
placement='top-start'
|
||||||
|
data={appData?.site}
|
||||||
|
forceClose={isPanel && !panelVisible}
|
||||||
|
/>
|
||||||
{/* powered by */}
|
{/* powered by */}
|
||||||
<div className='shrink-0'>
|
<div className='shrink-0'>
|
||||||
{!appData?.custom_config?.remove_webapp_brand && (
|
{!appData?.custom_config?.remove_webapp_brand && (
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import React, { useCallback, useRef, useState } from 'react'
|
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import type { Placement } from '@floating-ui/react'
|
import type { Placement } from '@floating-ui/react'
|
||||||
import {
|
import {
|
||||||
@@ -25,12 +25,14 @@ type Props = {
|
|||||||
data?: SiteInfo
|
data?: SiteInfo
|
||||||
placement?: Placement
|
placement?: Placement
|
||||||
hideLogout?: boolean
|
hideLogout?: boolean
|
||||||
|
forceClose?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const MenuDropdown: FC<Props> = ({
|
const MenuDropdown: FC<Props> = ({
|
||||||
data,
|
data,
|
||||||
placement,
|
placement,
|
||||||
hideLogout,
|
hideLogout,
|
||||||
|
forceClose,
|
||||||
}) => {
|
}) => {
|
||||||
const webAppAccessMode = useWebAppStore(s => s.webAppAccessMode)
|
const webAppAccessMode = useWebAppStore(s => s.webAppAccessMode)
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -55,6 +57,11 @@ const MenuDropdown: FC<Props> = ({
|
|||||||
|
|
||||||
const [show, setShow] = useState(false)
|
const [show, setShow] = useState(false)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (forceClose)
|
||||||
|
setOpen(false)
|
||||||
|
}, [forceClose, setOpen])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PortalToFollowElem
|
<PortalToFollowElem
|
||||||
|
|||||||
Reference in New Issue
Block a user