generated from defi-wonderland/web3-react-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes ZKS-112
- Loading branch information
Showing
5 changed files
with
32 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |