The Main Functions that make E-Task cool!

function eTaskSetUp() {
PerpareLocalStorage();
let tasks = getData();
//SetLocalStorage(tasks);
ListTasks(tasks);
}


function loadTasks() {
let tasks = [];
tasks = getData();
ListTask(tasks);
}                          


function saveTask() {

let tasks = GetLocalStorage();
let task = {};

let currentDatetime = new Date()
let formattedDate = displayDate(currentDatetime);

task["id"] = GenerateID();
task["create"] = formattedDate;
task["complete"] = "Pending";
task["title"] = document.getElementById("newTaskTitle").value;
task["dueDate"] = displayDate(document.getElementById("newTaskDueDate").value);


tasks.push(task);
SetLocalStorage(tasks);
ListTasks(tasks);

}


function saveTask() {

let tasks = GetLocalStorage();
let task = {};

let currentDatetime = new Date()
let formattedDate = displayDate(currentDatetime);

task["id"] = GenerateID();
task["create"] = formattedDate;
task["complete"] = "Pending";
task["title"] = document.getElementById("newTaskTitle").value;
task["dueDate"] = displayDate(document.getElementById("newTaskDueDate").value);


tasks.push(task);
SetLocalStorage(tasks);
ListTasks(tasks);

}


function ListTasks(allCurrentTask) {

const template = document.getElementById("Data-template");
const resultsBody = document.getElementById("resultsBody");

//clear the table
resultsBody.innerHTML = "";


for (let i = 0; i < allCurrentTask.length; i++) {
const dataRow = document.importNode(template.content, true);

//dataRow.getElementById("taskStatus").textContent = allCurrentTask[i].complete;
dataRow.getElementById("taskStatus").textContent = allCurrentTask[i].complete;
dataRow.getElementById("id").textContent = allCurrentTask[i].id;
dataRow.getElementById("title").textContent = allCurrentTask[i].title;
dataRow.getElementById("create").textContent = allCurrentTask[i].create;
dataRow.getElementById("dueDate").textContent = allCurrentTask[i].dueDate;

resultsBody.appendChild(dataRow);
}
}


function completeTask(element) {
// will refactor using a function
//let taskId = getId();

let taskId = $(element).parent().siblings(".d-none").text();

let tasks = GetLocalStorage();

let task = tasks.find(t => t.id == taskId);
task.complete = "Done";

SetLocalStorage(tasks);
//alert("I'm Here");
ListTasks(GetLocalStorage());
}