generated from Uzair-Manzoor/webpack-linters-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Uzair-Manzoor/List-structure
List structure
- Loading branch information
Showing
6 changed files
with
38 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,129 +1,42 @@ | ||
import './index.css'; | ||
import { | ||
tasks, deleteTask, editTask, addTask, | ||
} from './module/taskFunctions.js'; | ||
|
||
import updateStatus from './module/statusFunctions.js'; | ||
import clearAllCompletedTasks from './module/clearTask.js'; | ||
import { dragStart, dragOver, drop } from './module/dragAndDrop.js'; | ||
|
||
const todoListContainer = document.getElementById('todoList'); | ||
const addBtn = document.getElementById('addBtn'); | ||
const clearBtn = document.querySelector('.clear-completed'); | ||
|
||
const displayTasks = () => { | ||
todoListContainer.textContent = ''; | ||
tasks.forEach((task, index) => { | ||
todoListContainer.innerHTML += ` | ||
<li class="task" draggable="true" data-index="${index}"> | ||
<div class="checkbox-container"> | ||
<input type="checkbox" name="${task.description}" ${task.completed ? 'checked' : ''}> | ||
<input type="text" value="${task.description}" readonly> | ||
</div> | ||
<i class="fas fa-ellipsis-vertical" data-index="${index}"></i> | ||
</li> | ||
`; | ||
}); | ||
|
||
const addedTasks = document.querySelectorAll('.task'); | ||
|
||
const checkboxContainers = document.querySelectorAll('.task > .checkbox-container > input[type="checkbox"]'); | ||
|
||
checkboxContainers.forEach((checkbox) => { | ||
const inputText = checkbox.nextElementSibling; | ||
let previousState = checkbox.checked; | ||
|
||
inputText.readOnly = true; | ||
|
||
checkbox.addEventListener('change', (event) => { | ||
const currentState = event.target.checked; | ||
|
||
if (currentState !== previousState) { | ||
const foundTask = tasks.find((task) => task.description === inputText.value); | ||
if (foundTask) { | ||
foundTask.completed = currentState; | ||
updateStatus(tasks.indexOf(foundTask), currentState); | ||
} | ||
} | ||
|
||
previousState = currentState; | ||
}); | ||
}); | ||
|
||
addedTasks.forEach((task, index) => { | ||
const textInput = task.querySelector('input[type="text"]'); | ||
task.addEventListener('dblclick', () => { | ||
textInput.readOnly = false; | ||
if (task.querySelector('.fa-ellipsis-vertical')) { | ||
const ellipsisIcon = task.querySelector('.fa-ellipsis-vertical'); | ||
ellipsisIcon.classList.remove('fa-ellipsis-vertical'); | ||
ellipsisIcon.classList.add('fa-trash'); | ||
ellipsisIcon.addEventListener('click', () => { | ||
deleteTask(index); | ||
displayTasks(); | ||
}); | ||
} else { | ||
const trashIcon = task.querySelector('.fa-trash'); | ||
trashIcon.classList.remove('fa-trash'); | ||
trashIcon.classList.add('fa-ellipsis-vertical'); | ||
textInput.readOnly = true; | ||
} | ||
const taskListContainer = document.getElementById('todoList'); | ||
const tasks = [ | ||
{ | ||
description: 'complete', | ||
completed: true, | ||
index: 1, | ||
}, | ||
{ | ||
description: 'To do something', | ||
completed: false, | ||
index: 2, | ||
}, | ||
{ | ||
description: 'list tasks', | ||
completed: true, | ||
index: 3, | ||
}, | ||
]; | ||
|
||
export default class DisplayTasks { | ||
static renderTasks() { | ||
tasks.sort((a, b) => a.index - b.index); | ||
taskListContainer.innerHTML = ''; | ||
tasks.forEach((task, index) => { | ||
taskListContainer.innerHTML += ` | ||
<li class="task" draggable="true" data-index="${index}"> | ||
<div class="checkbox-container"> | ||
<input type="checkbox" name="${task.description}" ${task.completed ? 'checked' : ''}> | ||
<input type="text" value="${task.description}" readonly> | ||
</div> | ||
<i class="fas fa-ellipsis-vertical" data-index="${index}"></i> | ||
</li> | ||
`; | ||
}); | ||
|
||
// Edit | ||
textInput.addEventListener('input', () => { | ||
const data = textInput.value.trim(); | ||
editTask(data, index); | ||
}); | ||
|
||
// Drag and drop | ||
task.addEventListener('dragstart', dragStart); | ||
task.addEventListener('dragover', dragOver); | ||
task.addEventListener('drop', drop); | ||
}); | ||
}; | ||
|
||
const initializeTasks = () => { | ||
document.addEventListener('DOMContentLoaded', displayTasks); | ||
}; | ||
|
||
const refreshPage = () => { | ||
localStorage.removeItem('Tasks'); | ||
window.location.reload(); | ||
}; | ||
|
||
clearBtn.addEventListener('click', () => { | ||
clearAllCompletedTasks(); | ||
displayTasks(); | ||
}); | ||
|
||
initializeTasks(); | ||
addBtn.addEventListener('click', () => { | ||
const inputField = document.getElementById('input-task'); | ||
const taskDescription = inputField.value.trim(); | ||
|
||
// Check if the task description is not empty | ||
if (taskDescription !== '') { | ||
addTask(taskDescription); | ||
inputField.value = ''; | ||
displayTasks(); | ||
} | ||
}); | ||
document.addEventListener('keypress', (e) => { | ||
if (e.key === 'Enter') { | ||
const inputField = document.getElementById('input-task'); | ||
const taskDescription = inputField.value.trim(); | ||
|
||
// Check if the task description is not empty | ||
if (taskDescription !== '') { | ||
addTask(taskDescription); | ||
inputField.value = ''; | ||
displayTasks(); | ||
} | ||
} | ||
}); | ||
document.querySelector('.fa-arrows-rotate').addEventListener('click', refreshPage); | ||
// Add event listener to update the display | ||
document.addEventListener('updateDisplay', displayTasks); | ||
} | ||
|
||
export {}; | ||
document.addEventListener('DOMContentLoaded', () => { | ||
DisplayTasks.renderTasks(); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.