mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
add store of app detail
This commit is contained in:
@ -6,6 +6,7 @@ import cn from 'classnames'
|
||||
import useSWR from 'swr'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import s from './style.module.css'
|
||||
import { useStore } from '@/app/components/app/store'
|
||||
import AppSideBar from '@/app/components/app-sidebar'
|
||||
import { fetchAppDetail } from '@/service/apps'
|
||||
import { useAppContext } from '@/context/app-context'
|
||||
@ -27,14 +28,9 @@ const AppDetailLayout: FC<IAppDetailLayoutProps> = (props) => {
|
||||
const pathname = usePathname()
|
||||
const { isCurrentWorkspaceManager } = useAppContext()
|
||||
const detailParams = { url: '/apps', id: appId }
|
||||
const { appDetail, setAppDetail } = useStore()
|
||||
const { data: response } = useSWR(detailParams, fetchAppDetail)
|
||||
|
||||
// redirections
|
||||
if (response && (response?.mode === 'workflow' || response?.mode === 'advanced-chat') && (pathname).endsWith('configuration'))
|
||||
router.replace(`/app/${appId}/workflow`)
|
||||
if (response && (response?.mode !== 'workflow' && response?.mode !== 'advanced-chat') && (pathname).endsWith('workflow'))
|
||||
router.replace(`/app/${appId}/configuration`)
|
||||
|
||||
const appModeName = (() => {
|
||||
if (response?.mode === 'chat' || response?.mode === 'advanced-chat')
|
||||
return t('app.types.chatbot')
|
||||
@ -86,10 +82,19 @@ const AppDetailLayout: FC<IAppDetailLayoutProps> = (props) => {
|
||||
useEffect(() => {
|
||||
if (response?.name)
|
||||
document.title = `${(response.name || 'App')} - Dify`
|
||||
}, [response])
|
||||
if (response && response !== appDetail)
|
||||
setAppDetail(response)
|
||||
}, [appDetail, response, setAppDetail])
|
||||
|
||||
if (!response)
|
||||
return null
|
||||
|
||||
// redirections
|
||||
if (response && (response?.mode === 'workflow' || response?.mode === 'advanced-chat') && (pathname).endsWith('configuration'))
|
||||
router.replace(`/app/${appId}/workflow`)
|
||||
if (response && (response?.mode !== 'workflow' && response?.mode !== 'advanced-chat') && (pathname).endsWith('workflow'))
|
||||
router.replace(`/app/${appId}/configuration`)
|
||||
|
||||
return (
|
||||
<div className={cn(s.app, 'flex', 'overflow-hidden')}>
|
||||
<AppSideBar title={response.name} icon={response.icon} icon_background={response.icon_background} desc={appModeName} navigation={navigation} />
|
||||
|
||||
@ -22,6 +22,7 @@ import type { HtmlContentProps } from '@/app/components/base/popover'
|
||||
import CustomPopover from '@/app/components/base/popover'
|
||||
import Divider from '@/app/components/base/divider'
|
||||
import { asyncRunSafe } from '@/utils'
|
||||
import { getRedirection } from '@/utils/app-redirection'
|
||||
import { useProviderContext } from '@/context/provider-context'
|
||||
import { NEED_REFRESH_APP_LIST_KEY } from '@/config'
|
||||
|
||||
@ -207,8 +208,7 @@ const AppCard = ({ app, onRefresh }: AppCardProps) => {
|
||||
if (showSettingsModal)
|
||||
return
|
||||
e.preventDefault()
|
||||
|
||||
push(`/app/${app.id}/${isCurrentWorkspaceManager ? 'configuration' : 'overview'}`)
|
||||
getRedirection(isCurrentWorkspaceManager, app, push)
|
||||
}}
|
||||
className={style.listItem}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user