]> git repositories - QuestLog.git/commitdiff
added a task search feature
authorbochard <mail@tenkyuu.dev>
Wed, 11 Jun 2025 12:34:59 +0000 (20:34 +0800)
committerbochard <mail@bochard.net>
Thu, 17 Jul 2025 11:41:16 +0000 (19:41 +0800)
TODO.TXT
includes/dashboard.php
js/search.js [new file with mode: 0644]
js/tasks.js

index 76f2474ac6ba2839cb4bd77ed3c43e8598be885f..a34c85eca7b0c53a312e2dbc6fd9b4ea6cb01eda 100644 (file)
--- a/TODO.TXT
+++ b/TODO.TXT
@@ -2,6 +2,5 @@
 -add a session timer when user logged in
 -don't give direct access to paths esp. when usr. is not logged in or that path must not be accessible
 -add a short animation loading progress bar when user did some actions to a task
--create 'task sorting' feature
--create 'task search' feature
+-create 'task sorting' feature (not now, maybe when im not lazy to change a lot of code)
 -when popup is open, the main window will be unaccessible
\ No newline at end of file
index 453db9479c62ed101411a0803727d6506911bc53..01ab04a100b79b57225c797c85bc786f391e88b1 100644 (file)
       <div>
         <div>
           <input type="search" id="search" placeholder="Search task...">
-          <select class="rpgui-dropdown" name="sort" id="sort">
+          <!-- <select class="rpgui-dropdown" name="sort" id="sort">
             <option value="all" selected>All</option>
             <option value="incomplete">Incomplete</option>
             <option value="complete">Complete</option>
-          </select>
+          </select> -->
         </div>
         
         <!-- action buttons for tasks -->
       </div>
     </main>
   </div>
-
+  
+  <script src="./js/search.js"></script>
   <script src="./js/tasks.js"></script>
 </body>
 </html>
\ No newline at end of file
diff --git a/js/search.js b/js/search.js
new file mode 100644 (file)
index 0000000..f6c2c7c
--- /dev/null
@@ -0,0 +1,14 @@
+function searchFilter(query){
+  const taskItems = document.querySelectorAll('.task-item');
+
+  taskItems.forEach(function(taskItem){
+    const label = taskItem.querySelector('.task-label');
+    const text = label ? label.textContent.toLowerCase() : '';
+    taskItem.style.display = text.includes(query) ? 'block' : 'none';
+  });
+}
+
+document.getElementById('search').addEventListener('input', function(){
+  query = this.value.trim().toLowerCase();
+  searchFilter(query);
+});
\ No newline at end of file
index 927d2d395caa3a111a5c5a6b3de68bd12db04358..f90529cb98410ad514b41091661c367723f24df9 100644 (file)
@@ -15,9 +15,10 @@ function loadTasks(){
     if(Array.isArray(data) && data.length > 0){
       data.forEach(function(task){
         const div = document.createElement('div');
+        div.classList.add('task-item');
         div.innerHTML = `
           <input class="rpgui-checkbox" type="checkbox" id="${task.task_id}">
-          <label for="${task.task_id}">${task.task}</label>
+          <label for="${task.task_id}" class="task-label">${task.task}</label>
         `;
 
         taskBody.appendChild(div);
@@ -109,6 +110,7 @@ function addTask(){
     console.log('Message:', data.message);
     setTimeout(function(){
     loadTasks();
+    removeSearchInput();
     }, 500);
     setDisabledAttributesOnDeleteBtn();
     setDisabledAttributesOnEditBtn();
@@ -147,6 +149,7 @@ function editTask(){
     console.log(data);
     setTimeout(function(){
     loadTasks();
+    removeSearchInput();
     }, 500);
     setDisabledAttributesOnEditBtn();
     popupEditTaskClose();
@@ -174,6 +177,7 @@ function deleteTask(){
     console.log('Message:', data.message);
     setTimeout(function(){
     loadTasks();
+    removeSearchInput();
     }, 500);
     setDisabledAttributesOnDeleteBtn();
   })
@@ -223,6 +227,10 @@ function popupEditTaskClose(){
   popupWindow.style.visibility = 'hidden';
 }
 
+function removeSearchInput(){
+  document.getElementById('search').value = '';
+}
+
 
 // event listeners
 document.getElementById('new-task-popup-open').addEventListener('click', function(){