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 logic #4

Merged
merged 4 commits into from
Jul 18, 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
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()),
Copy link
Member

@0xArdy 0xArdy Jul 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the user should be able to search by chainId too, but it can be added in another pr

);

return (
<section>
<header>
<Title title='Chain list' />
<SearchBar />
<Title title={'Chain list'} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Title title={'Chain list'} />
<Title title="Chain list" />

<SearchBar value={searchTerm} onChange={handleChange} />
</header>
<Table />

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