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: search chain by id #8

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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>
);
};
Loading