From fb3972b14b2842618f1761d77f8e30c924393a71 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Thu, 23 May 2024 17:01:12 +0800 Subject: [PATCH] feat: nft collection sort by timestamp (#342) --- src/locales/en.json | 1 + src/locales/zh.json | 1 + src/pages/NftCollections/List.tsx | 51 ++++++++++++++++--------- src/pages/NftCollections/util.ts | 2 +- src/services/ExplorerService/fetcher.ts | 1 + 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/locales/en.json b/src/locales/en.json index 6e323b225..60e3daffb 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -763,6 +763,7 @@ "transfer-list": "Transfers", "holder-list": "Holders", "transactions": "24hr Transactions", + "created_time": "Created Time", "holder": "Holder", "minted": "Minted", "owner": "Owner", diff --git a/src/locales/zh.json b/src/locales/zh.json index 1caad1939..6c70a537e 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -764,6 +764,7 @@ "transfer-list": "转让记录", "holder-list": "持有人列表", "transactions": "24小时交易数", + "created_time": "发行时间", "holder": "持有人", "minted": "发行数", "quantity": "数量", diff --git a/src/pages/NftCollections/List.tsx b/src/pages/NftCollections/List.tsx index 59154af96..5587518e0 100644 --- a/src/pages/NftCollections/List.tsx +++ b/src/pages/NftCollections/List.tsx @@ -12,6 +12,7 @@ import { useIsMobile, useSearchParams } from '../../hooks' import styles from './styles.module.scss' import type { NFTCollection } from '../../services/ExplorerService/fetcher' import { useNFTCollectionsSortParam } from './util' +import { parseSimpleDate } from '../../utils/date' const primaryColor = getPrimaryColor() function useFilterList(): Record<'title' | 'value', string>[] { @@ -113,6 +114,23 @@ const HolderMinterSort = () => { ) } +interface SimpleSortProps { + sortField: 'transactions' | 'timestamp' + fieldI18n: string +} +const SimpleSortHeader: React.FC = ({ sortField, fieldI18n }) => { + const sortParam = useNFTCollectionsSortParam() + const { handleSortClick } = sortParam + return ( + + {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */} + handleSortClick(sortField)} role="button" tabIndex={0}> + {fieldI18n} + + + + ) +} const TypeInfo: React.FC<{ nft: NFTCollection }> = ({ nft: item }) => { const { t } = useTranslation() @@ -149,7 +167,6 @@ const TypeInfo: React.FC<{ nft: NFTCollection }> = ({ nft: item }) => { export const ListOnDesktop: React.FC<{ isLoading: boolean; list: NFTCollection[] }> = ({ list, isLoading }) => { const { t } = useTranslation() - const sortParam = useNFTCollectionsSortParam() return ( @@ -160,17 +177,14 @@ export const ListOnDesktop: React.FC<{ isLoading: boolean; list: NFTCollection[] + @@ -230,6 +244,7 @@ export const ListOnDesktop: React.FC<{ isLoading: boolean; list: NFTCollection[] + - @@ -265,20 +280,14 @@ export const ListOnDesktop: React.FC<{ isLoading: boolean; list: NFTCollection[] export const ListOnMobile: React.FC<{ isLoading: boolean; list: NFTCollection[] }> = ({ list, isLoading }) => { const { t } = useTranslation() - const sortParam = useNFTCollectionsSortParam() return (
- - {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */} - sortParam.handleSortClick('transactions')} role="button" tabIndex={0}> - {t('nft.transactions')} - - - + +
{list.length ? ( @@ -343,6 +352,14 @@ export const ListOnMobile: React.FC<{ isLoading: boolean; list: NFTCollection[] )}`} +
+
{t('nft.transactions')}
+
{item.h24_ckb_transactions_count}
+
+
+
{t('nft.created_time')}
+
{item.timestamp === null ? '' : parseSimpleDate(item.timestamp)}
+
{item.creator ? (
{t(`nft.minter_address`)}
diff --git a/src/pages/NftCollections/util.ts b/src/pages/NftCollections/util.ts index 06dfceaf0..6b359283f 100644 --- a/src/pages/NftCollections/util.ts +++ b/src/pages/NftCollections/util.ts @@ -1,7 +1,7 @@ import { includes } from '../../utils/array' import { useSortParam } from '../../hooks' -const NFTSortByTypes = ['transactions', 'holder', 'minted'] as const +const NFTSortByTypes = ['transactions', 'holder', 'minted', 'timestamp'] as const type NFTSortByType = (typeof NFTSortByTypes)[number] export const useNFTCollectionsSortParam = () => diff --git a/src/services/ExplorerService/fetcher.ts b/src/services/ExplorerService/fetcher.ts index 9dc39fd93..aec75d56d 100644 --- a/src/services/ExplorerService/fetcher.ts +++ b/src/services/ExplorerService/fetcher.ts @@ -1133,6 +1133,7 @@ export interface NFTCollection { holders_count: number | null type_script: { code_hash: string; hash_type: 'data' | 'type'; args: string } | null sn: string + timestamp: number } export interface NFTItem {
- - {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */} - sortParam.handleSortClick('transactions')} role="button" tabIndex={0}> - {t('nft.transactions')} - - - + + + {t('nft.minter_address')}
{`${(item.holders_count ?? 0).toLocaleString('en')}/${(item.items_count ?? 0).toLocaleString( 'en', )}`}{item.timestamp === null ? '' : parseSimpleDate(item.timestamp)}
{item.creator ? ( @@ -253,7 +268,7 @@ export const ListOnDesktop: React.FC<{ isLoading: boolean; list: NFTCollection[] }) ) : (
+ {isLoading ? 'loading' : t(`nft.no_record`)}