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

Implement infinite scrolling without Load More button #1229

Closed
humphd opened this issue Oct 21, 2020 · 10 comments · Fixed by #1332
Closed

Implement infinite scrolling without Load More button #1229

humphd opened this issue Oct 21, 2020 · 10 comments · Fixed by #1332
Assignees
Labels

Comments

@humphd
Copy link
Contributor

humphd commented Oct 21, 2020

We used to have an implementation of infinite scrolling that almost worked, but we replaced it with a manual "Load More..." button. In #1217 I moved us to using paged data and the useSWRInfinite() hook, and we could use that to implement infinite scrolling with an IntersectionObserver, see discussion in https://sergiodxa.com/articles/swr/pagination. I think all we'd need to do is listen for the scroll event and then call setSize(size + 1) there vs. in the onClick for the LoadMore button.

@humphd humphd added type: enhancement New feature or request area: front-end labels Oct 21, 2020
@tonyvugithub
Copy link
Contributor

tonyvugithub commented Oct 22, 2020

It is an interesting idea. Could I suggest another direction? Instead of watching for a scroll event, i wonder if we can do something like lazy loading that the first time only load 20 posts. and if we pass 20 posts, it loads more. I remember learning Flutter and they have something like that. Don't know if there is similar thing in React.

@humphd
Copy link
Contributor Author

humphd commented Oct 22, 2020

This is what an IntersectionObserver does: watches for a DOM element to interact with another element, or the top-level document.

@PedroFonsecaDEV
Copy link
Contributor

I was waiting for this.
I'm available.

@humphd
Copy link
Contributor Author

humphd commented Oct 24, 2020

As long as you aren't working on another PR at the same time (i.e., squatting on multiple Issues so other students can't get involved) go for it.

@PedroFonsecaDEV
Copy link
Contributor

I'm assigned on #1223 that is waiting for our decision about it since we may solve the issue with #1193. (We are waiting for sketches).
Meanwhile, I can work on an infinite scroll if you'd like.
Let me know.

@PedroFonsecaDEV
Copy link
Contributor

PedroFonsecaDEV commented Oct 28, 2020

I'm not available anymore. If someone wants to work on this issue, please go ahead.

@klee214
Copy link
Contributor

klee214 commented Nov 10, 2020

I am gonna try this one!

@manekenpix
Copy link
Member

@klee214 all yours!

@klee214
Copy link
Contributor

klee214 commented Nov 11, 2020

I am looking for some advice!, I am doing this right now, I could implement the infinite scrolling feature with the "more button" (Once the more button is on the viewport, the new posts are updated setSize(size + 1)). However, it seems hard to do this without the "more button" component for 2 reasons,
1. On the Timeline.jsx, useRef is always undefined even if it is on the useEffect, so it is hard to grab a node
2. On the Timeline.jsx, if the "more button" component is not used, what component or node should be the indicator for auto
I know, and pretty much sure that there must be a better way to implement this, yet I do not have any idea.... So please give me some advice.

@humphd
Copy link
Contributor Author

humphd commented Nov 11, 2020

We're using useSWR to do our loading, and it supports this. Here's an example https://sergiodxa.com/articles/swr/pagination#infinite-scroll. There are others if you search for 'infinite scroll useswr'.

klee214 added a commit to klee214/telescope that referenced this issue Nov 11, 2020
klee214 added a commit to klee214/telescope that referenced this issue Nov 11, 2020
PedroFonsecaDEV added a commit that referenced this issue Nov 13, 2020
Closes #1229: Implement infinite scrolling without Load More button
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants