Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 10 additions & 60 deletions static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
});
});
Expand Down Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -1433,7 +1390,6 @@ updateRoadmapProgress();
}
}

main
if (scrollTopBtn) {
window.addEventListener('scroll', handleScroll, { passive: true });
scrollTopBtn.addEventListener('click', function () {
Expand All @@ -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
Loading