-
-
Notifications
You must be signed in to change notification settings - Fork 366
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
feat: popular collections #5654
Changes from 32 commits
42a18c1
77946a3
11b36f6
809c01d
320c656
3c30108
9320fe3
17459b6
94ee766
f7ce248
f0f5221
936f31b
e7d06d4
e4c3a85
cf72aac
d1ceff0
5f060ba
f5adad0
20482b4
5aec002
a8ae00e
f1066c8
b703311
4107b76
3e04710
9c36906
8a95731
ccf4ca0
91dfa6b
4f75b7d
3436cd0
5c663ea
5444839
e6c1614
48d2dea
6861864
9c7163b
3fcf73b
a842b7e
63e9d13
d4c8614
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,16 @@ | |
{{ `${$t('Max')}:` }} | ||
<CommonTokenMoney :value="value" /> | ||
</NeoTag> | ||
<template v-else-if="key === 'collections'"> | ||
<NeoTag | ||
v-for="item in collections" | ||
:key="`${key}-${item.id}`" | ||
class="control" | ||
@close="removeCollection(item.id)"> | ||
{{ item.meta.name }} | ||
</NeoTag> | ||
</template> | ||
|
||
<NeoTag | ||
v-else | ||
:key="key" | ||
|
@@ -44,6 +54,10 @@ | |
<script lang="ts" setup> | ||
import NeoTag from '@/components/shared/gallery/NeoTag.vue' | ||
import CommonTokenMoney from '@/components/shared/CommonTokenMoney.vue' | ||
import { | ||
Collection, | ||
collectionArray, | ||
} from '@/components/shared/filters/modules/usePopularCollections' | ||
import useActiveRouterFilters from '@/composables/useActiveRouterFilters' | ||
|
||
const route = useRoute() | ||
|
@@ -58,6 +72,21 @@ const isItemsExplore = computed(() => route.path.includes('/explore/items')) | |
|
||
const breads = useActiveRouterFilters() | ||
|
||
const collectionIdList = computed( | ||
() => breads.value.collections?.split(',') || [] | ||
) | ||
|
||
const collections = computed<Collection[]>(() => | ||
collectionArray.value?.filter((x) => | ||
collectionIdList.value?.find((id) => x.id === id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please don't use name like |
||
) | ||
) | ||
|
||
const removeCollection = (id: string) => { | ||
const ids = collections.value.filter((x) => x.id !== id).map((x) => x.id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
replaceUrl({ collections: ids.join(',') }) | ||
} | ||
|
||
const isAnyFilterActive = computed(() => | ||
Boolean(Object.keys(breads.value).length) | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
<template> | ||
<b-collapse | ||
:open="expanded" | ||
animation="slide" | ||
class="border-bottom" | ||
:class="{ 'fluid-padding-left': fluidPadding }"> | ||
<template #trigger="{ open }"> | ||
<div class="is-flex" role="button" :aria-expanded="open"> | ||
<p class="card-header-title has-text-weight-normal"> | ||
{{ $t('general.popularCollectionsHeading') }} | ||
</p> | ||
<a class="card-header-icon"> | ||
<b-icon :icon="open ? 'minus' : 'plus'" /> | ||
</a> | ||
</div> | ||
</template> | ||
<div class="p-4"> | ||
<o-field | ||
v-for="collection in collections" | ||
:key="collection.id" | ||
class="mb-2"> | ||
<NeoCheckbox | ||
:value="checkedCollections.includes(collection.id)" | ||
class="mr-0 w-100" | ||
label-class="is-flex-grow-1" | ||
@input="toggleCollection(collection)"> | ||
<div | ||
class="is-flex is-align-items-center filter-container pl-2 is-flex-grow-1 min-width-0"> | ||
<img | ||
:src="sanitizeIpfsUrl(collection.meta.image)" | ||
class="image is-32x32 border mr-2" /> | ||
<div | ||
class="is-flex is-flex-direction-column is-flex-grow-1 min-width-0"> | ||
<NeoTooltip | ||
:label="collection.meta.name || collection.id" | ||
:append-to-body="false" | ||
:delay="1000"> | ||
<div class="is-ellipsis"> | ||
{{ collection.meta.name || collection.id }} | ||
</div> | ||
</NeoTooltip> | ||
<div | ||
class="is-flex is-justify-content-space-between is-size-7 has-text-grey"> | ||
<div>{{ $t('search.owners') }}: {{ collection.owners }}</div> | ||
<div>{{ getChainName(collection.chain) }}</div> | ||
</div> | ||
</div> | ||
</div> | ||
</NeoCheckbox> | ||
</o-field> | ||
</div> | ||
</b-collapse> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { NeoCheckbox, NeoTooltip } from '@kodadot1/brick' | ||
import { useExploreFiltersStore } from '@/stores/exploreFilters' | ||
import { Collection, usePopularCollections } from './usePopularCollections' | ||
import { OField } from '@oruga-ui/oruga' | ||
import { sanitizeIpfsUrl } from '@/utils/ipfs' | ||
|
||
const exploreFiltersStore = useExploreFiltersStore() | ||
const route = useRoute() | ||
const router = useRouter() | ||
const { replaceUrl: replaceURL } = useReplaceUrl() | ||
const { collections } = usePopularCollections() | ||
const { availableChains } = useChain() | ||
const { urlPrefix } = usePrefix() | ||
const { $store } = useNuxtApp() | ||
|
||
const getChainName = (chain: string): string => { | ||
return availableChains.value.find((x) => x.value === chain)?.text || '' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
floyd-li marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
type DataModel = 'query' | 'store' | ||
|
||
const props = withDefaults( | ||
defineProps<{ | ||
expanded?: boolean | ||
dataModel?: DataModel | ||
fluidPadding?: boolean | ||
}>(), | ||
{ | ||
expanded: false, | ||
dataModel: 'query', | ||
fluidPadding: false, | ||
} | ||
) | ||
|
||
const emit = defineEmits(['resetPage']) | ||
|
||
const checkedCollections = ref<string[]>([]) | ||
|
||
const toggleCollection = (collection: Collection) => { | ||
const index = checkedCollections.value.indexOf(collection.id) | ||
if (index > -1) { | ||
checkedCollections.value.splice(index, 1) | ||
} else { | ||
checkedCollections.value.push(collection.id) | ||
} | ||
if (urlPrefix.value !== collection.chain) { | ||
$store.dispatch('setUrlPrefix', collection.chain) | ||
const { page, ...restQuery } = route.query | ||
router.push({ | ||
params: { | ||
prefix: collection.chain, | ||
}, | ||
query: { | ||
...restQuery, | ||
collections: checkedCollections.value.join(','), | ||
}, | ||
}) | ||
} else { | ||
toggleSearchParam() | ||
} | ||
} | ||
|
||
const getSearchParam = () => { | ||
if (props.dataModel === 'query') { | ||
checkedCollections.value = | ||
(route.query?.collections as string)?.split(',').filter((x) => !!x) || [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} else { | ||
checkedCollections.value = exploreFiltersStore.collections || [] | ||
} | ||
} | ||
|
||
const toggleSearchParam = () => { | ||
if (props.dataModel === 'query') { | ||
applyToUrl() | ||
} else { | ||
exploreFiltersStore.setCollections(checkedCollections.value) | ||
} | ||
} | ||
|
||
const applyToUrl = () => { | ||
replaceURL({ collections: checkedCollections.value.join(',') }) | ||
emit('resetPage') | ||
} | ||
|
||
watch( | ||
() => { | ||
if (props.dataModel === 'query') { | ||
return (route.query?.collections as string)?.split(',') | ||
} else { | ||
return exploreFiltersStore.collections | ||
} | ||
}, | ||
getSearchParam, | ||
{ | ||
immediate: true, | ||
} | ||
) | ||
</script> | ||
<style lang="scss" scoped> | ||
.min-width-0 { | ||
min-width: 0; | ||
} | ||
:deep .neo-checkbox > span { | ||
max-width: calc(100% - 1rem); | ||
.o-tip__trigger { | ||
max-width: 100%; | ||
} | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export const POPULAR_COLLECTIONS = { | ||
ksm: [ | ||
'be15890524c6e9b359-WIZARD', | ||
'66241b171becfd500e-EGG', | ||
'342f12106eab6d904c-YOUDLE', | ||
'3e6f301b0a0b1a0e4e-MRWH', | ||
'8ac9852f42a86a395d-8GDSY', | ||
'72559667d353e6dc0d-HUBIM', | ||
'7a147cba01afccbf17-GA', | ||
'9692fa834afcce2d3e-RNDM', | ||
'a2a383db29d7601e4b-TONICS', | ||
'800f8a914281765a7d-KITTY', | ||
'c210bd52d397099b2c-JPS', | ||
'7cf9daa38281a57331-BSS', | ||
'f69287204232615e37-NEP4I', | ||
'22708b368d163c8007-KV', | ||
'dac5c7f54029d0e73c-HXAI8', | ||
'2644199cf3652aaa78-KK01', | ||
'b45943b4edbf6f5c0f-SKYLAB_ARTEMIS_R4VENS', | ||
'dac5c7f54029d0e73c-XCHIMPZ', | ||
'be15890524c6e9b359-TRUSTED', | ||
], | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you have this kind of string manipulation bit spread all over each time you need to read/write collection from the url
please create a util function and avoid repetition