Skip to content

Commit

Permalink
⚡️ Lazy fetch recommendation data (#1285)
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraHuang22 authored Aug 14, 2023
1 parent 05a3dd6 commit e2da962
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 48 deletions.
97 changes: 55 additions & 42 deletions src/components/NFTPage/Recommendation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,60 @@
{{ isFollowed ? $t('unfollow') : $t('follow') }}
</ButtonV2>
</div>

<div
v-if="recommendedList.length > 0"
class="relative mt-[24px]"
>
<Swiper
ref="recommendationSwiper"
:options="swiperOptions"
@slider-move="handleSliderMove"
>
<SwiperSlide
v-for="nft in recommendedList"
:key="nft.classId"
style="width: 310px; /* NOTE: Set width in style for auto slide per view calculation */"
<div class="flex justify-center items-center min-h-[375px]">
<div v-if="isLoading" class="flex items-center justify-center my-auto">
<ProgressIndicator />
</div>
<div v-else-if="recommendedList.length > 0" class="relative mt-[24px]">
<Swiper
ref="recommendationSwiper"
:options="swiperOptions"
@slider-move="handleSliderMove"
>
<NFTPortfolioItem
class="shadow-lg mb-[12px] mx-auto"
:class-id="nft.classId"
:portfolio-wallet="iscnOwner"
:should-fetch-when-visible="true"
@click.native="handleItemClick(nft.classId)"
@collect="handleItemCollect(nft.classId)"
/>
</SwiperSlide>
</Swiper>
<SwiperSlide
v-for="nft in recommendedList"
:key="nft.classId"
style="
width: 310px; /* NOTE: Set width in style for auto slide per view calculation */
"
>
<NFTPortfolioItem
class="shadow-lg mb-[12px] mx-auto"
:class-id="nft.classId"
:portfolio-wallet="iscnOwner"
:should-fetch-when-visible="true"
@click.native="handleItemClick(nft.classId)"
@collect="handleItemCollect(nft.classId)"
/>
</SwiperSlide>
</Swiper>

<div class="absolute inset-0 pointer-events-none flex justify-between items-center z-10 px-[16px]">
<div class="absolute inset-y-0 left-0 w-[32px] bg-gradient-to-r from-like-green/25 to-like-green/0" />
<div class="absolute inset-y-0 right-0 w-[32px] bg-gradient-to-l from-like-green/25 to-like-green/0" />
<ButtonV2
class="relative pointer-events-auto shadow-lg"
preset="tertiary"
:circle="true"
@click="handleClickPrev"
>
<IconArrowLeft class="w-[20px]" />
</ButtonV2>
<ButtonV2
class="relative pointer-events-auto shadow-lg"
preset="tertiary"
:circle="true"
@click="handleClickNext"
<div
class="absolute inset-0 pointer-events-none flex justify-between items-center z-10 px-[16px]"
>
<IconArrowLeft class="w-[20px] rotate-180" />
</ButtonV2>
<div
class="absolute inset-y-0 left-0 w-[32px] bg-gradient-to-r from-like-green/25 to-like-green/0"
/>
<div
class="absolute inset-y-0 right-0 w-[32px] bg-gradient-to-l from-like-green/25 to-like-green/0"
/>
<ButtonV2
class="relative shadow-lg pointer-events-auto"
preset="tertiary"
:circle="true"
@click="handleClickPrev"
>
<IconArrowLeft class="w-[20px]" />
</ButtonV2>
<ButtonV2
class="relative shadow-lg pointer-events-auto"
preset="tertiary"
:circle="true"
@click="handleClickNext"
>
<IconArrowLeft class="w-[20px] rotate-180" />
</ButtonV2>
</div>
</div>
</div>
</section>
Expand Down Expand Up @@ -88,6 +97,10 @@ export default {
type: Array,
default: () => [],
},
isLoading: {
type: Boolean,
default: false,
},
},
computed: {
swiperOptions() {
Expand Down
16 changes: 10 additions & 6 deletions src/pages/nft/class/_classId/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,17 @@
/>
</section>
<!-- recommend -->
<div v-if="isRecommendationLoading" class="flex justify-center items-center my-[24px]">
<ProgressIndicator />
</div>
<client-only>
<lazy-component
class="pointer-events-none"
@show.once="handleFetchRecommendInfo"
/>
</client-only>
<NFTPageRecommendation
v-else
:iscn-owner="iscnOwner"
:is-followed="isFollowed"
:recommended-list="recommendedList"
:is-loading="isRecommendationLoading"
@header-avatar-click="handleRecommendationHeaderAvatarClick"
@follow-button-click="handleFollowButtonClick"
@item-click="handleRecommendedItemClick"
Expand Down Expand Up @@ -487,8 +490,6 @@ export default {
this.isLoading = false;
}
await this.fetchRecommendInfo();
const { hash } = this.$route;
if (hash) {
this.$nextTick(() => {
Expand Down Expand Up @@ -528,6 +529,9 @@ export default {
);
await this.lazyGetUserInfoByAddresses(trimmedCollectors);
},
async handleFetchRecommendInfo() {
await this.fetchRecommendInfo();
},
async handleClickMoreCollector() {
logTrackerEvent(
this,
Expand Down

0 comments on commit e2da962

Please sign in to comment.