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

feat: popular collections #5654

Merged
merged 41 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
42a18c1
feat: init
floyd-li Apr 10, 2023
77946a3
feat(wip): popular collections
floyd-li Apr 12, 2023
11b36f6
feat(wip): add collection filter
floyd-li Apr 12, 2023
809c01d
feat(wip): popular collection
floyd-li Apr 12, 2023
320c656
feat: display fix
floyd-li Apr 13, 2023
3c30108
feat: handle redirect
floyd-li Apr 13, 2023
9320fe3
feat: count owners
floyd-li Apr 13, 2023
17459b6
feat: remove test data
floyd-li Apr 13, 2023
94ee766
feat: add mobile filter
floyd-li Apr 13, 2023
f7ce248
Squashed commit of the following:
floyd-li Apr 13, 2023
f0f5221
feat: add query params
floyd-li Apr 13, 2023
936f31b
Merge branch 'main' into feat/popular-collections
floyd-li Apr 13, 2023
e7d06d4
fix: rmrk2 rename
floyd-li Apr 13, 2023
e4c3a85
fix: code review suggestion
floyd-li Apr 14, 2023
cf72aac
fix: deepsource issue
floyd-li Apr 14, 2023
d1ceff0
refactor: router redirect
floyd-li Apr 14, 2023
5f060ba
refactor: review suggestion
floyd-li Apr 15, 2023
f5adad0
refactor: review suggestions
floyd-li Apr 15, 2023
20482b4
refactor: review suggestions
floyd-li Apr 15, 2023
5aec002
refactor: review suggestions
floyd-li Apr 16, 2023
a8ae00e
Merge branch 'main' into feat/popular-collections
floyd-li Apr 17, 2023
f1066c8
feat: click update
floyd-li Apr 17, 2023
b703311
feat: mobile filter
floyd-li Apr 17, 2023
4107b76
fix: ui update
floyd-li Apr 17, 2023
3e04710
feat: add margin
floyd-li Apr 17, 2023
9c36906
Merge branch 'main' into feat/popular-collections
floyd-li Apr 17, 2023
8a95731
feat: sticky button
floyd-li Apr 17, 2023
ccf4ca0
fix: use computed
floyd-li Apr 17, 2023
91dfa6b
fix: array concat error
floyd-li Apr 17, 2023
4f75b7d
refactor: rename to collections
floyd-li Apr 17, 2023
3436cd0
fix: collection concat issue
floyd-li Apr 18, 2023
5c663ea
feat: collection name sort
floyd-li Apr 18, 2023
5444839
Merge branch 'main' into feat/popular-collections
floyd-li Apr 18, 2023
e6c1614
feat: hide popular collection in detail
floyd-li Apr 18, 2023
48d2dea
refactor: fix codeclimate
floyd-li Apr 18, 2023
6861864
refactor: fix codeclimate
floyd-li Apr 18, 2023
9c7163b
fix: update var name
floyd-li Apr 19, 2023
3fcf73b
fix: code review suggestion
floyd-li Apr 19, 2023
a842b7e
refactor: get collection from query string
floyd-li Apr 19, 2023
63e9d13
refactor: use isExploreItems
floyd-li Apr 19, 2023
d4c8614
Update components/shared/filters/modules/PopularCollections.vue
floyd-li Apr 19, 2023
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
1 change: 1 addition & 0 deletions components/items/ItemsGrid/useItemsGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export function useFetchSearch({
() => route.query.min,
() => route.query.max,
() => route.query.owned,
() => route.query.collections,
],
() => {
resetSearch()
Expand Down
21 changes: 21 additions & 0 deletions components/items/ItemsGrid/utils/useSearchParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ function useSearchByCollectionId() {
}
}

function useSearchByCollections() {
const route = useRoute()

return {
collections: computed(() => {
if (route.query.collections) {
return [
{
collection: {
id_in: (route.query.collections as string).split(','),
Copy link
Contributor

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

},
},
]
}
return []
}),
}
}

// search items by user id
function useSearchByUserId() {
const route = useRoute()
Expand All @@ -85,6 +104,7 @@ export function useSearchParams() {
const { owner } = useSearchOwner()
const { collectionId } = useSearchByCollectionId()
const { userId } = useSearchByUserId()
const { collections } = useSearchByCollections()

const searchParams = computed(() => {
return [
Expand All @@ -93,6 +113,7 @@ export function useSearchParams() {
...owner.value,
...collectionId.value,
...userId.value,
...collections.value,
]
})

Expand Down
29 changes: 29 additions & 0 deletions components/shared/BreadcrumbsFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()
Expand All @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

please don't use name like x for variables

)
)

const removeCollection = (id: string) => {
const ids = collections.value.filter((x) => x.id !== id).map((x) => x.id)
Copy link
Contributor

Choose a reason for hiding this comment

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

x variable name

replaceUrl({ collections: ids.join(',') })
}

const isAnyFilterActive = computed(() =>
Boolean(Object.keys(breads.value).length)
)
Expand Down
16 changes: 14 additions & 2 deletions components/shared/filters/MobileFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@
v-if="!isCollectionActivityTab"
data-model="store"
expanded />
<PopularCollections
v-if="!isCollectionActivityTab"
data-model="store"
expanded />
</div>

<div class="buttons-container px-4 py-3 border-top">
<div
class="buttons-container px-4 py-3 border-top theme-background-color">
<NeoButton
label="Reset All"
variant="primary"
Expand All @@ -56,6 +61,7 @@ import { usePreferencesStore } from '@/stores/preferences'
import StatusFilter from '@/components/shared/filters/modules/StatusFilter.vue'
import EventTypeFilter from '@/components/shared/filters/modules/EventTypeFilter.vue'
import PriceFilter from '@/components/shared/filters/modules/PriceFilter.vue'
import PopularCollections from '@/components/shared/filters/modules/PopularCollections.vue'

const route = useRoute()
const preferencesStore = usePreferencesStore()
Expand Down Expand Up @@ -91,10 +97,12 @@ const syncFromUrlOnActivityTab = () => {
}
const syncFromUrlOnGrid = () => {
const listed = route.query?.listed?.toString() === 'true',
owned = route.query?.owned?.toString() === 'true'
owned = route.query?.owned?.toString() === 'true',
collections = (route.query?.collections as string)?.split(',')

exploreFiltersStore.setListed(listed)
exploreFiltersStore.setOwned(owned)
exploreFiltersStore.setCollections(collections)
}

const syncFromUrl = () => {
Expand Down Expand Up @@ -138,10 +146,12 @@ const resetFilters = () => {
const statusDefaults = {
listed: false,
owned: false,
collections: undefined,
}

exploreFiltersStore.setListed(statusDefaults.listed)
exploreFiltersStore.setOwned(statusDefaults.owned)
exploreFiltersStore.setCollections(statusDefaults.collections)

// price
const priceDefaults = {
Expand Down Expand Up @@ -188,6 +198,8 @@ watch(() => route.query, syncFromUrl, { immediate: true })
position: absolute;
}
.buttons-container {
position: sticky;
bottom: 0;
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 20px;
Expand Down
7 changes: 7 additions & 0 deletions components/shared/filters/SidebarFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<EventTypeFilter v-if="isCollectionActivityTab" expanded fluid-padding />
<StatusFilter v-else expanded fluid-padding />
<PriceFilter v-if="!isCollectionActivityTab" fluid-padding />
<PopularCollections
v-if="!isCollectionActivityTab"
expanded
fluid-padding />
</NeoSidebar>
</div>
</template>
Expand All @@ -13,6 +17,7 @@ import { NeoSidebar } from '@kodadot1/brick'
import StatusFilter from '@/components/shared/filters/modules/StatusFilter.vue'
import EventTypeFilter from '@/components/shared/filters/modules/EventTypeFilter.vue'
import PriceFilter from '@/components/shared/filters/modules/PriceFilter.vue'
import PopularCollections from '@/components/shared/filters/modules/PopularCollections.vue'
import { usePreferencesStore } from '@/stores/preferences'
const route = useRoute()

Expand All @@ -35,6 +40,8 @@ const isCollectionActivityTab = computed(
top: 84px;
height: calc(100vh - 84px);
margin-right: $fluid-container-padding;
overflow-y: auto;
flex-shrink: 0;
}

.o-side {
Expand Down
164 changes: 164 additions & 0 deletions components/shared/filters/modules/PopularCollections.vue
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 || ''
Copy link
Contributor

Choose a reason for hiding this comment

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

x var name

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) || []
Copy link
Contributor

Choose a reason for hiding this comment

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

x variable name

} 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>
23 changes: 23 additions & 0 deletions components/shared/filters/modules/constants.ts
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',
],
}
Loading