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: Infinitescroll Vue3 composition api #5108

Merged
merged 9 commits into from
Mar 3, 2023

Conversation

Jarsen136
Copy link
Contributor

@Jarsen136 Jarsen136 commented Feb 23, 2023

Thank you for your contribution to the KodaDot NFT gallery.

👇 _ Let's make a quick check before the contribution.

PR Type

  • Bugfix
  • Feature
  • Refactoring

Context

Before submitting pull request, please make sure:

  • My contribution builds clean without any errors or warnings
  • I've merged recent default branch -- main and I've no conflicts
  • I've tried to respect high code quality standards
  • I've didn't break any original functionality
  • I've posted a screenshot of demonstrated change in this PR

Optional

  • I've tested it at </bsx/collection>
  • I've tested PR on mobile
  • I've written unit tests 🧪
  • I've found edge cases

Had issue bounty label?

  • Fill up your KSM address: Payout

Community participation

Screenshot 📸

  • My fix has changed something on UI; a screenshot is best to understand changes for others.

@Jarsen136 Jarsen136 requested a review from a team as a code owner February 23, 2023 15:42
@Jarsen136 Jarsen136 requested review from roiLeo and vikiival and removed request for a team February 23, 2023 15:42
@kodabot
Copy link
Collaborator

kodabot commented Feb 23, 2023

SUCCESS @Jarsen136 PR for issue #4952 which is assigned to you. Please wait for review and don't hesitate to grab another issue in the meantime!

@netlify
Copy link

netlify bot commented Feb 23, 2023

Deploy Preview for koda-nuxt ready!

Name Link
🔨 Latest commit 6cffd72
🔍 Latest deploy log https://app.netlify.com/sites/koda-nuxt/deploys/640183fd441f4500089d13d5
😎 Deploy Preview https://deploy-preview-5108--koda-nuxt.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.


type LoadDirection = 'up' | 'down'

export default function ({
Copy link

Choose a reason for hiding this comment

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

Function default has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.

Copy link
Contributor

@roiLeo roiLeo left a comment

Choose a reason for hiding this comment

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

Here are my concern:

  • useDebounceFn 😐
  • 200+ LOC
  • DOM elements access (no ssr)
  • event listener

have you tried to use vInfiniteScroll from @vueuse/components?

@Jarsen136
Copy link
Contributor Author

Jarsen136 commented Feb 23, 2023

Here are my concern:

  • useDebounceFn 😐

It's necessary to use debounce if some events would be triggered frequently. In this scroll case, user would scroll to the bottom frequently to fetch next page.

  • DOM elements access (no ssr)

I'm really curious about how could we improve the ssr in this case. I could not think of anything related to it TBH. Could you pls expand more?

  • event listener

We have to listen to the scroll event to know which page we are visiting.

  • 200+ LOC

have you tried to use vInfiniteScroll from @vueuse/components?

I have read the docs about useInfiniteScroll. The function provided could not fit our requirements. It could only provide single-direction scrolling. In our codebase, the infinite scroll mixins provide much more functionality, like a double-direction scroll, prefetch data, pagination etc. That's why it has so much LOC :)

@roiLeo
Copy link
Contributor

roiLeo commented Feb 24, 2023

It's necessary to use debounce if some events would be triggered frequently. In this scroll case, user would scroll to the bottom frequently to fetch next page.

hmmm, okay

I'm really curious about how could we improve the ssr in this case. I could not think of anything related to it TBH. Could you pls expand more?

maybe use ref on tag

We have to listen to the scroll event to know which page we are visiting.

@scroll event?

I have read the docs about useInfiniteScroll. The function provided could not fit our requirements. It could only provide single-direction scrolling. In our codebase, the infinite scroll mixins provide much more functionality, like a double-direction scroll, prefetch data, pagination etc. That's why it has so much LOC :)

direction?: "top" | "bottom" | "left" | "right"

I'll take a look when I have time to make it work with vueuse. pretty sure it's doable

@vikiival
Copy link
Member

Screenshot 2023-02-24 at 10 46 20

Up direction has up button anyway so I would check if user on first hit is on other page than one.
and for the direction going down I would prefer
useInfiniteScroll.

@Jarsen136
Copy link
Contributor Author

Jarsen136 commented Feb 24, 2023

I'm really curious about how could we improve the ssr in this case. I could not think of anything related to it TBH. Could you pls expand more?

maybe use ref on tag

Sorry, I just thought ssr is server-side render. I guess use ref does not change anything to it. Let me know if I miss something.

We have to listen to the scroll event to know which page we are visiting.

@scroll event?

However, it binds the scroll event on window for now.

I have read the docs about useInfiniteScroll. The function provided could not fit our requirements. It could only provide single-direction scrolling. In our codebase, the infinite scroll mixins provide much more functionality, like a double-direction scroll, prefetch data, pagination etc. That's why it has so much LOC :)

direction?: "top" | "bottom" | "left" | "right"

I'll take a look when I have time to make it work with vueuse. pretty sure it's doable

emm. Maybe use twice time to bind two directions. I'm not sure if would work as expected. Anyway, I'm willing to see if someone could improve the code.

@Jarsen136
Copy link
Contributor Author

Jarsen136 commented Feb 24, 2023

Up direction has up button anyway so I would check if user on first hit is on other page than one.
and for the direction going down I would prefer
useInfiniteScroll.

The up button for loading the previous is only for the explore gallery page because it has a special structure. I wonder if we would like to apply the up button to other pages also. If so, I could try to do some refactoring and use [useInfiniteScroll] for the down-direction loading.

double-direction scroll example: https://beta.kodadot.xyz/rmrk/explore/collectibles?page=3

@yangwao
Copy link
Member

yangwao commented Feb 25, 2023

hey haven't read anything on this pr, just having head's up on this that we should probably drop infinity scroll to the top and replace it to the button best which adds 4 rows with extra items

@Jarsen136
Copy link
Contributor Author

hey haven't read anything on this pr, just having head's up on this that we should probably drop infinity scroll to the top and replace it to the button best which adds 4 rows with extra items

OKi, I will make it work.

@Jarsen136 Jarsen136 marked this pull request as draft February 26, 2023 02:19
@Jarsen136
Copy link
Contributor Author

I have created a useListInfiniteScroll composable function and applied it to the CollectionList component.

Here is the preview path: https://deploy-preview-5108--koda-nuxt.netlify.app/rmrk/explore/collectibles

@Jarsen136 Jarsen136 marked this pull request as ready for review March 1, 2023 16:45
@yangwao
Copy link
Member

yangwao commented Mar 1, 2023

Here is the preview path

seems working well, can try to add to items?

@Jarsen136
Copy link
Contributor Author

Here is the preview path

seems working well, can try to add to items?

Yes, I will refactor GalleryList component to composition api first, and then I would apply the infinitescroll to items.

@Jarsen136 Jarsen136 marked this pull request as draft March 2, 2023 05:35
@Jarsen136
Copy link
Contributor Author

Here is the preview path

seems working well, can try to add to items?

Yes, I will refactor GalleryList component to composition api first, and then I would apply the infinitescroll to items.

✅ added infiniteScroll to redesign items page

preview: https://deploy-preview-5108--koda-nuxt.netlify.app/bsx/explore/items?redesign=true

@Jarsen136 Jarsen136 marked this pull request as ready for review March 2, 2023 16:42
Comment on lines 10 to 15
<a
v-if="startPage > 1 && !isLoading && total > 0"
class="is-flex is-justify-content-center pb-4"
@click="reachTopHandler">
<b-icon icon="chevron-up" />
</a>
Copy link
Member

Choose a reason for hiding this comment

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

just one thing, I would make this as component because we plan to reuse that across app

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DONE

Copy link
Member

@vikiival vikiival left a comment

Choose a reason for hiding this comment

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

Let it break 👀

@codeclimate
Copy link

codeclimate bot commented Mar 3, 2023

Code Climate has analyzed commit 6cffd72 and detected 3 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 3

View more on Code Climate.

@vikiival vikiival merged commit 0a13387 into kodadot:main Mar 3, 2023
@vikiival
Copy link
Member

vikiival commented Mar 3, 2023

pay 50 usd

@yangwao
Copy link
Member

yangwao commented Mar 3, 2023

😍 Perfect, I’ve sent the payout
💵 $50 @ 34.13 USD/KSM ~ 1.465 $KSM
🧗 Caiv9TbPz68q5dC8EcHu5xKYPRnremimGzqmEejDFNpWWLG
🔗 0xd2679d658fa1c638d1493d0d547b8cea83659620bd4d210502e9563a382fc732

🪅 Let’s grab another issue and get rewarded!
🪄 github.com/kodadot/nft-gallery/issues

@yangwao yangwao added the paid pull-request has been paid label Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
paid pull-request has been paid
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Infinitescroll Vue3 composition api
5 participants