From 83112555b7da1966a61bed1fafeac1a290f7379f Mon Sep 17 00:00:00 2001 From: Mike Smith <89040888+smiggiddy@users.noreply.github.com> Date: Thu, 4 Jan 2024 17:41:00 -0500 Subject: [PATCH] feat: add sorting by dates --- todo/src/components/todo.js | 12 +++++++++++- todo/src/components/todoComponent.js | 2 +- todo/src/style.css | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/todo/src/components/todo.js b/todo/src/components/todo.js index 895f2f2..c960afa 100644 --- a/todo/src/components/todo.js +++ b/todo/src/components/todo.js @@ -1,8 +1,12 @@ +import { format, compareAsc } from "date-fns"; + function createTodo(title, description, dueDate, pomodoros) { + dueDate = dueDate.replaceAll('-', '/'); + const newTodo = { title: title, description: description, - dueDate: dueDate, + dueDate: format(new Date(dueDate), 'MM/dd/yyyy'), pomodoros: pomodoros, completed: false } @@ -46,6 +50,12 @@ class todoHandler { if (!_titleExists) { this.projects[index].todos.push(new createTodo(title, description, dueDate, pomodoros)); + this.projects[index].todos.sort((a,b) => { + + return compareAsc(new Date(a.dueDate), new Date(b.dueDate)); + }); + console.log(this.projects[index]); + //(itemA, itemB) => {return itemA.dueDate - itemB.dueDate}) } else { alert('unable to create duplicate note'); return diff --git a/todo/src/components/todoComponent.js b/todo/src/components/todoComponent.js index 3a0c292..c0f221c 100644 --- a/todo/src/components/todoComponent.js +++ b/todo/src/components/todoComponent.js @@ -127,7 +127,7 @@ function addTodo(todoHandler) { let newTodo = handleTodoInput(input.childNodes); let title = newTodo[0]; let description = newTodo[1]; - let date = new Date(newTodo[2]); + let date = newTodo[2]; // new Date(newTodo[2]); console.log(date); todoHandler.addTodo(activeProject, title, description, date, 0); div.classList.remove('todo-add-active'); diff --git a/todo/src/style.css b/todo/src/style.css index a18fd80..5e999d8 100644 --- a/todo/src/style.css +++ b/todo/src/style.css @@ -30,6 +30,7 @@ button { font-size: 1rem; } + input[type="checkbox"] { /* appearance: none; */ /* For iOS < 15 to remove gradient background */