feat: logic/html rendered

This commit is contained in:
Mike 2024-01-04 14:44:08 -05:00
parent 3305e39bf2
commit 1fc78a7879
4 changed files with 45 additions and 21 deletions

View file

@ -53,14 +53,16 @@ class todoHandler {
} }
editTodo(project, title, description, dueDate, pomodors) { editTodo(project, title) {
// TODO: implement todo method currently just a toggle for completed;
let projectIndex = this.projects.findIndex(x => x.name === project); let projectIndex = this.projects.findIndex(x => x.name === project);
let todo = this.projects[projectIndex].todos.find(t => t.title === title) let todo = this.projects[projectIndex].todos.find(t => t.title === title)
if (todo){ if (todo){
if(description) todo.description = description; todo.completed = !todo.completed;
if(dueDate) todo.dueDate = dueDate; // if(description) todo.description = description;
if(pomodors) todo.pomodoros = pomodors; // if(dueDate) todo.dueDate = dueDate;
// if(pomodors) todo.pomodoros = pomodors;
} }
} }

View file

@ -1,4 +1,4 @@
import { getActiveProject, setActiveProject, updateDisplay } from ".."; import { getActiveProject, setActiveProject, updateDisplay, getTodoHandler } from "..";
import { save } from "./storage"; import { save } from "./storage";
function todoTableComponent(todos) { function todoTableComponent(todos) {
@ -62,6 +62,7 @@ function createTableCheckBox(content) {
checkbox.type = 'checkbox'; checkbox.type = 'checkbox';
checkbox.classList.add('todo-checkbox'); checkbox.classList.add('todo-checkbox');
checkbox.checked = content; checkbox.checked = content;
return checkbox; return checkbox;
} }
@ -81,6 +82,7 @@ function createTableTodoDeleteBtn() {
function createTableRow(_todo) { function createTableRow(_todo) {
const tr = document.createElement('tr'); const tr = document.createElement('tr');
tr.classList.add('todo-row'); tr.classList.add('todo-row');
tr.dataset.todoId = _todo.title; tr.dataset.todoId = _todo.title;
let checkbox = createTableCheckBox(_todo.completed); let checkbox = createTableCheckBox(_todo.completed);
@ -88,16 +90,23 @@ function createTableRow(_todo) {
createTableCell(checkbox), createTableCell(checkbox),
createTableCell(_todo.title), createTableCell(_todo.title),
createTableCell(_todo.description), createTableCell(_todo.description),
createTableCell(_todo.dueDate), createTableCell(_todo.dueDate.toString()),
createTableCell(createTableTodoDeleteBtn()) createTableCell(createTableTodoDeleteBtn())
// createTableCell(_todo.pomodoros) // createTableCell(_todo.pomodoros)
] ]
cells.forEach(cell => tr.appendChild(cell)); cells.forEach(cell => tr.appendChild(cell));
if (_todo.completed) {
tr.classList.add('completed');
} else {
tr.classList.remove('completed');
}
return tr; return tr;
} }
function addTodo(todoHandler) { function addTodo(todoHandler) {
const activeProject = getActiveProject(); const activeProject = getActiveProject();
const button = document.querySelector('.add-todo-btn'); const button = document.querySelector('.add-todo-btn');
@ -118,7 +127,8 @@ function addTodo(todoHandler) {
let newTodo = handleTodoInput(input.childNodes); let newTodo = handleTodoInput(input.childNodes);
let title = newTodo[0]; let title = newTodo[0];
let description = newTodo[1]; let description = newTodo[1];
let date = Date(newTodo[2]); let date = new Date(newTodo[2]);
console.log(date);
todoHandler.addTodo(activeProject, title, description, date, 0); todoHandler.addTodo(activeProject, title, description, date, 0);
div.classList.remove('todo-add-active'); div.classList.remove('todo-add-active');
updateDisplay(); updateDisplay();
@ -146,6 +156,20 @@ function deleteTodo(todoHandler) {
} }
function handleCompletedTodo(todoHandler) {
const activeProject = getActiveProject();
const checkbox = document.querySelectorAll('.todo-checkbox');
checkbox.forEach(c => {
c.addEventListener('click', e => {
const title = e.target.parentNode.parentNode.dataset.todoId;
todoHandler.editTodo(activeProject, title);
save(todoHandler.getEverything());
updateDisplay();
});
});
}
function projectComponent() { function projectComponent() {
const div = document.createElement('div'); const div = document.createElement('div');
const input = document.createElement('input'); const input = document.createElement('input');
@ -290,6 +314,6 @@ export {
addProject, addProject,
deleteProject, deleteProject,
addTodo, addTodo,
deleteTodo deleteTodo,
handleCompletedTodo
}; };

View file

@ -7,15 +7,17 @@ import {
todoTableComponent, todoTableComponent,
getTodoFromActiveProject, getTodoFromActiveProject,
addTodoComponent, addTodoComponent,
handleCompletedTodo
} from "./components/todoComponent"; } from "./components/todoComponent";
import { navbar } from "./components/navbar"; import { navbar } from "./components/navbar";
import { todoHandler as todoManager } from "./components/todo";
import { save, load } from "./components/storage"; import { save, load } from "./components/storage";
import './style.css'; import './style.css';
import { add } from "date-fns"; import { todoHandler as todoManager } from "./components/todo";
// import { add } from "date-fns";
const data = load(); const data = load();
let todos = data ? new todoManager(JSON.parse(data)) : new todoManager(); let todos;
todos = data ? new todoManager(JSON.parse(data)) : new todoManager();
let activeProject = 'default'; let activeProject = 'default';
@ -67,8 +69,10 @@ function updateDisplay() {
deleteTodo(todos); deleteTodo(todos);
addProject(todos); addProject(todos);
deleteProject(todos); deleteProject(todos);
handleCompletedTodo(todos);
} }
fontAwesome(); fontAwesome();
website(); website();
save(todos.getEverything()); save(todos.getEverything());

View file

@ -162,12 +162,6 @@ input[type="checkbox"] {
width: initial; width: initial;
} }
/* .todo-buttons { */ .completed {
/* display: flex; */ text-decoration: line-through 3px;
/* gap: 10px; */ }
/* } */
/**/
/* .todo-buttons button { */
/* width: 100%; */
/* margin: 10px 0; */
/* } */