feature: infinite scroll (#119)
Add infinite scroll support to app list and dataset list.
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
'use client'
|
||||
|
||||
import { createContext, useContext } from 'use-context-selector'
|
||||
import type { App } from '@/types/app'
|
||||
import type { UserProfileResponse } from '@/models/common'
|
||||
|
||||
export type AppContextValue = {
|
||||
apps: App[]
|
||||
mutateApps: () => void
|
||||
userProfile: UserProfileResponse
|
||||
mutateUserProfile: () => void
|
||||
}
|
||||
|
||||
const AppContext = createContext<AppContextValue>({
|
||||
apps: [],
|
||||
mutateApps: () => { },
|
||||
userProfile: {
|
||||
id: '',
|
||||
name: '',
|
||||
email: '',
|
||||
},
|
||||
mutateUserProfile: () => { },
|
||||
})
|
||||
|
||||
export const useAppContext = () => useContext(AppContext)
|
||||
|
||||
export default AppContext
|
45
web/context/app-context.tsx
Normal file
45
web/context/app-context.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
'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
|
Reference in New Issue
Block a user