Skip to content

Commit

Permalink
feat: search bar
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtiti committed Jul 17, 2024
1 parent 8b82fb8 commit 99ac76f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
13 changes: 11 additions & 2 deletions src/components/SearchBar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
export const SearchBar = () => {
interface SearchBarProps {
value: string;
onChange: (value: string) => void;
}

export const SearchBar = ({ value, onChange }: SearchBarProps) => {
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
onChange(event.target.value);
};

return (
<form>
<input type='text' placeholder='Search...' />
<input type='text' value={value} onChange={handleChange} placeholder='Search...' />
</form>
);
};
11 changes: 7 additions & 4 deletions src/components/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { useData } from '~/hooks';
import { EcosystemChainData } from '~/types';

export const Table = () => {
const { ecosystemData } = useData();
interface TableProps {
chains: EcosystemChainData[];
}

export const Table = ({ chains }: TableProps) => {
return (
<table>
<tr>
Expand All @@ -12,7 +15,7 @@ export const Table = () => {
<th>Type</th>
</tr>

{ecosystemData?.chains.map((data, index) => {
{chains?.map((data, index) => {
return (
<tr key={index}>
<td>{data.name}</td>
Expand Down
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './CustomHead';
export * from './Table';
export * from './SearchBar';
export * from './TotalValueLocked';
export * from './Title';
22 changes: 18 additions & 4 deletions src/containers/Dashboard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import { SearchBar, Table } from '~/components';
import { Title } from '~/components/Title';
import { useState } from 'react';
import { SearchBar, Table, Title } from '~/components';
import { useData } from '~/hooks';

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

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={'Chain list'} />
<SearchBar />
<SearchBar value={searchTerm} onChange={handleChange} />
</header>
<Table />

<Table chains={filteredChains} />
</section>
);
};
Expand Down

0 comments on commit 99ac76f

Please sign in to comment.