From 8e90578994c2904f784760640836157f3bc78f00 Mon Sep 17 00:00:00 2001 From: Jun Ma Date: Mon, 6 Mar 2023 01:34:52 +0800 Subject: [PATCH] add comments --- pages/multi-token-collections/index.tsx | 6 +++--- utils/handler.ts | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pages/multi-token-collections/index.tsx b/pages/multi-token-collections/index.tsx index b93ba634..26158b25 100644 --- a/pages/multi-token-collections/index.tsx +++ b/pages/multi-token-collections/index.tsx @@ -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' @@ -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({ diff --git a/utils/handler.ts b/utils/handler.ts index e110dddd..7c7ceaa8 100644 --- a/utils/handler.ts +++ b/utils/handler.ts @@ -75,18 +75,21 @@ export const handleNftImageLoadError = (e: React.SyntheticEvent { +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]) }) }