Skip to content

Commit

Permalink
improve provider state type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesmac committed Feb 12, 2025
1 parent 6149252 commit a13c4d3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { PayloadListContext } from './Context.tsx'
import {
useNextPayloads, useTableUi, useTotalPayloads,
} from './hooks/index.ts'
import type { PayloadListState, UIState } from './State.ts'
import type {
PayloadListState, TotalPayloadsState, UIState,
} from './State.ts'

export interface PayloadListProviderProps extends PropsWithChildren {
archivist?: ArchivistInstance
Expand Down Expand Up @@ -52,33 +54,38 @@ export const PayloadListProvider: React.FC<PayloadListProviderProps> = ({
nextOptions,
)

const uiState: UIState = useMemo(() => ({
loading,
scrollRef,
scrollTo,
updateLoading,
}), [loading, scrollRef, scrollToTop])
const uiState: UIState = useMemo(() => {
const uiState: UIState = {
loading,
scrollRef,
scrollToTop,
updateLoading,
}
return uiState
}, [loading, scrollRef, scrollToTop])

const totalPayloadsState = useMemo(() => ({
cursor,
fetchMorePayloads,
totalPayloads,
totalPayloadsCount,
updateCursor,
updateTotalPayloads,
}), [cursor, fetchMorePayloads, totalPayloads, totalPayloadsCount])
const totalPayloadsState = useMemo(() => {
const totalPayloadsState: TotalPayloadsState = {
cursor,
fetchMorePayloads,
totalPayloads,
totalPayloadsCount,
updateCursor,
updateTotalPayloads,
}
return totalPayloadsState
}, [cursor, fetchMorePayloads, totalPayloads, totalPayloadsCount])

const value = useMemo<PayloadListState>(() => ({
errors: [newPayloadsError],
provided: true,
resetList,
totalPayloadsState,
uiState,
}), [
newPayloadsError,
resetList,
uiState,
totalPayloadsState])
const value = useMemo(() => {
const payloadListState: PayloadListState = {
errors: [newPayloadsError],
provided: true,
totalPayloadsState,
resetList,
uiState,
}
return payloadListState
}, [newPayloadsError, totalPayloadsState, resetList, uiState])

return (
<PayloadListContext.Provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface TotalPayloadsState {

export interface PayloadListState extends ContextExState {
errors?: (Error | undefined)[]
payloadState?: TotalPayloadsState
resetList?: () => void
totalPayloadsState?: TotalPayloadsState
uiState?: UIState
}

0 comments on commit a13c4d3

Please sign in to comment.