mirror of
https://gitee.com/dify_ai/dify.git
synced 2024-12-04 20:28:12 +08:00
4779fcf6f1
Add infinite scroll support to app list and dataset list.
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
'use client'
|
|
|
|
import { createContext, useContext, useContextSelector } from 'use-context-selector'
|
|
import type { App } from '@/types/app'
|
|
import type { UserProfileResponse } from '@/models/common'
|
|
import { createRef, FC, PropsWithChildren } from 'react'
|
|
|
|
export const useSelector = <T extends any>(selector: (value: AppContextValue) => T): T =>
|
|
useContextSelector(AppContext, selector);
|
|
|
|
export type AppContextValue = {
|
|
apps: App[]
|
|
mutateApps: () => void
|
|
userProfile: UserProfileResponse
|
|
mutateUserProfile: () => void
|
|
pageContainerRef: React.RefObject<HTMLDivElement>,
|
|
useSelector: typeof useSelector,
|
|
}
|
|
|
|
const AppContext = createContext<AppContextValue>({
|
|
apps: [],
|
|
mutateApps: () => { },
|
|
userProfile: {
|
|
id: '',
|
|
name: '',
|
|
email: '',
|
|
},
|
|
mutateUserProfile: () => { },
|
|
pageContainerRef: createRef(),
|
|
useSelector,
|
|
})
|
|
|
|
export type AppContextProviderProps = PropsWithChildren<{
|
|
value: Omit<AppContextValue, 'useSelector'>
|
|
}>
|
|
|
|
export const AppContextProvider: FC<AppContextProviderProps> = ({ value, children }) => (
|
|
<AppContext.Provider value={{ ...value, useSelector }}>
|
|
{children}
|
|
</AppContext.Provider>
|
|
)
|
|
|
|
export const useAppContext = () => useContext(AppContext)
|
|
|
|
export default AppContext
|