diff --git a/js/app.js b/js/app.js index 5dc8d87..7f53b13 100644 --- a/js/app.js +++ b/js/app.js @@ -1,5 +1,5 @@ const STORAGE_SAVE_KEY = "launchdesk-v1-items"; -const STORAGE_LOAD_KEY = "launchdesk-items-v1"; // Intentional bug: this key should match STORAGE_SAVE_KEY. +const STORAGE_LOAD_KEY = "launchdesk-v1-items"; const demoChecks = [ { @@ -91,7 +91,7 @@ const activityLog = document.getElementById("activityLog"); let checks = loadChecks(); let currentView = checks; -form.addEventListener("submit", (event) => handleAddChek(event)); // Intentional bug: misspelled function name. +form.addEventListener("submit", handleAddCheck); searchInput.addEventListener("input", applyFilters); statusFilter.addEventListener("change", applyFilters); priorityFilter.addEventListener("change", applyFilters); @@ -103,6 +103,7 @@ exportButton.addEventListener("click", exportCsv); renderApp(); logActivity("Demo data loaded. Start by testing the checklist workflows."); +// Loads the checks from localStorage or uses demo checks if no saved data is found. function loadChecks() { const saved = localStorage.getItem(STORAGE_LOAD_KEY); @@ -111,17 +112,20 @@ function loadChecks() { } try { - return JSON.parse(saved); + const parsed = JSON.parse(saved); + return Array.isArray(parsed) ? parsed : [...demoChecks] } catch (error) { console.warn("Could not parse saved launch checks.", error); return [...demoChecks]; } } +// Saves the current list of checks to localStorage. function saveChecks() { localStorage.setItem(STORAGE_SAVE_KEY, JSON.stringify(checks)); } +// Handles adding a new check to the list. function handleAddCheck(event) { event.preventDefault(); @@ -132,8 +136,7 @@ function handleAddCheck(event) { const owner = ownerInput.value.trim() || "Unassigned"; const dueDate = dueDateInput.value || new Date().toISOString().slice(0, 10); - if (!title && !category) { - // Intentional bug: validation should stop when either required field is missing. + if (!title || !category) { formMessage.textContent = "Please enter a check title and choose a category."; return; @@ -158,18 +161,28 @@ function handleAddCheck(event) { logActivity(`Added "${newCheck.title}" to the launch checklist.`); } +// Applies filters to the checks list based on search term and status/priority filters. function applyFilters() { const searchTerm = searchInput.value.trim().toLowerCase(); const selectedStatus = statusFilter.value; const selectedPriority = priorityFilter.value; - let filtered = checks.filter((check) => - check.owner.toLowerCase().includes(searchTerm), - ); // Intentional bug: search should include title, category, priority, status, and owner. + let filtered = checks.filter((check) => { + if (!searchTerm) return true; + + const term = searchTerm; + return ( + check.title?.toLowerCase().includes(term) || + check.category?.toLowerCase().includes(term) || + check.priority?.toLowerCase().includes(term) || + check.status?.toLowerCase().includes(term) || + check.owner?.toLowerCase().includes(term) + ); + }); if (selectedStatus !== "All") { - filtered = filtered.filter((check) => check.priority === selectedStatus); - } // Intentional bug: status filter compares against priority. + filtered = filtered.filter((check) => check.status === selectedStatus); + } if (selectedPriority !== "All") { filtered = filtered.filter((check) => check.priority === selectedPriority); @@ -191,7 +204,7 @@ function renderRows(list) { const rows = list.map((check) => { const priorityClass = `priority-${check.priority.toLowerCase()}`; - const statusClass = `status-${check.status.toLowerCase()}`; // Intentional bug: "In Progress" needs a slug class. + const statusClass = `status-${check.status.toLowerCase().replace(" ", "-")}`; return ` @@ -210,12 +223,12 @@ function renderRows(list) {