From: Amazingca Date: Thu, 7 May 2026 17:54:10 +0000 (-0600) Subject: Merge archived.js and home.js into todos.js X-Git-Url: http://git.amazingca.dev/?a=commitdiff_plain;h=1d64f74eb2b55236c569618e6a1e1b1a068dc65a;p=autumn%2Ftodo Merge archived.js and home.js into todos.js --- diff --git a/app/archived.html b/app/archived.html index ed69325..de97658 100644 --- a/app/archived.html +++ b/app/archived.html @@ -4,7 +4,7 @@ todo - +
diff --git a/app/index.html b/app/index.html index 06d115f..38a5577 100644 --- a/app/index.html +++ b/app/index.html @@ -4,7 +4,7 @@ todo - +
diff --git a/app/index.js b/app/todos.js similarity index 70% rename from app/index.js rename to app/todos.js index 9a1eaa8..efe7fcb 100644 --- a/app/index.js +++ b/app/todos.js @@ -46,7 +46,13 @@ if (window.location.hash.length > 0) { } } -document.getElementById("createTodo").addEventListener("click", () => { +const archivedElement = document.getElementById("archived"); +const todosElement = document.getElementById("todos"); +const completedElement = document.getElementById("todos-completed"); + +const page = (archivedElement) ? "archived" : "home"; + +if (page == "home") document.getElementById("createTodo").addEventListener("click", () => { document.documentElement.scrollTop = 0; @@ -62,47 +68,42 @@ document.getElementById("createTodo").addEventListener("click", () => { backupData(); }); -const todosCompleted = document.getElementById("todos-completed"); - const doShowCompleted = (backup = false) => { if (theme.showCompleted) { - todosCompleted.classList.remove("hidden"); + completedElement.classList.remove("hidden"); } else { - todosCompleted.classList.add("hidden"); + completedElement.classList.add("hidden"); } if (backup) backupData(); } -doShowCompleted() +if (page == "home") doShowCompleted(); -document.getElementById("showCompleted").addEventListener("click", () => { +if (page == "home") document.getElementById("showCompleted").addEventListener("click", () => { theme.showCompleted = !theme.showCompleted; doShowCompleted(true); resizeTextHeights(); }); -const todosElement = document.getElementById("todos"); -const completedElement = document.getElementById("todos-completed"); - -const todoElement = (item, index, isCompleted) => { +const todoElement = (item, index, isCompleted = false) => { - let completedText = (isCompleted) ? "completed" : "uncompleted"; + let targetText = (isCompleted) ? "completed" : (page == "archived") ? "archived" : "uncompleted"; return ` - -
+ +
${(isCompleted) ? '' : ''}
- +
-

archive

-

delete

+

${(page == 'home') ? 'archive' : 'restore'}

+

delete

@@ -122,7 +123,41 @@ const applyListeners = () => { resizeTextHeights(); - for (var i = 0; i < todos.uncompleted.length; i++) { + if (page == "archived") for (var i = 0; i < archived.length; i++) { + + let index = i; // fixes scoping issue - what a disaster + + document.getElementById(`todo-archived-${i}-description`).addEventListener("input", (event) => { + + event.target.style.height = "0"; + event.target.style.height = event.target.scrollHeight + "px"; + + archived[index].description = event.target.value; + + backupData(); + }); + + document.getElementById(`todo-archived-${i}-restore`).addEventListener("click", (event) => { + + todos.uncompleted = [ + archived[index] + ].concat(todos.uncompleted); + archived.splice(index, 1); + + hydrateTodos(); + backupData(); + }); + + document.getElementById(`todo-archived-${i}-delete`).addEventListener("click", (event) => { + + archived.splice(index, 1); + + hydrateTodos(); + backupData(); + }); + } + + if (page == "home") for (var i = 0; i < todos.uncompleted.length; i++) { let index = i; // fixes scoping issue - what a disaster @@ -167,7 +202,7 @@ const applyListeners = () => { }); } - for (var i = 0; i < todos.completed.length; i++) { + if (page == "home") for (var i = 0; i < todos.completed.length; i++) { let index = i; // fixes scoping issue - what a disaster @@ -210,6 +245,14 @@ const applyListeners = () => { } } +const hydrateArchived = () => { + + if (archived.length > 0) archivedElement.innerHTML = archived + .map((x, index) => todoElement(x, index)) + .join(""); + else archivedElement.innerHTML = "

no archived todos for now…

"; +}; + const hydrateUncompleted = () => { todosElement.innerHTML = todos.uncompleted @@ -226,14 +269,19 @@ const hydrateCompleted = () => { const hydrateTodos = () => { - hydrateUncompleted(); - hydrateCompleted(); + if (page == "archived") hydrateArchived(); + if (page == "home") { + + hydrateUncompleted(); + hydrateCompleted(); + } applyListeners(); }; hydrateTodos(); + const updateTheme = (force = false) => { if (theme.colorScheme != "default") {