Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add useInfiniteDataLoader #2282

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

DorianMaliszewski
Copy link
Member

Implement useInfiniteDataLoader to handle Load More on our UI

Copy link

changeset-bot bot commented Nov 6, 2024

🦋 Changeset detected

Latest commit: 6b32e34

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@scaleway/use-dataloader Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@DorianMaliszewski DorianMaliszewski added the enhancement New feature or request label Nov 6, 2024
Copy link

codecov bot commented Nov 6, 2024

Codecov Report

Attention: Patch coverage is 95.39171% with 10 lines in your changes missing coverage. Please review.

Project coverage is 91.62%. Comparing base (70b7464) to head (6b32e34).
Report is 77 commits behind head on main.

Files with missing lines Patch % Lines
packages/use-dataloader/src/DataLoaderProvider.tsx 16.66% 5 Missing ⚠️
...ckages/use-dataloader/src/useInfiniteDataLoader.ts 93.90% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2282      +/-   ##
==========================================
+ Coverage   91.26%   91.62%   +0.35%     
==========================================
  Files          47       49       +2     
  Lines        2371     2592     +221     
  Branches      104      118      +14     
==========================================
+ Hits         2164     2375     +211     
- Misses        196      203       +7     
- Partials       11       14       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@alexandre-combemorel alexandre-combemorel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have much time to fully deep dive into the code flow. But happy to test it with our use cases. LGTM

Comment on lines +76 to +81
useEffect(
() => () => {
requestRefs.current.forEach(request => request.removeObserver(() => null))
},
[],
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it executed ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes on unmount

ErrorType extends Error,
ParamsType,
ParamsKey extends keyof ParamsType,
> = Omit<UseDataLoaderConfig<ResultType, ErrorType>, 'initialData'> & {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove polling ?

req => req.status === StatusEnum.IDLE && !enabled,
)

const reload = useCallback(async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happen when a page doesn't exists anymore ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data will be null/undefined/empty array and be filtered out when user get the data from the hook. May be if it doesnt fit some edge cases I can cont how many requests we have and try to get each one sequentially then by using getNextPage the hook can try to fill the same number of pages but if it cant it will not make useless calls ? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants