From bd08e24f1f7de0d33ca28ddf23c037caba0a9504 Mon Sep 17 00:00:00 2001 From: sharma-shray Date: Tue, 5 Mar 2024 14:08:22 +0200 Subject: [PATCH 1/2] fix --- resources/js/main.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/resources/js/main.js b/resources/js/main.js index 61e71c3..2336b43 100644 --- a/resources/js/main.js +++ b/resources/js/main.js @@ -25,15 +25,19 @@ document.getElementById('item').addEventListener('keydown', function (e) { addItem(value); } }); - -function addItem (value) { - addItemToDOM(value); - document.getElementById('item').value = ''; - - data.todo.push(value); - dataObjectUpdated(); +function addItem(value) { + value = value.trim(); + + // Check if the trimmed value is not empty + if (value !== '') { + addItemToDOM(value); + document.getElementById('item').value = ''; + data.todo.push(value); + dataObjectUpdated(); + } } + function renderTodoList() { if (!data.todo.length && !data.completed.length) return; From a053194ef8664d6b1a273fe146a3bfc440f86d81 Mon Sep 17 00:00:00 2001 From: sharma-shray Date: Sun, 10 Mar 2024 16:23:13 +0200 Subject: [PATCH 2/2] time tracker --- resources/js/main.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/resources/js/main.js b/resources/js/main.js index 2336b43..06714c9 100644 --- a/resources/js/main.js +++ b/resources/js/main.js @@ -15,16 +15,42 @@ renderTodoList(); document.getElementById('add').addEventListener('click', function() { var value = document.getElementById('item').value; if (value) { - addItem(value); + addItem(value + addCompleteFullDate()); } }); document.getElementById('item').addEventListener('keydown', function (e) { - var value = this.value; + var value = this.value + addCompleteFullDate(); if ((e.code === 'Enter' || e.code === 'NumpadEnter') && value) { addItem(value); } }); + + +// ===== < YYYY-MM-DD > ====== +function addCompleteFullDate() { + var currentDate = new Date(); + + var year = currentDate.getFullYear(); + var month = currentDate.getMonth() + 1; + var day = currentDate.getDate(); + + var formattedDate = ' [' + year + '-' + month.toString().padStart(2, '0') + '-' + day.toString().padStart(2, '0') + ']'; + + console.log(formattedDate); + return formattedDate; +} + +// ===== < TIME ONLY > ====== +function addCompleteTimeDate(){ + var currentDate = new Date(); + var hours = currentDate.getHours(); + var minutes = currentDate.getMinutes(); + + var formattedTime = ' [' +hours.toString().padStart(2, '0') + ':' + minutes.toString().padStart(2, '0') + ']'; + return formattedTime; +} + function addItem(value) { value = value.trim();