-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
50 lines (40 loc) · 1.5 KB
/
app.js
File metadata and controls
50 lines (40 loc) · 1.5 KB
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
// app.js
import { Store } from './store.js';
import { UI } from './UI.js';
const appStore = new Store();
// INITIALIZE: Tell UI to render whenever Store changes
appStore.subscribe((newState) => {
UI.renderTasks(newState, (id, col) => appStore.deleteTask(id, col));
});
// EVENT: Add Task
const input = document.getElementById('taskInput');
const addBtn = document.getElementById('addBtn');
const handleAddTask = () => {
if (input.value.trim()) {
appStore.addTask('todo', input.value);
input.value = '';
}
};
addBtn.addEventListener('click', handleAddTask);
input.addEventListener('keypress', (e) => { if(e.key === 'Enter') handleAddTask(); });
// EVENT: Drop Zones (Drag & Drop API)
document.querySelectorAll('.column').forEach(zone => {
zone.addEventListener('dragover', (e) => {
e.preventDefault(); // Required to allow drop
zone.style.background = "rgba(255, 255, 255, 0.1)";
});
zone.addEventListener('dragleave', () => {
zone.style.background = "rgba(255, 255, 255, 0.03)";
});
zone.addEventListener('drop', (e) => {
zone.style.background = "rgba(255, 255, 255, 0.03)";
const taskId = e.dataTransfer.getData('taskId');
const sourceCol = e.dataTransfer.getData('sourceCol');
const targetCol = zone.id;
if (sourceCol !== targetCol) {
appStore.moveTask(taskId, sourceCol, targetCol);
}
});
});
// Initial Load
UI.renderTasks(appStore.state, (id, col) => appStore.deleteTask(id, col));