Skip to content

Commit

Permalink
Add button to clear search list
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlpoole committed Dec 17, 2023
1 parent 64fa6d8 commit 5e2020b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions islands/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useEffect, useState } from "preact/hooks";
import AddToList from "../islands/AddToList.tsx";
import CountList from "../islands/CountList.tsx";
import Search from "../types/Search.ts";
import { Button } from "../components/Button.tsx";

export default function App() {
const [searchList, setSearchList] = useState([] as Search[]);
Expand All @@ -16,13 +17,19 @@ export default function App() {

function addTerm(newSearch: Search) {
const newList = [...searchList, newSearch];

setSearchList(newList);
localStorage.setItem(
"seekerList",
JSON.stringify(newList),
);
}

function clearList() {
setSearchList([]);
localStorage.removeItem("seekerList");
}

return (
<>
<h1 class="text-4xl font-bold pb-4 text-white">The Seeker</h1>
Expand All @@ -32,6 +39,7 @@ export default function App() {
</p>
<AddToList addTerm={addTerm} />
<CountList searchList={searchList} />
{searchList.length > 0 && <Button onClick={clearList}>Clear list</Button>}
</>
);
}

0 comments on commit 5e2020b

Please sign in to comment.