Skip to content

Commit

Permalink
Merge pull request #25 from the-collab-lab/ec-hm-issue-7
Browse files Browse the repository at this point in the history
7. add search list form and function in List
  • Loading branch information
3campos authored Feb 23, 2024
2 parents 40ba763 + eda4664 commit 9b54739
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/api/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export async function addItem(listPath, { itemName, daysUntilNextPurchase }) {
// We'll use updateItem to put a Date here when the item is purchased!
dateLastPurchased: null,
dateNextPurchased: getFutureDate(daysUntilNextPurchase),
name: itemName,
name: itemName.toLowerCase(),
totalPurchases: 0,
});
}
Expand Down
34 changes: 33 additions & 1 deletion src/views/List.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
import { useState } from 'react';
import { ListItem } from '../components/ListItem';

export function List({ data }) {
const [search, setSearch] = useState('');

const handleSubmit = (e) => {
e.preventDefault();
};

const handleChange = (e) => {
setSearch(e.target.value);
};

const handleClear = () => {
setSearch('');
};

const filteredData = data.filter((item) =>
item.name.includes(search.toLowerCase()),
);

return (
<>
<p>
Hello from the <code>/list</code> page!
</p>
<form onSubmit={handleSubmit}>
<label htmlFor="search">Search:</label>
<input
type="text"
id="search"
name="search"
onChange={handleChange}
value={search}
/>
<button type="button" onClick={handleClear}>
x
</button>
</form>
<ul>
{data.map((item) => (
{filteredData.map((item) => (
<ListItem key={item.name} name={item.name} />
))}
</ul>
Expand Down

0 comments on commit 9b54739

Please sign in to comment.