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: nft collection sort by timestamp #342

Merged
merged 3 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@
"transfer-list": "Transfers",
"holder-list": "Holders",
"transactions": "24hr Transactions",
"created_time": "Created Time",
"holder": "Holder",
"minted": "Minted",
"owner": "Owner",
Expand Down
1 change: 1 addition & 0 deletions src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@
"transfer-list": "转让记录",
"holder-list": "持有人列表",
"transactions": "24小时交易数",
"created_time": "发行时间",
"holder": "持有人",
"minted": "发行数",
"quantity": "数量",
Expand Down
49 changes: 33 additions & 16 deletions src/pages/NftCollections/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>[] {
Expand Down Expand Up @@ -113,6 +114,23 @@ const HolderMinterSort = () => {
</div>
)
}
interface SimpleSortProps {
sortField: 'transactions' | 'timestamp'
fieldI18n: string
}
const SimpleSortHeader: React.FC<SimpleSortProps> = ({ sortField, fieldI18n }) => {
const sortParam = useNFTCollectionsSortParam()
Keith-CY marked this conversation as resolved.
Show resolved Hide resolved
const { handleSortClick } = sortParam
return (
<span>
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */}
<span onClick={() => handleSortClick(sortField)} role="button" tabIndex={0}>
Keith-CY marked this conversation as resolved.
Show resolved Hide resolved
{fieldI18n}
</span>
<SortButton field={sortField} sortParam={sortParam} />
</span>
)
}

const TypeInfo: React.FC<{ nft: NFTCollection }> = ({ nft: item }) => {
const { t } = useTranslation()
Expand Down Expand Up @@ -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 (
<table data-role="desktop-list">
Expand All @@ -160,17 +177,14 @@ export const ListOnDesktop: React.FC<{ isLoading: boolean; list: NFTCollection[]
<TypeFilter />
</th>
<th className={styles.transactionsHeader}>
<span>
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */}
<span onClick={() => sortParam.handleSortClick('transactions')} role="button" tabIndex={0}>
{t('nft.transactions')}
</span>
<SortButton field="transactions" sortParam={sortParam} />
</span>
<SimpleSortHeader sortField="transactions" fieldI18n={t('nft.transactions')} />
</th>
<th>
<HolderMinterSort />
</th>
<th>
<SimpleSortHeader sortField="timestamp" fieldI18n={t('nft.created_time')} />
</th>
<th>{t('nft.minter_address')}</th>
</tr>
</thead>
Expand Down Expand Up @@ -230,6 +244,7 @@ export const ListOnDesktop: React.FC<{ isLoading: boolean; list: NFTCollection[]
<td>{`${(item.holders_count ?? 0).toLocaleString('en')}/${(item.items_count ?? 0).toLocaleString(
'en',
)}`}</td>
<td>{item.timestamp === null ? '' : parseSimpleDate(item.timestamp)}</td>
<td>
<div>
{item.creator ? (
Expand Down Expand Up @@ -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 (
<div data-role="mobile-list">
<div className={styles.listHeader}>
<TypeFilter />
<span>
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */}
<span onClick={() => sortParam.handleSortClick('transactions')} role="button" tabIndex={0}>
{t('nft.transactions')}
</span>
<SortButton field="transactions" sortParam={sortParam} />
</span>
<SimpleSortHeader sortField="transactions" fieldI18n={t('nft.transactions')} />
<HolderMinterSort />
<SimpleSortHeader sortField="timestamp" fieldI18n={t('nft.created_time')} />
</div>
<div>
{list.length ? (
Expand Down Expand Up @@ -343,6 +352,14 @@ export const ListOnMobile: React.FC<{ isLoading: boolean; list: NFTCollection[]
)}`}
</dd>
</dl>
<dl>
<dt>{t('nft.transactions')}</dt>
<dd>{item.h24_ckb_transactions_count}</dd>
</dl>
<dl>
<dt>{t('nft.created_time')}</dt>
<dd>{item.timestamp === null ? '' : parseSimpleDate(item.timestamp)}</dd>
</dl>
{item.creator ? (
<dl>
<dt>{t(`nft.minter_address`)}</dt>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/NftCollections/util.ts
Original file line number Diff line number Diff line change
@@ -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 = () =>
Expand Down
1 change: 1 addition & 0 deletions src/services/ExplorerService/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down