feat: add sorting by dates

This commit is contained in:
Mike 2024-01-04 17:41:00 -05:00
parent 1fc78a7879
commit 83112555b7
3 changed files with 13 additions and 2 deletions

View file

@ -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

View file

@ -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');

View file

@ -30,6 +30,7 @@ button {
font-size: 1rem;
}
input[type="checkbox"] {
/* appearance: none; */
/* For iOS < 15 to remove gradient background */