Spaces:
Running
Running
File size: 7,341 Bytes
3e519ec | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | class ToolTasks extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
// Load tasks from localStorage if available
const savedTasks = JSON.parse(localStorage.getItem('flowstate_tasks')) || [];
this.tasks = savedTasks;
this.shadowRoot.innerHTML = `
<style>
.wrapper {
background: #1e293b;
border-radius: 1rem;
padding: 2rem;
border: 1px solid #334155;
}
.input-group {
display: flex;
gap: 0.5rem;
margin-bottom: 2rem;
}
input[type="text"] {
flex-grow: 1;
background: #0f172a;
border: 1px solid #334155;
padding: 0.75rem 1rem;
border-radius: 0.5rem;
color: white;
font-size: 1rem;
outline: none;
transition: border-color 0.2s;
}
input[type="text"]:focus {
border-color: #10b981;
}
.add-btn {
background: #10b981;
color: white;
border: none;
padding: 0 1.5rem;
border-radius: 0.5rem;
font-weight: 600;
cursor: pointer;
transition: background 0.2s;
}
.add-btn:hover {
background: #059669;
}
.task-list {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
gap: 0.75rem;
max-height: 60vh;
overflow-y: auto;
}
.task-item {
display: flex;
align-items: center;
background: #0f172a;
padding: 0.75rem 1rem;
border-radius: 0.5rem;
border: 1px solid #334155;
transition: all 0.2s;
animation: slideIn 0.3s ease;
}
@keyframes slideIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.task-item:hover {
border-color: #475569;
transform: translateX(4px);
}
.task-item.completed {
opacity: 0.5;
background: #020617;
}
.task-item.completed span {
text-decoration: line-through;
color: #64748b;
}
.checkbox {
width: 20px;
height: 20px;
border: 2px solid #475569;
border-radius: 4px;
margin-right: 1rem;
cursor: pointer;
display: grid;
place-items: center;
flex-shrink: 0;
}
.task-item.completed .checkbox {
background: #10b981;
border-color: #10b981;
}
.task-text {
flex-grow: 1;
font-size: 1rem;
}
.delete-btn {
background: transparent;
border: none;
color: #ef4444;
opacity: 0;
cursor: pointer;
transition: opacity 0.2s;
}
.task-item:hover .delete-btn {
opacity: 1;
}
.empty-state {
text-align: center;
color: #64748b;
padding: 2rem;
font-style: italic;
}
/* Custom Scrollbar for list */
.task-list::-webkit-scrollbar {
width: 6px;
}
.task-list::-webkit-scrollbar-thumb {
background: #334155;
border-radius: 3px;
}
</style>
<div class="wrapper">
<div class="input-group">
<input type="text" id="taskInput" placeholder="What needs doing?">
<button class="add-btn" id="addBtn">
<i data-feather="plus"></i>
</button>
</div>
<ul class="task-list" id="taskList">
<!-- Tasks will be injected here -->
</ul>
</div>
`;
this.inputEl = this.shadowRoot.getElementById('taskInput');
this.listEl = this.shadowRoot.getElementById('taskList');
this.addBtn = this.shadowRoot.getElementById('addBtn');
this.addBtn.addEventListener('click', () => this.addTask());
this.inputEl.addEventListener('keypress', (e) => {
if (e.key === 'Enter') this.addTask();
});
this.renderTasks();
feather.replace();
}
renderTasks() {
this.listEl.innerHTML = '';
if (this.tasks.length === 0) {
this.listEl.innerHTML = '<li class="empty-state">All clear. Flow unblocked.</li>';
return;
}
this.tasks.forEach((task, index) => {
const li = document.createElement('li');
li.className = `task-item ${task.completed ? 'completed' : ''}`;
li.innerHTML = `
<div class="checkbox" onclick="this.getRootNode().host.toggleTask(${index})">
${task.completed ? '<i data-feather="check" color="white" width="14" height="14"></i>' : ''}
</div>
<span class="task-text">${this.escapeHtml(task.text)}</span>
<button class="delete-btn" onclick="this.getRootNode().host.deleteTask(${index})">
<i data-feather="trash-2" width="18" height="18"></i>
</button>
`;
this.listEl.appendChild(li);
});
feather.replace();
this.save();
}
addTask() {
const text = this.inputEl.value.trim();
if (text) {
this.tasks.unshift({ text, completed: false });
this.inputEl.value = '';
this.renderTasks();
}
}
toggleTask(index) {
this.tasks[index].completed = !this.tasks[index].completed;
this.renderTasks();
}
deleteTask(index) {
this.tasks.splice(index, 1);
this.renderTasks();
}
save() {
localStorage.setItem('flowstate_tasks', JSON.stringify(this.tasks));
}
escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
}
customElements.define('tool-tasks', ToolTasks); |