Skip to content

Commit

Permalink
feat: search by id | chain not found
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtiti committed Jul 19, 2024
1 parent 9932945 commit bd9e62d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
3 changes: 2 additions & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"nativeToken": "Native token",
"tvl": "TVL - L1",
"type": "Type",
"search": "Search by chain name or id..."
"search": "Search by chain name or id...",
"notFound": "Chain not found"
}
},
"CHAINPAGE": {
Expand Down
3 changes: 2 additions & 1 deletion public/locales/es/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"nativeToken": "Token nativo",
"tvl": "TVL - L1",
"type": "Tipo",
"search": "Buscar por nombre o ID de la cadena..."
"search": "Buscar por nombre o ID de la cadena...",
"notFound": "Cadena no encontrada"
}
},
"CHAINPAGE": {
Expand Down
11 changes: 11 additions & 0 deletions src/components/NotFound.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
interface NotFoundProps {
text: string;
}

export const NotFound = ({ text }: NotFoundProps) => {
return (
<div>
<p>{text}</p>
</div>
);
};
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './SearchBar';
export * from './TotalValueLocked';
export * from './Title';
export * from './TitleBanner';
export * from './NotFound';
23 changes: 16 additions & 7 deletions src/containers/Dashboard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
import { useTranslation } from 'next-i18next';
import { useState } from 'react';

import { SearchBar, Table, Title } from '~/components';
import { NotFound, SearchBar, Table, Title } from '~/components';
import { useData } from '~/hooks';

export const Dashboard = () => {
const { t } = useTranslation();
const { ecosystemData } = useData();
const [searchTerm, setSearchTerm] = useState<string>('');

const filteredChains = ecosystemData?.chains.filter((chain) => {
const chainIdStr = String(chain.id);
const formattedSearchTerm = String(searchTerm).toLowerCase();

// Check if either chain name or chain ID matches the search term
const matchesName = chain.name.toLowerCase().includes(formattedSearchTerm);
const matchesId = chainIdStr.includes(formattedSearchTerm);

return matchesName || matchesId;
});

const availableChains = filteredChains?.length > 0;

const handleChange = (value: string) => {
setSearchTerm(value);
};

// Filter chains based on search term
const filteredChains = ecosystemData?.chains.filter((chain) =>
chain.name.toLowerCase().includes(searchTerm.toLowerCase()),
);

return (
<section>
<header>
<Title title={t('HOME.DASHBOARD.title')} />
<SearchBar value={searchTerm} onChange={handleChange} />
</header>

<Table chains={filteredChains} />
{availableChains && <Table chains={filteredChains} />}
{!availableChains && <NotFound text={t('HOME.DASHBOARD.notFound')} />}
</section>
);
};

0 comments on commit bd9e62d

Please sign in to comment.