2021-08-01 21:33:31 +02:00
|
|
|
<script>
|
2021-08-01 22:22:34 +02:00
|
|
|
import {todos} from "$lib/stores/todos.js";
|
|
|
|
let todo_text = "";
|
2021-08-02 07:59:31 +02:00
|
|
|
let todo_type = "active";
|
2021-08-01 23:04:31 +02:00
|
|
|
let filteredTodo = [];
|
2021-08-01 21:33:31 +02:00
|
|
|
let addTodo = () => {
|
|
|
|
if (todo_text.length > 0) {
|
|
|
|
const todo = {
|
|
|
|
text: todo_text,
|
|
|
|
date: Date.now,
|
|
|
|
done: false
|
|
|
|
}
|
2021-08-01 23:04:31 +02:00
|
|
|
if (todo_type == "done") todo_type = "all";
|
2021-08-01 21:33:31 +02:00
|
|
|
$todos = [todo, ...$todos];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let clearTodo = (todo) => {
|
2021-08-01 23:04:31 +02:00
|
|
|
if(todo.done) {
|
2021-08-01 21:33:31 +02:00
|
|
|
$todos = $todos.filter(x => x != todo)
|
2021-08-01 23:04:31 +02:00
|
|
|
}
|
|
|
|
else {
|
2021-08-01 21:33:31 +02:00
|
|
|
todo.done = true;
|
2021-08-01 23:04:31 +02:00
|
|
|
$todos = $todos
|
|
|
|
}
|
2021-08-01 21:33:31 +02:00
|
|
|
}
|
2021-08-01 22:22:34 +02:00
|
|
|
let filterTodo = (type) => {
|
2021-08-01 23:04:31 +02:00
|
|
|
todo_type = type;
|
2021-08-01 22:22:34 +02:00
|
|
|
switch (type) {
|
|
|
|
case 'active':
|
|
|
|
filteredTodo = $todos.filter(todo => !todo.done);
|
|
|
|
break;
|
|
|
|
case 'done':
|
|
|
|
filteredTodo = $todos.filter(todo => todo.done);
|
|
|
|
break;
|
|
|
|
case 'all':
|
|
|
|
filteredTodo = $todos;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-08-01 23:04:31 +02:00
|
|
|
$: {
|
|
|
|
filteredTodo = $todos;
|
|
|
|
filterTodo(todo_type)
|
|
|
|
}
|
2021-08-01 21:33:31 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class = "panel">
|
2021-08-01 22:22:34 +02:00
|
|
|
<h2 class= "title">TODO</h2>
|
|
|
|
<hr/>
|
2021-08-02 07:59:31 +02:00
|
|
|
<input bind:value="{todo_text}" placeholder="title"/>
|
|
|
|
<button on:click="{addTodo}" disabled = {todo_text.length == 0} class = {todo_text.length == 0 ? 'disabled' : ''}>add</button>
|
2021-08-01 22:22:34 +02:00
|
|
|
<div class="todo-filter">
|
2021-08-02 07:59:31 +02:00
|
|
|
<button on:click="{() => filterTodo('active')}" class = {todo_type == 'active' ? 'disabled' : ''}>active</button>
|
|
|
|
<button on:click="{() => filterTodo('done')}" class = {todo_type == 'done' ? 'disabled' : ''}>done</button>
|
|
|
|
<button on:click="{() => filterTodo('all')}" class = {todo_type == 'all' ? 'disabled' : ''}>all</button>
|
2021-08-01 21:33:31 +02:00
|
|
|
</div>
|
2021-08-01 22:22:34 +02:00
|
|
|
<ul class = "todo-list">
|
|
|
|
{#each filteredTodo as todo}
|
|
|
|
<li class = "todo {todo.done ? 'done' : ''}">
|
|
|
|
<p>{todo.text}</p>
|
|
|
|
<button on:click="{() => clearTodo(todo)}">{todo.done ? '✗' : '✓'}</button>
|
|
|
|
</li>
|
|
|
|
{/each}
|
|
|
|
</ul>
|
2021-08-01 21:33:31 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
|
|
|
input {
|
|
|
|
padding: 5px;
|
|
|
|
margin: 0px;
|
2021-08-01 22:40:32 +02:00
|
|
|
border: solid var(--gray) 1px;
|
2021-08-01 21:33:31 +02:00
|
|
|
border-radius: 5px;
|
|
|
|
}
|
|
|
|
|
|
|
|
button {
|
|
|
|
padding: 5px;
|
|
|
|
margin: 0px;
|
2021-08-01 22:40:32 +02:00
|
|
|
background-color: var(--lightgray);
|
|
|
|
border: solid var(--gray) 1px;
|
2021-08-01 21:33:31 +02:00
|
|
|
border-radius: 5px;
|
|
|
|
}
|
|
|
|
|
2021-08-02 07:59:31 +02:00
|
|
|
.disabled {
|
|
|
|
background-color: var(--gray);
|
|
|
|
}
|
|
|
|
|
|
|
|
button:active {
|
|
|
|
background-color: var(--gray);
|
|
|
|
}
|
|
|
|
|
2021-08-01 22:22:34 +02:00
|
|
|
hr {
|
2021-08-01 22:40:32 +02:00
|
|
|
margin-top: 10px;
|
|
|
|
margin-bottom: 10px;
|
|
|
|
border: 1px solid var(--gray);
|
2021-08-01 22:22:34 +02:00
|
|
|
}
|
|
|
|
|
2021-08-01 21:33:31 +02:00
|
|
|
.panel {
|
|
|
|
background-color: rgb(245, 253, 255);
|
|
|
|
padding: 10px;
|
2021-08-01 22:40:32 +02:00
|
|
|
border: solid var(--gray) 1px;
|
2021-08-01 21:33:31 +02:00
|
|
|
border-radius: 5px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.title {
|
2021-08-01 22:22:34 +02:00
|
|
|
padding: 0px;
|
2021-08-01 21:33:31 +02:00
|
|
|
margin: 0px;
|
|
|
|
margin-left: 5px;
|
|
|
|
font-family: Georgia, 'Times New Roman', Times, serif;
|
|
|
|
font-weight: 400;
|
|
|
|
font-size: 1.5rem;
|
|
|
|
}
|
|
|
|
|
2021-08-01 22:22:34 +02:00
|
|
|
.todo-filter {
|
|
|
|
padding-top: 10px;
|
|
|
|
padding-bottom: 10px;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.todo-filter button {
|
|
|
|
margin-right: 5px;
|
|
|
|
}
|
|
|
|
|
2021-08-01 21:33:31 +02:00
|
|
|
/* .todo-list {
|
|
|
|
padding: 5px;
|
|
|
|
background-color: azure;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
} */
|
|
|
|
|
|
|
|
.todo {
|
|
|
|
padding: 10px;
|
|
|
|
margin: 5px 0px 5px 0px;
|
|
|
|
background-color: rgb(255, 255, 255);
|
2021-08-01 22:40:32 +02:00
|
|
|
border: solid var(--gray) 1px;
|
2021-08-01 21:33:31 +02:00
|
|
|
border-radius: 5px;
|
|
|
|
display: flex;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.done p {
|
|
|
|
text-decoration: line-through
|
|
|
|
}
|
|
|
|
|
|
|
|
.todo p {
|
|
|
|
padding: 0px;
|
|
|
|
margin: 0px 10px 0px 0px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.todo button {
|
|
|
|
margin-left: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|