-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI.js
More file actions
45 lines (38 loc) · 1.73 KB
/
UI.js
File metadata and controls
45 lines (38 loc) · 1.73 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
// UI.js
export class UI {
static renderTasks(state, onDelete) {
const columns = ['todo', 'doing', 'done'];
columns.forEach(col => {
const container = document.getElementById(col);
container.innerHTML = ''; // Clear the column
state[col].forEach(task => {
const taskEl = document.createElement('div');
taskEl.className = 'task-card';
taskEl.draggable = true;
taskEl.id = task.id;
taskEl.innerHTML = `
<p>${task.content}</p>
<div style="display: flex; justify-content: space-between; align-items: center;">
<span>${task.timestamp}</span>
<button class="del-btn" data-id="${task.id}" data-col="${col}"
style="background:none; color:#ff4d4d; padding:0; font-size:12px;">Delete</button>
</div>
`;
// Drag start logic
taskEl.addEventListener('dragstart', (e) => {
taskEl.classList.add('dragging');
e.dataTransfer.setData('taskId', task.id);
e.dataTransfer.setData('sourceCol', col);
});
taskEl.addEventListener('dragend', () => {
taskEl.classList.remove('dragging');
});
// Delete logic
taskEl.querySelector('.del-btn').addEventListener('click', (e) => {
onDelete(e.target.dataset.id, e.target.dataset.col);
});
container.appendChild(taskEl);
});
});
}
}