Skip to content

Commit

Permalink
feat: search logic (#4)
Browse files Browse the repository at this point in the history
closes ZKS-106
  • Loading branch information
0xtiti authored Jul 18, 2024
2 parents fb72425 + e855fcb commit f6a50ee
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 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
21 changes: 18 additions & 3 deletions src/containers/Dashboard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
import { useState } from 'react';
import { SearchBar, Table, Title } from '~/components';
import { useData } from '~/hooks';

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

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

0 comments on commit f6a50ee

Please sign in to comment.