Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsupa597 committed Mar 7, 2023
1 parent 6663517 commit 8e90578
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pages/multi-token-collections/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { SIZES } from 'components/PageSize'

import NoDataIcon from 'assets/icons/no-data.svg'
import SortIcon from 'assets/icons/sort.svg'
import { client, GraphQLSchema, handleSorterArrayToMap, handleSorterArrayFromPath } from 'utils'
import { client, GraphQLSchema, handleSorterArrayToMap, handleSorterArrayAboutPath } from 'utils'

import styles from './styles.module.scss'

Expand Down Expand Up @@ -124,10 +124,10 @@ const MultiTokenCollectionList = () => {
{ type: 'holder_count_sort', order: 'ASC' },
]

const sorterArrayFromPath = handleSorterArrayFromPath(asPath, sorters)
const sorterArrayFromPath = handleSorterArrayAboutPath(asPath, sorters)

// get a sorter array to query listdata from server
const sorterArrayForQuery = handleSorterArrayFromPath(asPath, sorters, UdtsSorterValueEnum)
const sorterArrayForQuery = handleSorterArrayAboutPath(asPath, sorters, UdtsSorterValueEnum)

const handleUrlForPush = (clickedSorter = null) => {
return `${asPath.split('?')[0] ?? ''}?${new URLSearchParams({
Expand Down
7 changes: 5 additions & 2 deletions utils/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,21 @@ export const handleNftImageLoadError = (e: React.SyntheticEvent<HTMLImageElement
}

// return a sorter array
export const handleSorterArrayFromPath = (url, sorters, sorterValueEnum = null) => {
export const handleSorterArrayAboutPath = (url, sorters, sorterValueEnum = null) => {
const params = url.slice(url.indexOf('?') + 1)
const sorterParamsArray = []

var searchParams = new URLSearchParams(params)
const searchParams = new URLSearchParams(params)
Array(...searchParams.keys()).forEach((item, index) => {
if (sorters.includes(item)) {
// return sort array which used for query, like: [{sort_type: ASC , sort_value: xxx}]
if (sorterValueEnum) {
sorterParamsArray.push({
sort_type: decodeURIComponent([...searchParams.values()][index]),
sort_value: sorterValueEnum[item],
})

// return sort array which from url, like: [{type: xxx , order: ASC}]
} else {
sorterParamsArray.push({ type: item, order: decodeURIComponent([...searchParams.values()][index]) })
}
Expand Down

0 comments on commit 8e90578

Please sign in to comment.