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

Refactor feeds to use react-query #1862

Merged
merged 16 commits into from
Nov 10, 2023
Merged

Refactor feeds to use react-query #1862

merged 16 commits into from
Nov 10, 2023

Conversation

pfrazee
Copy link
Collaborator

@pfrazee pfrazee commented Nov 10, 2023

Refactors the feed to use react-query.

The feed query-key is the FeedDescriptor type, which is a string that uses template-literal-types to ensure correct usage. I decided to go with a string because it gets passed around a fair amount and it'll be easier to avoid needless re-renders with that. Also note: it uses a pipe (|) separator for the params to avoid colliding with potential values (initially I used : but that collides with URIs).

Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

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

lgtm overall

src/state/preferences/feed-tuners.tsx Show resolved Hide resolved
src/state/queries/post-feed.ts Show resolved Hide resolved
src/state/queries/post-feed.ts Show resolved Hide resolved
Copy link
Member

@estrattonbailey estrattonbailey left a comment

Choose a reason for hiding this comment

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

Looking good to me. One smaller note: stale data flashes and is replaced when you toggle back and forth between feeds. We might want to play with staleTime, maybe even only manually marking as stale to trigger a refresh.

src/lib/api/feed/merge.ts Outdated Show resolved Hide resolved
src/state/queries/post-feed.ts Show resolved Hide resolved
src/state/preferences/feed-tuners.tsx Show resolved Hide resolved
src/state/queries/post-feed.ts Show resolved Hide resolved
src/view/com/posts/FeedItem.tsx Show resolved Hide resolved
src/view/com/posts/FeedItem.tsx Outdated Show resolved Hide resolved
[opts?.disableTuner],
)

const pollLatest = useCallback(async () => {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we shouldn't just do polling, hasNew state, etc in this hook and expose as state 🤔 Would remove some logic from Feed and make that simpler.

In general, I think we should aim for something as simple as:

  • fetch data and handle refresh and state up top (like in this hook)
    • all logic lives here
  • construct item skeleton
  • pass to FlatList to render

Maybe can't get to that point, or not right now anyway, but could be a good guiding light moving forward.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's probably possible, though we do need the onHasNew emitter so that we can emit that state back out to the wrapper components

Copy link
Member

Choose a reason for hiding this comment

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

If outer components need state, could we move this hook up a level and flatten children out more? Then we don't need to emit anything, we just check for hasNew and render stuff.

But yeah not saying we should do all this here 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd like to keep the hook inside the <Feed> component but maybe the answer is to move that state and UI behaviors into the Feed component

@pfrazee pfrazee changed the title Refactor feeds to use react-query [WIP] Refactor feeds to use react-query Nov 10, 2023
@pfrazee pfrazee marked this pull request as ready for review November 10, 2023 23:16
@pfrazee pfrazee merged commit c8c308e into main Nov 10, 2023
3 of 4 checks passed
@pfrazee pfrazee deleted the rq-feeds branch November 10, 2023 23:34
estrattonbailey added a commit that referenced this pull request Nov 11, 2023
* origin:
  Refactor feeds to use react-query (#1862)
  Use min height for pager lists and increase it (#1869)
  Fix initial pager gap after fast scroll (#1868)
  Scroll sync in the pager without jumps (#1863)
  Push useAnimatedScrollHandler down everywhere to work around bugs (#1866)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants