dify/web/app/components/explore/index.tsx

57 lines
1.8 KiB
TypeScript
Raw Normal View History

2023-05-25 16:59:47 +08:00
'use client'
import type { FC } from 'react'
import React, { useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
2023-05-25 16:59:47 +08:00
import ExploreContext from '@/context/explore-context'
import Sidebar from '@/app/components/explore/sidebar'
import { useAppContext } from '@/context/app-context'
import { fetchMembers } from '@/service/common'
import type { InstalledApp } from '@/models/explore'
2023-05-25 16:59:47 +08:00
export type IExploreProps = {
2023-05-25 16:59:47 +08:00
children: React.ReactNode
}
const Explore: FC<IExploreProps> = ({
children,
2023-05-25 16:59:47 +08:00
}) => {
2023-05-25 22:13:43 +08:00
const { t } = useTranslation()
2023-05-25 16:59:47 +08:00
const [controlUpdateInstalledApps, setControlUpdateInstalledApps] = useState(0)
const { userProfile } = useAppContext()
const [hasEditPermission, setHasEditPermission] = useState(false)
const [installedApps, setInstalledApps] = useState<InstalledApp[]>([])
useEffect(() => {
2023-05-25 22:13:43 +08:00
document.title = `${t('explore.title')} - Dify`;
2023-05-25 16:59:47 +08:00
(async () => {
const { accounts } = await fetchMembers({ url: '/workspaces/current/members', params: {} })
if (!accounts)
return
2023-05-25 16:59:47 +08:00
const currUser = accounts.find(account => account.id === userProfile.id)
setHasEditPermission(currUser?.role !== 'normal')
})()
}, [])
return (
2023-11-28 20:05:19 +08:00
<div className='flex h-full bg-gray-100 border-t border-gray-200 overflow-hidden'>
2023-05-25 16:59:47 +08:00
<ExploreContext.Provider
value={
{
controlUpdateInstalledApps,
setControlUpdateInstalledApps,
hasEditPermission,
installedApps,
setInstalledApps,
2023-05-25 16:59:47 +08:00
}
}
>
<Sidebar controlUpdateInstalledApps={controlUpdateInstalledApps} />
2024-02-04 16:10:46 +08:00
<div className='grow w-0'>
2023-05-25 16:59:47 +08:00
{children}
</div>
</ExploreContext.Provider>
</div>
)
}
export default React.memo(Explore)