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: Price sort by logic #11075

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
20 changes: 0 additions & 20 deletions components/explore/ExploreSort.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,6 @@ const { $i18n } = useNuxtApp()
const { hasItems: isItems } = useHasRoute()
const { options } = useRouteSortByOptions()

function removeDuplicateSortKeys(options: string[]) {
const uniqueOptions = {}

if (!Array.isArray(options)) {
return []
}

options.forEach((option) => {
const opt = option.split('_')
const identifier = opt[0]
const sort = opt[1]

uniqueOptions[identifier] = sort
})

return Object.keys(uniqueOptions).map((identifier) => {
return `${identifier}_${uniqueOptions[identifier]}`
})
}

const sortOptions = ref<string[]>([])
const selectedSort = computed({
get: () => sortOptions.value,
Expand Down
18 changes: 0 additions & 18 deletions components/items/ItemsGrid/useItemsGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,24 +140,6 @@ export function useFetchSearch({
]),
}

const isPriceSortActive = (sort?: string | null | (string | null)[]) => {
if (!sort) {
return false
}
const sortArray = Array.isArray(sort) ? sort : [sort]
return sortArray.some(sortBy => (sortBy ?? '').includes('price'))
}
watch(
() => route.query.sort,
(newSort, oldSort) => {
const priceSortHasBeenActivated
= isPriceSortActive(newSort) && !isPriceSortActive(oldSort)
if (priceSortHasBeenActivated && route.query.listed !== 'true') {
route.query.listed = 'true'
}
},
)

const searchForToken = getSearchCriteria(
search?.length ? search : searchParams.value,
)
Expand Down
20 changes: 0 additions & 20 deletions components/profile/OrderByDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,6 @@ const options = computed(() => {
: NFT_SQUID_SORT_CONDITION_LIST
})

function removeDuplicateSortKeys(options: string[]) {
const uniqueOptions = {}

if (!Array.isArray(options)) {
return []
}

options.forEach((option) => {
const opt = option.split('_')
const identifier = opt[0]
const sort = opt[1]

uniqueOptions[identifier] = sort
})

return Object.keys(uniqueOptions).map((identifier) => {
return `${identifier}_${uniqueOptions[identifier]}`
})
}

const sortOptions = ref<string[]>([])
const selectedSort = computed({
get: () => sortOptions.value,
Expand Down
6 changes: 0 additions & 6 deletions components/search/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,6 @@ const updateSortBy = useDebounceFn((value: string[] | string) => {
const final = (Array.isArray(value) ? value : [value]).filter(condition =>
sortByOptions.value.includes(condition),
)
const listed = final.some(
condition => condition.toLowerCase().indexOf('price') > -1,
)
if (listed && !vListed.value) {
vListed.value = true
}

replaceUrl({ sort: final })

Expand Down
6 changes: 2 additions & 4 deletions locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,6 @@
"BLOCK_NUMBER_ASC": "Älteste",
"BLOCK_NUMBER_DESC": "Kürzlich erstellt",
"EMOTES_COUNT_DESC": "Meiste Reaktionen",
"PRICE_ASC": "Presi: Niedrig zu Hoch",
"PRICE_DESC": "Preis: Hoch zu Niedrig",
"SN_ASC": "Alphabetisch",
"UPDATED_AT_ASC": "Unpopulär",
Expand All @@ -633,23 +632,22 @@
"BLOCK_NUMBER_ASC": "Älteste",
"BLOCK_NUMBER_DESC": "Kürzlich erstellt",
"EMOTES_COUNT_DESC": "Meiste Reaktionen",
"PRICE_ASC": "Preis: Niedrig zu Hoch",
"PRICE_DESC": "Preis: Hoch zu Niedrig",
"SN_ASC": "Alphabetisch",
"UPDATED_AT_ASC": "Unpopulär",
"UPDATED_AT_DESC": "Kürzlich interagiert",
"blockNumber_ASC": "Ältere zuerst",
"blockNumber_DESC": "Neue zuerst",
"listed": "Jetzt kaufen",
"price_ASC": "Preis: Niedrig zu Hoch",
"price_ASC_NULLS_LAST": "Preis: Niedrig zu Hoch",
"price_DESC": "Preis: Hoch zu Niedrig",
"sn_ASC": "Alphabetisch",
"updatedAt_ASC": "Unpopulär",
"updatedAt_DESC": "Kürzlich interagiert"
},
"listed": "Jetzt kaufen",
"own": "Eigene",
"price_ASC": "Preis: Niedrig zu Hoch",
"price_ASC_NULLS_LAST": "Preis: Niedrig zu Hoch",
"price_DESC": "Preis: Hoch zu Niedrig",
"sn_ASC": "Alphabetisch",
"updatedAt_ASC": "Unpopulär",
Expand Down
4 changes: 2 additions & 2 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,7 @@
"blockNumber_ASC": "Oldest",
"blockNumber_DESC": "Newest",
"highestSale_DESC": "Highest Sale",
"price_ASC": "Price: Low to High",
"price_ASC_NULLS_LAST": "Price: Low to High",
"price_DESC": "Price: High to Low",
"sn_ASC": "Serial (Low→High)",
"sn_DESC": "Serial (High→Low)",
Expand All @@ -1766,7 +1766,7 @@
"listed": "Listed for sale",
"listed_RMRK": "Listed",
"own": "Own",
"price_ASC": "Price: Low to High",
"price_ASC_NULLS_LAST": "Price: Low to High",
"price_DESC": "Price: High to Low",
"sn_ASC": "Serial (Low→High)",
"sn_DESC": "Serial (High→Low)",
Expand Down
6 changes: 2 additions & 4 deletions locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,6 @@
"BLOCK_NUMBER_ASC": "El más antiguo",
"BLOCK_NUMBER_DESC": "Recién creado",
"EMOTES_COUNT_DESC": "El mas reaccionado",
"PRICE_ASC": "Precio: de menor a mayor",
"PRICE_DESC": "Precio: de mayor a menor",
"SN_ASC": "Alfabéticamente",
"UPDATED_AT_ASC": "Impopular",
Expand All @@ -598,23 +597,22 @@
"BLOCK_NUMBER_ASC": "El más antiguo",
"BLOCK_NUMBER_DESC": "Recién creado",
"EMOTES_COUNT_DESC": "El mas reaccionado",
"PRICE_ASC": "Precio: de menor a mayor",
"PRICE_DESC": "Precio: de mayor a menor",
"SN_ASC": "Alfabéticamente",
"UPDATED_AT_ASC": "Impopular",
"UPDATED_AT_DESC": "Interactuado recientemente",
"blockNumber_ASC": "Antiguo primero",
"blockNumber_DESC": "Nuevo primero",
"listed": "Compre ahora",
"price_ASC": "Precio: de menor a mayor",
"price_ASC_NULLS_LAST": "Precio: de menor a mayor",
"price_DESC": "Precio: de mayor a menor",
"sn_ASC": "Alfabéticamente",
"updatedAt_ASC": "Impopular",
"updatedAt_DESC": "Interactuado recientemente"
},
"listed": "Compre ahora",
"own": "En posesión",
"price_ASC": "Precio: de menor a mayor",
"price_ASC_NULLS_LAST": "Precio: de menor a mayor",
"price_DESC": "Precio: de mayor a menor",
"sn_ASC": "Alfabéticamente",
"updatedAt_ASC": "Impopular",
Expand Down
4 changes: 2 additions & 2 deletions locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
"blockNumber_ASC": "Ancien",
"blockNumber_DESC": "Nouveau",
"listed": "En vente",
"price_ASC": "Prix : du plus bas au plus haut",
"price_ASC_NULLS_LAST": "Prix : du plus bas au plus haut",
"price_DESC": "Prix : du plus haut au plus bas",
"sn_ASC": "Alphabétiquement",
"sortBy": "Trier par",
Expand All @@ -303,7 +303,7 @@
},
"listed": "En vente",
"own": "Possédé",
"price_ASC": "Prix : du plus bas au plus haut",
"price_ASC_NULLS_LAST": "Prix : du plus bas au plus haut",
"price_DESC": "Prix : du plus haut au plus bas",
"sn_ASC": "Alphabétiquement",
"updatedAt_ASC": "Peu populaire",
Expand Down
4 changes: 2 additions & 2 deletions locales/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@
"blockNumber_DESC": "नवीनतम",
"highestSale_DESC": "सबसे अधिक बिक्री",
"listed": "अब खरीदें",
"price_ASC": "मूल्य: कम से उच्च",
"price_ASC_NULLS_LAST": "मूल्य: कम से उच्च",
"price_DESC": "मूल्य: उच्च से कम",
"sn_ASC": "वर्णमाला के अनुसार",
"sortBy": "क्रमबद्ध करें द्वारा",
Expand All @@ -1341,7 +1341,7 @@
"instance_ASC": "क्रम",
"listed": "अभी खरीदें",
"own": "अपना",
"price_ASC": "मूल्य: कम से उच्च",
"price_ASC_NULLS_LAST": "मूल्य: कम से उच्च",
"price_DESC": "मूल्य: उच्च से कम",
"sn_ASC": "वर्णक्रमानुसार",
"updatedAt_ASC": "अप्रसार्पित",
Expand Down
4 changes: 2 additions & 2 deletions locales/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,11 @@
"sort": {
"BLOCK_NUMBER_ASC": "Urutan Akhir",
"BLOCK_NUMBER_DESC": "Urutan Pertama",
"PRICE_ASC": "Harga Rendah Ke Tinggi",
"PRICE_DESC": "Harga Tinggi Ke Rendah",
"UPDATED_AT_ASC": "Aktifitas Terakhir",
"UPDATED_AT_DESC": "Aktifitas Terbaru",
"listed": "Beli Sekarang"
"listed": "Beli Sekarang",
"price_ASC_NULLS_LAST": "Harga Rendah Ke Tinggi"
},
"spotlight": {
"averagePrice": "Ø Harga",
Expand Down
6 changes: 2 additions & 4 deletions locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,6 @@
"BLOCK_NUMBER_ASC": "O mais antigo",
"BLOCK_NUMBER_DESC": "Criado recentemente",
"EMOTES_COUNT_DESC": "O Mais reagido",
"PRICE_ASC": "Preço: Menor para Maior",
"PRICE_DESC": "Preço: Maior para Menor",
"SN_ASC": "Alfabeticamente",
"UPDATED_AT_ASC": "Impopular",
Expand All @@ -571,23 +570,22 @@
"BLOCK_NUMBER_ASC": "O mais antigo",
"BLOCK_NUMBER_DESC": "Criado recentemente",
"EMOTES_COUNT_DESC": "O Mais reagido",
"PRICE_ASC": "Preço: Menor para Maior",
"PRICE_DESC": "Preço: Maior para Menor",
"SN_ASC": "Alfabeticamente",
"UPDATED_AT_ASC": "Impopular",
"UPDATED_AT_DESC": "Interagido recentemente",
"blockNumber_ASC": "Antigo primeiro",
"blockNumber_DESC": "Novo primeiro",
"listed": "Compre agora",
"price_ASC": "Preço: Menor para Maior",
"price_ASC_NULLS_LAST": "Preço: Menor para Maior",
"price_DESC": "Preço: Maior para Menor",
"sn_ASC": "Alfabeticamente",
"updatedAt_ASC": "Impopular",
"updatedAt_DESC": "Interagido recentemente"
},
"listed": "Compre agora",
"own": "Em posse",
"price_ASC": "Preço: Menor para Maior",
"price_ASC_NULLS_LAST": "Preço: Menor para Maior",
"price_DESC": "Preço: Maior para Menor",
"sn_ASC": "Alfabeticamente",
"updatedAt_ASC": "Impopular",
Expand Down
6 changes: 2 additions & 4 deletions locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,6 @@
"BLOCK_NUMBER_ASC": "Старейший",
"BLOCK_NUMBER_DESC": "Недавно созданный",
"EMOTES_COUNT_DESC": "Наибольшее количество реакций",
"PRICE_ASC": "Цена: от низкой до высокой",
"PRICE_DESC": "Цена: от высокой до низкой",
"SN_ASC": "В алфавитном порядке",
"UPDATED_AT_ASC": "Непопулярный",
Expand All @@ -413,7 +412,7 @@
"blockNumber_DESC": "Недавно созданный",
"listed": "Купить сейчас",
"own": "Собственный",
"price_ASC": "Цена: от низкой до высокой",
"price_ASC_NULLS_LAST": "Цена: от низкой до высокой",
"price_DESC": "Цена: от высокой до низкой",
"sn_ASC": "В алфавитном порядке",
"updatedAt_ASC": "Непопулярный",
Expand All @@ -422,15 +421,14 @@
"BLOCK_NUMBER_ASC": "Старейший",
"BLOCK_NUMBER_DESC": "Недавно созданный",
"EMOTES_COUNT_DESC": "Наибольшее количество реакций",
"PRICE_ASC": "Цена: от низкой до высокой",
"PRICE_DESC": "Цена: от высокой до низкой",
"SN_ASC": "В алфавитном порядке",
"UPDATED_AT_ASC": "Непопулярный",
"UPDATED_AT_DESC": "Недавно взаимодействовали",
"blockNumber_ASC": "Сначала старый",
"blockNumber_DESC": "Сначала новый",
"listed": "Купить сейчас",
"price_ASC": "Цена: от низкой до высокой",
"price_ASC_NULLS_LAST": "Цена: от низкой до высокой",
"price_DESC": "Цена: от высокой до низкой",
"sn_ASC": "В алфавитном порядке",
"updatedAt_ASC": "Непопулярный",
Expand Down
6 changes: 2 additions & 4 deletions locales/ua.json
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@
"BLOCK_NUMBER_ASC": "Найстаріший",
"BLOCK_NUMBER_DESC": "Нещодавно створений",
"EMOTES_COUNT_DESC": "Найбільше реакцій",
"PRICE_ASC": "Ціна: від низької до високої",
"PRICE_DESC": "Ціна: від високої до низької",
"SN_ASC": "За алфавітом",
"UPDATED_AT_ASC": "Непопулярний",
Expand All @@ -385,7 +384,7 @@
"blockNumber_DESC": "Нещодавно створений",
"listed": "Купити зараз",
"own": "Власний",
"price_ASC": "Ціна: від низької до високої",
"price_ASC_NULLS_LAST": "Ціна: від низької до високої",
"price_DESC": "Ціна: від високої до низької",
"sn_ASC": "За алфавітом",
"updatedAt_ASC": "Непопулярний",
Expand All @@ -394,15 +393,14 @@
"BLOCK_NUMBER_ASC": "Найстаріший",
"BLOCK_NUMBER_DESC": "Нещодавно створений",
"EMOTES_COUNT_DESC": "Найбільше реакцій",
"PRICE_ASC": "Ціна: від низької до високої",
"PRICE_DESC": "Ціна: від високої до низької",
"SN_ASC": "За алфавітом",
"UPDATED_AT_ASC": "Непопулярний",
"UPDATED_AT_DESC": "Нещодавно взаємодіяли",
"blockNumber_ASC": "Спочатку старий",
"blockNumber_DESC": "Спочатку новий",
"listed": "Купити зараз",
"price_ASC": "Ціна: від низької до високої",
"price_ASC_NULLS_LAST": "Ціна: від низької до високої",
"price_DESC": "Ціна: від високої до низької",
"sn_ASC": "За алфавітом",
"updatedAt_ASC": "Непопулярний",
Expand Down
12 changes: 0 additions & 12 deletions pages/[prefix]/explore/items.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,6 @@ onBeforeMount(() => checkRouteAvailability())

definePageMeta({
layout: 'explore-layout',
middleware: [
function (to) {
if (to.query.listed === undefined) {
return navigateTo({
path: to.path,
query: {
...to.query,
listed: 'true',
} })
}
},
],
})

useSeoMeta({
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/explore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ test('Explore Items', async ({ page, Commands }) => {
await test.step('Sort results by price, ascending', async () => {
const exploreSort = page.getByTestId('explore-sort-dropdown').nth(1)
await exploreSort.click()
await page.getByTestId('price_ASC').nth(1).click()
const btnAsc = await page.$('[value="price_ASC"]')
await page.getByTestId('price_ASC_NULLS_LAST').nth(1).click()
const btnAsc = await page.$('[value="price_ASC_NULLS_LAST"]')
await btnAsc?.click()
await page.keyboard.press('Escape')
})
Expand Down
2 changes: 1 addition & 1 deletion utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const NFT_SQUID_SORT_CONDITION_LIST: string[] = [
'blockNumber_ASC',
'updatedAt_DESC',
'updatedAt_ASC',
'price_ASC',
'price_ASC_NULLS_LAST',
'price_DESC',
]

Expand Down
18 changes: 18 additions & 0 deletions utils/sort.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function removeDuplicateSortKeys(options: string[]) {
const uniqueOptions = {}

if (!Array.isArray(options)) {
return []
}

options.forEach((option) => {
const [identifier, ...rest] = option.split('_')
const sort = rest.join('_')

uniqueOptions[identifier] = sort
})

return Object.keys(uniqueOptions).map((identifier) => {
return `${identifier}_${uniqueOptions[identifier]}`
})
}
Loading