Skip to content

Commit

Permalink
Merge pull request kodadot#5137 from kodadot/feat/dynamic-grid-on-col…
Browse files Browse the repository at this point in the history
…lection-list

feat: use dynamic grid on existing explorer
  • Loading branch information
yangwao committed Mar 1, 2023
2 parents a24442d + 47878c6 commit 8d3e659
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 31 deletions.
14 changes: 6 additions & 8 deletions components/collection/CollectionList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@
:distance="prefetchDistance"
direction="top"
@infinite="reachTopHandler" />
<div
<DynamicGrid
:id="scrollContainerId"
class="columns is-multiline"
:default-width="{ small: 16 * 20, large: 16 * 25 }"
:mobile-variant="false"
@scroll="onScroll">
<div
v-for="(collection, index) in results"
:key="collection.id"
:class="`column ${classLayout} ${scrollItemClassName}`"
:class="scrollItemClassName"
:data-cy="`collection-index-${index}`">
<CollectionCard :is-loading="isLoading" :collection="collection" />
</div>
</div>
</DynamicGrid>
<InfiniteLoading
v-if="canLoadNextPage && !isLoading && total > 0"
:distance="prefetchDistance"
Expand Down Expand Up @@ -61,6 +62,7 @@ const components = {
ScrollTopButton: () => import('@/components/shared/ScrollTopButton.vue'),
CollectionCard: () => import('@/components/collection/CollectionCard.vue'),
EmptyResult: () => import('@/components/common/EmptyResult.vue'),
DynamicGrid: () => import('@/components/shared/DynamicGrid.vue'),
}
@Component<CollectionList>({
Expand Down Expand Up @@ -94,10 +96,6 @@ export default class CollectionList extends mixins(
return this.currentPage
}
get classLayout() {
return this.$store.getters['preferences/getLayoutClass']
}
@Debounce(500)
private resetPage() {
this.gotoPage(1)
Expand Down
31 changes: 25 additions & 6 deletions components/shared/DynamicGrid.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
<template>
<div ref="container" :style="gridCols">
<slot />
<slot :is-mobile-variant="isMobileVariant" />
</div>
</template>

<script setup lang="ts">
import { useResizeObserver } from '@vueuse/core'
const defaultWidth = {
small: 16 * 15, // 15rem
large: 16 * 20, // 20rem
}
const props = withDefaults(
defineProps<{
defaultWidth: {
small: number
large: number
}
mobileVariant: boolean
}>(),
{
defaultWidth: () => ({
small: 16 * 15, // 15rem
large: 16 * 20, // 20rem
}),
mobileVariant: true,
}
)
const { $store } = useNuxtApp()
Expand All @@ -19,10 +31,17 @@ const containerWidth = ref(0)
const container = ref<HTMLDivElement | null>(null)
const grid = computed(() => $store.getters['preferences/getGridSize'])
const isMobileVariant = computed(
() => props.mobileVariant && containerWidth.value <= 768
)
const updateColumns = () => {
if (containerWidth.value) {
cols.value = Math.floor(containerWidth.value / defaultWidth[grid.value])
const getCols = Math.floor(
containerWidth.value / props.defaultWidth[grid.value]
)
cols.value = isMobileVariant.value ? 2 : getCols
}
}
Expand Down
23 changes: 6 additions & 17 deletions components/shared/gallery/Gallery.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,17 @@
@click="fetchPreviousPage">
<b-icon icon="chevron-up" />
</a>
<div
:id="scrollContainerId"
class="columns is-multiline is-hidden-mobile">
<div
v-for="(nft, index) in results"
:key="`${nft.id}-${index}`"
:class="`column ${classLayout} ${scrollItemClassName}`">
<NftCard :nft="nft" :data-cy="`item-index-${index}`" />
</div>
</div>
<div
:id="scrollContainerId"
class="columns is-mobile is-multiline is-hidden-tablet">
<DynamicGrid :id="scrollContainerId" v-slot="slotProps">
<div
v-for="(nft, index) in results"
:key="`${nft.id}-${index}`"
:class="`column ${classLayout} ${scrollItemClassName}`">
:class="scrollItemClassName">
<NftCard
variant="minimal"
:nft="nft"
:data-cy="`item-index-${index}`" />
:data-cy="`item-index-${index}`"
:variant="slotProps.isMobileVariant && 'minimal'" />
</div>
</div>
</DynamicGrid>
<InfiniteLoading
v-if="canLoadNextPage && !isLoading && total > 0"
:distance="prefetchDistance"
Expand Down Expand Up @@ -101,6 +89,7 @@ const components = {
SidebarFilter: () => import('@/components/explore/SidebarFilter.vue'),
BreadcrumbsFilter: () => import('./BreadcrumbsFilter.vue'),
EmptyResult: () => import('@/components/common/EmptyResult.vue'),
DynamicGrid: () => import('@/components/shared/DynamicGrid.vue'),
}
@Component<Gallery>({
Expand Down

1 comment on commit 8d3e659

@vercel
Copy link

@vercel vercel bot commented on 8d3e659 Mar 2, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

nft-gallery – ./

nft-gallery-ruddy.vercel.app
nft-gallery-preschian.vercel.app
nft-gallery-git-main-preschian.vercel.app

Please sign in to comment.