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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter by nft attributes in collection #9798

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 53 additions & 0 deletions components/collection/CollectionGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const searchQuery = reactive<SearchQuery>({
type: route.query?.type?.toString() ?? '',
sortBy: sortBy.value ?? undefined,
listed: route.query?.listed?.toString() === 'true',
moreThanItems: route.query?.moreThanItems || 0,
})

const resetPage = useDebounceFn(() => {
Expand All @@ -89,6 +90,18 @@ const buildSearchParam = (): Record<string, unknown>[] => {
params.push({ nfts_some: { price_gt: '0' } })
}

if (!!searchQuery.moreThanItems) {
params.push({ nftCount_gt: Number(searchQuery.moreThanItems) })
}

if (!!searchQuery.priceMin) {
params.push({ volume_gte: Number(searchQuery.priceMin) })
}

if (!!searchQuery.priceMax) {
params.push({ volume_lte: Number(searchQuery.priceMax) })
}

return params
}

Expand Down Expand Up @@ -208,6 +221,46 @@ watch(
},
)

watch(
() => route.query.moreThanItems,
(val, oldVal) => {
if (!isEqual(val, oldVal)) {
resetPage()
searchQuery.moreThanItems = Number(val) || 0
}
},
)

watch(
() => route.query.listed,
(val, oldVal) => {
if (!isEqual(val, oldVal)) {
resetPage()
searchQuery.listed = val
}
},
)

watch(
() => route.query.min,
(val, oldVal) => {
if (!isEqual(val, oldVal)) {
resetPage()
searchQuery.priceMin = val
}
},
)

watch(
() => route.query.max,
(val, oldVal) => {
if (!isEqual(val, oldVal)) {
resetPage()
searchQuery.priceMax = val
}
},
)

watch(
() => searchQuery,
() => {
Expand Down
1 change: 1 addition & 0 deletions components/explore/FilterMenuButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const disabled = computed(() => {
'prefix-explore-items',
'prefix-collection-id',
'prefix-collection-id-activity',
'prefix-explore-collectibles',
]

return !allowedList.includes(route.name || '')
Expand Down
1 change: 1 addition & 0 deletions components/search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type SearchQuery = {
priceMin?: number
priceMax?: number
sortByMultiple?: string[]
moreThanItems?: number
}

export type SearchSuggestion = Record<
Expand Down
10 changes: 9 additions & 1 deletion components/shared/filters/MobileFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,21 @@ const applyFilters = () => {
const priceRangeFilter = exploreFiltersStore.getPriceRange
const eventTypeFilter = activityFiltersStore.getEventTypeFilters

console.log(
'isactivitytab',
isCollectionActivityTab.value,
'restfilters',
restStatusFilters,
)
// apply to URL
if (isCollectionActivityTab.value) {
console.log('here1')
replaceUrl({ ...eventTypeFilter, ...priceRangeFilter })
} else {
console.log('here2', restStatusFilters.moreThanItems)
replaceUrl({ art_view: artView, ...restStatusFilters, ...priceRangeFilter })
}
emit('resetPage')
// emit('resetPage')
closeFilterModal()
}

Expand Down
7 changes: 5 additions & 2 deletions components/shared/filters/SidebarFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<EventTypeFilter expanded fluid-padding />
<IdentityVerficationFilter expanded fluid-padding />
</template>
<StatusFilter v-else expanded fluid-padding />
<StatusFilter v-if="!isCollectionActivityTab" expanded fluid-padding />
<PriceFilter
v-if="!isCollectionActivityTab"
fluid-padding
data-testid="sidebar-price-filter" />
<PopularCollections v-if="isExploreItems" expanded fluid-padding />
<AdvancedFilter
v-if="!isCollectionActivityTab"
v-if="!isCollectionActivityTab && !isCollectibles"
fluid-padding
data-testid="sidebar-advanced-filter" />
</NeoSidebar>
Expand All @@ -34,6 +34,9 @@ const open = computed(() => preferencesStore.getsidebarFilterCollapse)
const isCollectionActivityTab = computed(
() => route.name === 'prefix-collection-id-activity',
)
const isCollectibles = computed(
() => route.name === 'prefix-explore-collectibles',
)
const isExploreItems = computed(() => route.name === 'prefix-explore-items')
</script>

Expand Down
6 changes: 5 additions & 1 deletion components/shared/filters/modules/PriceFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<template #trigger="{ open }">
<div class="flex" role="button" :aria-expanded="open">
<p class="card-header-title font-normal">
{{ $t('tabs.tabActivity.price') }}
{{ isCollectibles ? 'Volume' : $t('tabs.tabActivity.price') }}
</p>
<a class="card-header-icon">
<NeoIcon :icon="open ? 'minus' : 'plus'" />
Expand Down Expand Up @@ -154,6 +154,10 @@ const inputFocused = ref(false)
const toggleInputFocused = (): void => {
inputFocused.value = !inputFocused.value
}

const isCollectibles = computed(
() => route.name === 'prefix-explore-collectibles',
)
</script>

<style lang="scss">
Expand Down
33 changes: 31 additions & 2 deletions components/shared/filters/modules/StatusFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,43 @@
{{ $t(ListedOrBuynow) }}</NeoCheckbox
>
</NeoField>
<NeoField>
<NeoField v-if="!isCollectibles">
<NeoCheckbox v-model="owned" :disabled="!accountId">
{{ $t('sort.own') }}
</NeoCheckbox>
</NeoField>
<NeoField v-if="isCollectibles">
<div>More than {{ moreThanItems }} nfts</div>
<NeoInput
v-model="moreThanItems"
type="number"
min="0"
step="any"
placeholder="0" />
</NeoField>
</div>
</NeoCollapse>
</template>

<script lang="ts" setup>
import { useExploreFiltersStore } from '@/stores/exploreFilters'
import { NeoCheckbox, NeoCollapse, NeoField, NeoIcon } from '@kodadot1/brick'
import {
NeoCheckbox,
NeoCollapse,
NeoField,
NeoIcon,
NeoInput,
} from '@kodadot1/brick'

const exploreFiltersStore = useExploreFiltersStore()
const route = useRoute()
const { accountId } = useAuth()
const { replaceUrl: replaceURL } = useReplaceUrl()
const { urlPrefix } = usePrefix()
const { isRemark } = useIsChain(urlPrefix)
const isCollectibles = computed(
() => route.name === 'prefix-explore-collectibles',
)

type DataModel = 'query' | 'store'

Expand Down Expand Up @@ -83,6 +101,17 @@ const owned =
set: (value) => exploreFiltersStore.setOwned(value),
})

const moreThanItems =
props.dataModel === 'query'
? computed({
get: () => route.query?.moreThanItems,
set: (value) => applyToUrl({ moreThanItems: value }),
})
: computed({
get: () => exploreFiltersStore.moreThanItems,
set: (value) => exploreFiltersStore.setMoreThanItems(value),
})

const applyToUrl = (queryCondition: { [key: string]: any }) => {
replaceURL(queryCondition)
emit('resetPage')
Expand Down
7 changes: 5 additions & 2 deletions pages/[prefix]/explore/collectibles.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<template>
<div class="container is-fluid">
<CollectionGridWithBreadcrumbs />
<div class="flex">
<SidebarFilter />
<div class="container is-fluid">
<CollectionGridWithBreadcrumbs />
</div>
</div>
</template>

Expand Down
6 changes: 6 additions & 0 deletions stores/exploreFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ interface State {
listed: boolean
owned: boolean
artView: boolean
moreThanItems: number
// price
min: number | undefined
max: number | undefined
Expand All @@ -19,13 +20,15 @@ export const useExploreFiltersStore = defineStore('exploreFilters', {
max: undefined,
artView: false,
collections: undefined,
moreThanItems: 0,
}),
getters: {
getStatusFilters: (state) => ({
listed: state.listed,
owned: state.owned,
artView: state.artView,
collections: state.collections?.toString(),
moreThanItems: state.moreThanItems,
}),
getPriceRange: (state) => ({ min: state.min, max: state.max }),
},
Expand All @@ -52,5 +55,8 @@ export const useExploreFiltersStore = defineStore('exploreFilters', {
setCollections(payload) {
this.collections = payload
},
setMoreThanItems(payload) {
this.moreThanItems = payload
},
},
})