Skip to content

Commit

Permalink
filter is applied
Browse files Browse the repository at this point in the history
  • Loading branch information
hasnat-shohag committed Nov 13, 2023
1 parent c82cd77 commit 4179795
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
40 changes: 35 additions & 5 deletions src/components/Todo/Todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const Todo = () => {
const isDataFetched = useRef(false);
const [isLoading, setIsLoading] = useState(true);
const [errorMessage, setErrorMessage] = useState("");
const [filter, setFilter] = useState("");

const apiFun = async () => {
let responseData = await fetch(
Expand All @@ -28,6 +29,10 @@ const Todo = () => {
isDataFetched.current = true;
}, []);

const handleChangeFilter = (event) => {
setFilter(event.target.value);
};

if (isLoading) {
return <LoadingSpinner />;
}
Expand All @@ -36,13 +41,38 @@ const Todo = () => {
return <div>{errorMessage}</div>;
}

let todoList = value;

if (filter === "Completed") {
todoList = value.filter((todo) => todo.completed);
} else if (filter === "Incompleted") {
todoList = value.filter((todo) => !todo.completed);
}

return (
<div>
<ul>
{value.map((val) => {
return <li key={val.id}>{val.title}</li>;
})}
</ul>
<div className="main-content">
<div className="todo-list-content">
<ul>
{todoList.map((val) => {
return <li key={val.id}>{val.title}</li>;
})}
</ul>
</div>
<div className="short-content">
<label>Filter: </label>
<select
name="filter"
value={filter}
onChange={handleChangeFilter}
>
<option value="">-- Please Select --</option>
<option value="Completed">Completed</option>
<option value="Incompleted">Incompleted</option>
<option value="Both">Both</option>
</select>
</div>
</div>
</div>
);
};
Expand Down
14 changes: 14 additions & 0 deletions src/styles/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,17 @@
transform: rotate(360deg);
}
}
.main-content{
margin-top: 20px;
display: flex;
flex-direction: row;
justify-content: space-between;

}
/* .main-content .todo-list-content{} */
.main-content .todo-list-content ul{
list-style: number;
}
.main-content .todo-list-content ul li{
padding: 10px;
}

0 comments on commit 4179795

Please sign in to comment.