diff --git a/static/script.js b/static/script.js index 8123c42..6426e99 100644 --- a/static/script.js +++ b/static/script.js @@ -690,15 +690,15 @@ if (isIndexPage) { // Form submission and API call // ---------------------------------------------------------- - form.addEventListener("submit", function (evt) { - evt.preventDefault(); + form.addEventListener("submit", function (evt) { + evt.preventDefault(); - clearAllErrors(); + clearAllErrors(); - if (skillsTextInput.value.trim()) { - addSkill(skillsTextInput.value); - skillsTextInput.value = ""; - hideSuggestions(); + if (skillsTextInput.value.trim()) { + addSkill(skillsTextInput.value); + skillsTextInput.value = ""; + hideSuggestions(); } if (!validateForm()) return; @@ -733,24 +733,17 @@ if (isIndexPage) { if (generalErr) { generalErr.textContent = data.error; } - return; } - renderResults(data.projects || [], data.message); }) - .catch(function (err) { - + .catch(function () { setLoadingState(false); - var generalErr = document.getElementById("form-error-general"); - if (generalErr) { generalErr.textContent = - "Something went wrong. Please try again."; + "Something went wrong while fetching recommendations."; } - - console.error("API request failed:", err); }); }); }); @@ -782,7 +775,6 @@ if (isIndexPage) { // Render result cards // ---------------------------------------------------------- - main function truncate(text, maxLength) { if (!text) return ""; return text.length > maxLength ? text.slice(0, maxLength) + "..." : text; @@ -793,44 +785,9 @@ if (isIndexPage) { span.className = "project-tag project-tag--" + type; span.textContent = text; return span; - - //takes the array of projects from the api and draws them on the page as cards - //if array is empty it shows the "no results" message instead - function renderResults(projects, message) { - resultsSection.style.display = "block"; - resultsLoadingEl.style.display = "none"; - // Clear out any cards from a previous search before showing new ones - resultsGrid.innerHTML = ""; - - if (!projects || projects.length === 0) { - resultsGrid.style.display = "none"; - resultsEmptyEl.style.display = "block"; - - // Show a friendly custom message when the user selected an interest - var selectedInterest = document.getElementById("interest")?.value; - if (selectedInterest) { - emptyMessageEl.textContent = "No projects are currently available for this interest. Please check back later or try a different area."; - } else if (message) { - emptyMessageEl.textContent = message; - } else { - emptyMessageEl.textContent = "Try adjusting your skills or choosing a different interest area."; - } - - resultsSection.scrollIntoView({ behavior: "smooth" }); - return; - } - - resultsEmptyEl.style.display = "none"; - resultsGrid.style.display = "grid"; - - projects.forEach(function (project) { - resultsGrid.appendChild(buildProjectCard(project)); - }); - - resultsSection.scrollIntoView({ behavior: "smooth" }); - main } + function buildProjectCard(project) { var card = document.createElement("div"); card.className = "project-card"; @@ -1433,7 +1390,6 @@ updateRoadmapProgress(); } } - main if (scrollTopBtn) { window.addEventListener('scroll', handleScroll, { passive: true }); scrollTopBtn.addEventListener('click', function () { @@ -1447,9 +1403,3 @@ updateRoadmapProgress(); } }()); -/* Only wire up listeners if the button exists on this page */ -if (scrollTopBtn) { - window.addEventListener('scroll', handleScroll); - scrollTopBtn.addEventListener('click', scrollToTop); -} - main