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

🩹 Fix portfolio grid layout issues #810

Merged
merged 4 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions src/components/NFTCover.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<template>
<div
class="bg-gray-9b"
class="relative bg-gray-9b"
:style="rootStyle"
>
<img
v-if="src && !isError"
v-if="isShowImage"
v-bind="imgProps"
:src="resizedSrc"
@load="handleImageLoad"
@error="handleImageError"
>
<img
v-else
v-bind="imgProps"
v-if="!isShowImage || !isLoaded"
v-bind="imgPropsForPlaceholder"
src="~/assets/images/nft/primitive-nft.png"
>
</div>
Expand Down Expand Up @@ -40,6 +40,7 @@ export default {
data() {
return {
isError: false,
isLoaded: false,
};
},
computed: {
Expand All @@ -49,27 +50,56 @@ export default {
};
},
imgProps() {
const { imgPropsForPlaceholder: props, isLoaded } = this;
return {
...props,
class: [
...props.class,
{
'absolute inset-x-0 top-0 opacity-0 pointer-events-none': !isLoaded,
},
],
};
},
imgPropsForPlaceholder() {
return {
class: 'object-contain w-full',
class: [
'object-contain w-full',
{
'animate-pulse': !this.isLoaded,
},
],
loading: 'lazy',
...this.$attrs,
};
},
resizedSrc() {
return getLikeCoResizedImageUrl(this.src, this.size);
},
isShowImage() {
return this.src && !this.isError;
},
},
watch: {
src() {
this.isError = false;
this.isLoaded = false;
},
},
methods: {
handleImageLoad(e) {
this.$emit('load', e);
this.isLoaded = true;
this.emitLoadEvent(e);
},
handleImageError() {
handleImageError(e) {
this.isError = true;
this.isLoaded = true;
this.emitLoadEvent(e);
},
emitLoadEvent(e) {
this.$nextTick(() => {
this.$emit('load', e);
});
},
},
};
Expand Down
4 changes: 4 additions & 0 deletions src/components/NFTPortfolio/Base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
:src="imageSrc"
:size="350"
:bg-color="imageBgColor"
@load="handleCoverLoaded"
/>
<div
:class="[
Expand Down Expand Up @@ -150,6 +151,9 @@ export default {
handleClickCollect(event) {
this.$emit('collect', event);
},
handleCoverLoaded(event) {
this.$emit('load-cover', event);
},
},
};
</script>
4 changes: 4 additions & 0 deletions src/components/NFTPortfolio/Item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
:is-collecting="uiIsOpenCollectModal && isCollecting"
:own-count="ownCount"
@collect="handleClickCollect"
@load-cover="handleCoverLoaded"
/>
</NuxtLink>
</template>
Expand Down Expand Up @@ -95,6 +96,9 @@ export default {
1
);
},
handleCoverLoaded(e) {
this.$emit('load-cover', e);
},
},
};
</script>
2 changes: 1 addition & 1 deletion src/components/NFTPortfolio/MainView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
:class-id="nft.classId"
:portfolio-wallet="portfolioWallet"
:nft-id="nft.id"
@load="updatePortfolioGrid"
@load-cover="updatePortfolioGrid"
/>
</li>
</ul>
Expand Down