Skip to content

Commit

Permalink
fix: load first page of uploads list in provider (#288)
Browse files Browse the repository at this point in the history
rather than doing this in the headless component, do it in the Provider
so that all users (especially hook users) automatically get a first page of results
  • Loading branch information
travis authored Jan 25, 2023
1 parent e2a833e commit 6778d6c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 1 addition & 5 deletions packages/react-uploads-list/src/UploadsList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { As, Component, Props, Options, RenderProp } from 'ariakit-react-utils'
import type { UploadsListContextState, UploadsListContextActions } from '@w3ui/uploads-list-core'

import React, { Fragment, createContext, useContext, useMemo, useCallback, useEffect } from 'react'
import React, { Fragment, createContext, useContext, useMemo, useCallback } from 'react'
import { createComponent, createElement } from 'ariakit-react-utils'
import { useUploadsList } from './providers/UploadsList'

Expand Down Expand Up @@ -68,10 +68,6 @@ export const UploadsListRoot = (props: UploadsListRootProps): JSX.Element => {
} else {
renderedChildren = children as React.ReactNode
}
useEffect(() => {
// load the first page of results asynchronously
void actions.next()
}, [])
return (
<UploadsListComponentContext.Provider value={contextValue}>
{renderedChildren}
Expand Down
5 changes: 4 additions & 1 deletion packages/react-uploads-list/src/providers/UploadsList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, createContext, useState } from 'react'
import React, { useContext, createContext, useState, useEffect } from 'react'
import { UploadListResult, UploadsListContextState, UploadsListContextActions, ServiceConfig, list } from '@w3ui/uploads-list-core'
import { useKeyring } from '@w3ui/react-keyring'
import { list as uploadList } from '@web3-storage/capabilities/upload'
Expand Down Expand Up @@ -82,6 +82,9 @@ export function UploadsListProvider ({ size, servicePrincipal, connection, child
}
}

// we should reload the page any time the space or agent change
useEffect(() => { void loadPage() }, [space, agent])

return (
<UploadsListContext.Provider value={[state, actions]}>
{children}
Expand Down

0 comments on commit 6778d6c

Please sign in to comment.