From dce48c619a302b9a5953cc1ff9ca84e37b258f9d Mon Sep 17 00:00:00 2001 From: franklin004 Date: Mon, 24 Oct 2022 16:39:46 +0200 Subject: [PATCH] after josephfeedback I tried to refactor and fix the storing function but havent finished --- src/.DS_Store | Bin 6148 -> 6148 bytes src/index.ts | 47 ++++++++++++++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/.DS_Store b/src/.DS_Store index da24fbd81134c1146bde1902dbf505149e3f696d..69aa8ddb350e86a86d1963159915df4ed26b231a 100644 GIT binary patch delta 301 zcmZoMXfc=|#>B)qu~2NHo+2a1#DLw4A22d9a!lr7G^kH1FD^*R$xmWnU^tOfkds+l zVqkEck%^gwm5rT)laqs!moqjvBfmVjB(bEl*eS6n8pI1oEXhcMvP1IobKva6q_E7? z@^}Fe=lr~q#LT?ZBCzJnlvJRSnDETJl>Bn1{L;LXVz4>Ep%59cP4NQa)zy}k7CH(B zwK@vbh9)KkItmu%=C!q)9O9~mww?*Ol~vU>wRJOqjs*fnMhMNo52az$%*jTK#gqLR x*?G!>i}G^v^U^`8H!or=WZBHl!OsBB`mu~2NHo+2aL#DLw5Y?FDI3?@r4XKtR!oX4{H0rMBe&Fmcf96)88 aFEW2;p3E;|$-w{wj0_A+n*&6)FarR)s1hFl diff --git a/src/index.ts b/src/index.ts index ef72098..33af214 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,7 +28,7 @@ form?.addEventListener("submit", (e) => { tasks.push(newTask); //하나아이템 type then push, then it's uploaded(stored). <-wrote it after line 13 addListItem(newTask); - input.value = ""; //clear the input type part, as you already made one to do item + input.value = ""; //clear the input type part, as you already made one to-do-item }); function addListItem(task: Task) { @@ -62,11 +62,12 @@ function addListItem(task: Task) { }); editbtn.addEventListener("click", function () { label?.focus(); - changeTask(item); + changeTask(item); //joseph 24th Oct 2022 }); } function saveTasks() { + const taskJSON = localStorage.getItem("TASKS") || "[]"; //hmm... 24 Oct localStorage.setItem("TASKS", JSON.stringify(tasks)); } @@ -76,19 +77,31 @@ function loadTasks(): Task[] { return JSON.parse(taskJSON); // if it's not null, return to the taskJSON. As : Task[] is written after func loadTasks(), it will specifically parse the array. Without it, it will parse anything } -function changeTask(item) { - var changer = document.createElement("input"); - changer.className = "changer"; - var text = item.firstChild.innerHTML; - changer.value = text.replace('',""); - item.append(changer); - var button = document.createElement("button"); - button.innerHTML = "X" - item.append(button); - button.addEventListener("click", function (){ - item.firstChild.innerHTML = ''+ changer.value; - changer.remove(); - button.remove(); - - }); +function changeTask(item: any) { + var changer = document.createElement("input"); //joseph created another input field next to the item (,which is clicked and to be modified.) + //I wanted to directly modify the item in the listed label, without making anothe input next to it. + changer.className = "changer"; + var writtenLabel = item.firstChild.innerHTML; + changer.value = writtenLabel.replace('', ""); + item.append(changer); + var button = document.createElement("button"); + button.innerHTML = "modify"; + item.append(button); + button.addEventListener("click", function () { + item.firstChild.innerHTML = '' + changer.value; + changer.remove(); + button.remove(); + }); //joseph 24th Oct 2022 + console.log(item.firstChild); + console.log(item); } + +// function deleteTask(item: any) { +// const deletebtn = document.createElement("button"); +// deletebtn.classList.add("deletebtn"); + +// item.append(deletebtn); +// deletebtn.addEventListener("click", function () { +// item.parentNode?.removeChild(item); +// }); +//} Wanting to refactor, I attempted to separate the deleteTask function here but failed. 24 Oct