From 86ed6d2f02fcf7d2d3cf1b5b82362af3eba91021 Mon Sep 17 00:00:00 2001 From: Majorfi Date: Wed, 13 Nov 2024 10:46:41 +0100 Subject: [PATCH] list view --- app/components/Lists.tsx | 92 ++++++++++++++++++------------- app/components/TokenListTable.tsx | 88 +++++++++++++++++++++++++++++ app/components/ViewToggle.tsx | 25 +++++++++ app/list/[list]/page.tsx | 4 +- package.json | 1 + 5 files changed, 169 insertions(+), 41 deletions(-) create mode 100644 app/components/TokenListTable.tsx create mode 100644 app/components/ViewToggle.tsx diff --git a/app/components/Lists.tsx b/app/components/Lists.tsx index b908520..1e9e06d 100644 --- a/app/components/Lists.tsx +++ b/app/components/Lists.tsx @@ -8,6 +8,7 @@ import useSWR from 'swr'; import {motion} from 'framer-motion'; import TokenListCard, {LegacyTokenListCard} from './TokenListCard'; +import {ViewToggle} from './ViewToggle'; import type {Variants} from 'framer-motion'; import type {ReactElement} from 'react'; @@ -15,6 +16,7 @@ import type {TNDict} from '@builtbymom/web3/types'; import type {TTokenListItem, TTokenListSummary} from '@/utils/types/types'; import TokenListHero from '@/app/components/TokenListHero'; +import {TokenListTable} from '@/app/components/TokenListTable'; import LEGACY_TOKEN_LISTS from '@/utils/legacyTokenLists'; const fetcher = async (url: string): Promise => axios.get(url).then(res => res.data); @@ -101,6 +103,7 @@ export function Filters({ function Lists(): ReactElement { const [typeOfList, set_typeOfList] = useState<'tokens' | 'pools' | 'chains' | 'statics' | 'legacy'>('chains'); + const [viewMode, set_viewMode] = useState<'grid' | 'list'>('grid'); const [search, set_search] = useState(''); const [currentNetwork, set_currentNetwork] = useState(-1); const {data: summary} = useSWR( @@ -217,12 +220,18 @@ function Lists(): ReactElement {
- +
+ + +
-
- {typeOfList === 'legacy' - ? LEGACY_TOKEN_LISTS.map( - (tokenListItem, i): ReactElement => ( - - - - ) - ) - : (listToRender || []).map( - (tokenListItem: TTokenListItem, i: number): ReactElement => ( - - - + {viewMode === 'grid' ? ( +
+ {typeOfList === 'legacy' + ? LEGACY_TOKEN_LISTS.map( + (tokenListItem, i): ReactElement => ( + + + + ) ) - )} -
+ : (listToRender || []).map( + (tokenListItem: TTokenListItem, i: number): ReactElement => ( + + + + ) + )} +
+ ) : ( + + )}
); diff --git a/app/components/TokenListTable.tsx b/app/components/TokenListTable.tsx new file mode 100644 index 0000000..c1d15d2 --- /dev/null +++ b/app/components/TokenListTable.tsx @@ -0,0 +1,88 @@ +import Link from 'next/link'; +import {ArrowUpRight} from 'lucide-react'; +import {formatAmount} from '@builtbymom/web3/utils'; + +import type {ReactElement} from 'react'; +import type {TTokenListItem} from '@utils/types/types'; + +import {ImageWithFallback} from '@/app/components/ImageWithFallback'; + +type TTokenListTableProps = { + items: TTokenListItem[]; + network: number; +}; + +export function TokenListTable({items, network}: TTokenListTableProps): ReactElement { + return ( +
+ + + + + + + + + + + {items.map(item => { + const fileName = (item.URI || '') + .toLowerCase() + .replace('https://raw.githubusercontent.com/smoldapp/tokenlists/main/lists/', ''); + + return ( + + + + + + + ); + })} + +
{'Name'}{'Version'}{'Tokens'}{'View'}
+ + +
+ {item.name} +

+ {item.description || `A list of token for ${item.name}`} +

+
+ +
+ {`v${item.version.major}.${item.version.minor}.${item.version.patch}`} + + {formatAmount( + network === -1 + ? item.tokenCount + : item.metadata.tokenCountPerChain[network] || 0, + 0, + 0 + )} + + + + +
+
+ ); +} diff --git a/app/components/ViewToggle.tsx b/app/components/ViewToggle.tsx new file mode 100644 index 0000000..7fb6039 --- /dev/null +++ b/app/components/ViewToggle.tsx @@ -0,0 +1,25 @@ +import {LayoutGrid, LayoutList} from 'lucide-react'; + +import Button from './Button'; + +import type {ReactElement} from 'react'; + +type TViewMode = 'grid' | 'list'; + +type TViewToggleProps = { + currentView: TViewMode; + onViewChange: (view: TViewMode) => void; +}; + +export function ViewToggle({currentView, onViewChange}: TViewToggleProps): ReactElement { + return ( +
+ +
+ ); +} diff --git a/app/list/[list]/page.tsx b/app/list/[list]/page.tsx index e5d10de..1182d5e 100644 --- a/app/list/[list]/page.tsx +++ b/app/list/[list]/page.tsx @@ -55,8 +55,8 @@ async function getList(listId: string): Promise { } } -export default async function ListPage({params}: any): Promise { - const list = await getList(params.list); +export default async function ListPage({params}: {params: {list: string}}): Promise { + const list = await getList(await params.list); if (!list) { return { diff --git a/package.json b/package.json index 2542c45..4074ee0 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "dayjs": "^1.11.11", "framer-motion": "^11.3.3", "graphql-request": "^7.1.0", + "lucide-react": "^0.456.0", "next": "^15.0.3", "next-pwa": "^5.6.0", "next-seo": "^6.5.0",