mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-18 04:25:54 +08:00
plugin page context
This commit is contained in:
parent
466f61d044
commit
fcf43ee845
@ -1,10 +1,10 @@
|
|||||||
|
import PluginPage from '@/app/components/plugins/plugin-page'
|
||||||
import PluginsPanel from '@/app/components/plugins/plugins-panel'
|
import PluginsPanel from '@/app/components/plugins/plugins-panel'
|
||||||
import Container from '@/app/components/plugins/container'
|
|
||||||
import Marketplace from '@/app/components/plugins/marketplace'
|
import Marketplace from '@/app/components/plugins/marketplace'
|
||||||
|
|
||||||
const PluginList = async () => {
|
const PluginList = async () => {
|
||||||
return (
|
return (
|
||||||
<Container
|
<PluginPage
|
||||||
plugins={<PluginsPanel />}
|
plugins={<PluginsPanel />}
|
||||||
marketplace={<Marketplace />}
|
marketplace={<Marketplace />}
|
||||||
/>
|
/>
|
||||||
|
30
web/app/components/plugins/plugin-page/context.tsx
Normal file
30
web/app/components/plugins/plugin-page/context.tsx
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import type { ReactNode } from 'react'
|
||||||
|
import { useRef } from 'react'
|
||||||
|
import { createContext } from 'use-context-selector'
|
||||||
|
|
||||||
|
export type PluginPageContextValue = {
|
||||||
|
containerRef: React.RefObject<HTMLDivElement>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const PluginPageContext = createContext<PluginPageContextValue>({
|
||||||
|
containerRef: { current: null },
|
||||||
|
})
|
||||||
|
|
||||||
|
type PluginPageContextProviderProps = {
|
||||||
|
children: ReactNode
|
||||||
|
}
|
||||||
|
|
||||||
|
export const PluginPageContextProvider = ({
|
||||||
|
children,
|
||||||
|
}: PluginPageContextProviderProps) => {
|
||||||
|
const containerRef = useRef<HTMLDivElement>(null)
|
||||||
|
return (
|
||||||
|
<PluginPageContext.Provider value={{
|
||||||
|
containerRef,
|
||||||
|
}}>
|
||||||
|
{children}
|
||||||
|
</PluginPageContext.Provider>
|
||||||
|
)
|
||||||
|
}
|
@ -1,14 +1,19 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useMemo, useRef } from 'react'
|
import { useMemo } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { useContextSelector } from 'use-context-selector'
|
||||||
import {
|
import {
|
||||||
RiArrowRightUpLine,
|
RiArrowRightUpLine,
|
||||||
RiBugLine,
|
RiBugLine,
|
||||||
RiClipboardLine,
|
RiClipboardLine,
|
||||||
RiEqualizer2Line,
|
RiEqualizer2Line,
|
||||||
} from '@remixicon/react'
|
} from '@remixicon/react'
|
||||||
import InstallPluginDropdown from './Install-plugin-dropdown'
|
import {
|
||||||
|
PluginPageContext,
|
||||||
|
PluginPageContextProvider,
|
||||||
|
} from './context'
|
||||||
|
import InstallPluginDropdown from './install-plugin-dropdown'
|
||||||
import { useTabSearchParams } from '@/hooks/use-tab-searchparams'
|
import { useTabSearchParams } from '@/hooks/use-tab-searchparams'
|
||||||
import { useModalContext } from '@/context/modal-context'
|
import { useModalContext } from '@/context/modal-context'
|
||||||
import Button from '@/app/components/base/button'
|
import Button from '@/app/components/base/button'
|
||||||
@ -17,16 +22,17 @@ import ActionButton from '@/app/components/base/action-button'
|
|||||||
import Tooltip from '@/app/components/base/tooltip'
|
import Tooltip from '@/app/components/base/tooltip'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
|
|
||||||
type ContainerWrapperProps = {
|
export type PluginPageProps = {
|
||||||
plugins: React.ReactNode
|
plugins: React.ReactNode
|
||||||
marketplace: React.ReactNode
|
marketplace: React.ReactNode
|
||||||
}
|
}
|
||||||
const ContainerWrapper = ({
|
const PluginPage = ({
|
||||||
plugins,
|
plugins,
|
||||||
marketplace,
|
marketplace,
|
||||||
}: ContainerWrapperProps) => {
|
}: PluginPageProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { setShowPluginSettingModal } = useModalContext() as any
|
const { setShowPluginSettingModal } = useModalContext() as any
|
||||||
|
const containerRef = useContextSelector(PluginPageContext, v => v.containerRef)
|
||||||
|
|
||||||
const options = useMemo(() => {
|
const options = useMemo(() => {
|
||||||
return [
|
return [
|
||||||
@ -39,8 +45,6 @@ const ContainerWrapper = ({
|
|||||||
defaultTab: options[0].value,
|
defaultTab: options[0].value,
|
||||||
})
|
})
|
||||||
|
|
||||||
const containerRef = useRef<HTMLDivElement>(null)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={containerRef}
|
ref={containerRef}
|
||||||
@ -118,4 +122,12 @@ const ContainerWrapper = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ContainerWrapper
|
const PluginPageWithContext = (props: PluginPageProps) => {
|
||||||
|
return (
|
||||||
|
<PluginPageContextProvider>
|
||||||
|
<PluginPage {...props} />
|
||||||
|
</PluginPageContextProvider>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PluginPageWithContext
|
Loading…
x
Reference in New Issue
Block a user