Commit 7e647cc6 authored by JzoNg's avatar JzoNg

fix page title update

parent ec710d7f
'use client' 'use client'
import type { FC } from 'react' import type { FC } from 'react'
import React, { useEffect, useMemo } from 'react' import React, { useCallback, useEffect, useState } from 'react'
import { usePathname, useRouter } from 'next/navigation' import { usePathname, useRouter } from 'next/navigation'
import cn from 'classnames' import cn from 'classnames'
import useSWR from 'swr'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import s from './style.module.css' import s from './style.module.css'
import { useStore } from '@/app/components/app/store' import { useStore } from '@/app/components/app/store'
import AppSideBar from '@/app/components/app-sidebar' import AppSideBar from '@/app/components/app-sidebar'
import type { NavIcon } from '@/app/components/app-sidebar/navLink'
import { fetchAppDetail } from '@/service/apps' import { fetchAppDetail } from '@/service/apps'
import { useAppContext } from '@/context/app-context' import { useAppContext } from '@/context/app-context'
import { BarChartSquare02, FileHeart02, PromptEngineering, TerminalSquare } from '@/app/components/base/icons/src/vender/line/development' import { BarChartSquare02, FileHeart02, PromptEngineering, TerminalSquare } from '@/app/components/base/icons/src/vender/line/development'
...@@ -28,15 +28,19 @@ const AppDetailLayout: FC<IAppDetailLayoutProps> = (props) => { ...@@ -28,15 +28,19 @@ const AppDetailLayout: FC<IAppDetailLayoutProps> = (props) => {
const pathname = usePathname() const pathname = usePathname()
const { isCurrentWorkspaceManager } = useAppContext() const { isCurrentWorkspaceManager } = useAppContext()
const { appDetail, setAppDetail } = useStore() const { appDetail, setAppDetail } = useStore()
const detailParams = { url: '/apps', id: appId } const [navigation, setNavigation] = useState<Array<{
const { data: response } = useSWR(detailParams, fetchAppDetail) name: string
href: string
icon: NavIcon
selectedIcon: NavIcon
}>>([])
const navigation = useMemo(() => { const getNavigations = useCallback((appId: string, isCurrentWorkspaceManager: boolean, mode: string) => {
const navs = [ const navs = [
...(isCurrentWorkspaceManager ...(isCurrentWorkspaceManager
? [{ ? [{
name: t('common.appMenus.promptEng'), name: t('common.appMenus.promptEng'),
href: `/app/${appId}/${(response?.mode === 'workflow' || response?.mode === 'advanced-chat') ? 'workflow' : 'configuration'}`, href: `/app/${appId}/${(mode === 'workflow' || mode === 'advanced-chat') ? 'workflow' : 'configuration'}`,
icon: PromptEngineering, icon: PromptEngineering,
selectedIcon: PromptEngineeringSolid, selectedIcon: PromptEngineeringSolid,
}] }]
...@@ -49,7 +53,7 @@ const AppDetailLayout: FC<IAppDetailLayoutProps> = (props) => { ...@@ -49,7 +53,7 @@ const AppDetailLayout: FC<IAppDetailLayoutProps> = (props) => {
selectedIcon: TerminalSquareSolid, selectedIcon: TerminalSquareSolid,
}, },
{ {
name: response?.mode !== 'workflow' name: mode !== 'workflow'
? t('common.appMenus.logAndAnn') ? t('common.appMenus.logAndAnn')
: t('common.appMenus.logs'), : t('common.appMenus.logs'),
href: `/app/${appId}/logs`, href: `/app/${appId}/logs`,
...@@ -64,18 +68,20 @@ const AppDetailLayout: FC<IAppDetailLayoutProps> = (props) => { ...@@ -64,18 +68,20 @@ const AppDetailLayout: FC<IAppDetailLayoutProps> = (props) => {
}, },
] ]
return navs return navs
}, [appId, isCurrentWorkspaceManager, response?.mode, t]) }, [t])
useEffect(() => { useEffect(() => {
if (response && !appDetail) if (appDetail)
setAppDetail(response)
}, [appDetail, response, setAppDetail])
useEffect(() => {
if (appDetail?.name)
document.title = `${(appDetail.name || 'App')} - Dify` document.title = `${(appDetail.name || 'App')} - Dify`
}, [appDetail]) }, [appDetail])
useEffect(() => {
fetchAppDetail({ url: '/apps', id: appId }).then((res) => {
setAppDetail(res)
setNavigation(getNavigations(appId, isCurrentWorkspaceManager, res.mode))
})
}, [appId, getNavigations, isCurrentWorkspaceManager, setAppDetail])
if (!appDetail) if (!appDetail)
return null return null
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment