console.log("entered script"); document.addEventListener('DOMContentLoaded', function () { const questionTypeElement = document.getElementById('question_type'); console.log("dom content loaded!"); if (questionTypeElement) { questionTypeElement.addEventListener('change', function () { const optionsSection = document.getElementById('options-section'); const selectedType = this.value; if (selectedType === 'multiple_choice' || selectedType === 'single_choice' || selectedType === 'dropdown') { optionsSection.style.display = 'block'; } else { optionsSection.style.display = 'none'; } }); } document.querySelectorAll('input[id^="other_"]').forEach(el => { const id = el.id.split('_')[1]; const otherTextElement = document.getElementById(`other_text_${id}`); if (otherTextElement) { el.addEventListener('change', function () { otherTextElement.style.display = this.checked ? 'block' : 'none'; }); } }); document.querySelectorAll('input[id^="radio_other_"]').forEach(el => { const id = el.id.split('_')[2]; const radioOtherTextElement = document.getElementById(`radio_other_text_${id}`); if (radioOtherTextElement) { el.addEventListener('change', function () { radioOtherTextElement.style.display = this.checked ? 'block' : 'none'; }); } }); }); document.addEventListener('DOMContentLoaded', function () { const tagsInput = document.getElementById('classes-input'); const matchesContainer = document.getElementById('matches-container'); let classes = []; // Stores the classes entered by the user let fetchedPeople = []; // Stores the people returned from the server function addClass(classname) { const container = document.getElementById('classes-container'); const classElement = document.createElement('span'); classElement.classList.add('tag'); classElement.textContent = classname; const closeIcon = document.createElement('span'); closeIcon.classList.add('close'); closeIcon.textContent = 'x'; closeIcon.addEventListener('click', function () { container.removeChild(classElement); classes = classes.filter(c => c !== classname); fetchMatchingPeople(); // Fetch updated matches when a class is removed }); classElement.appendChild(closeIcon); container.appendChild(classElement); } function fetchMatchingPeople() { if (classes.length === 0) { matchesContainer.innerHTML = '
No one has a similar class yet!
'; return; } fetch("/fetch-matches", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ classes: classes }) }) .then(response => { if (!response.ok) { throw new Error("Network response was not OK"); } return response.json(); }) .then(data => { // Handle null or empty data if (!data || data.length === 0) { matchesContainer.innerHTML = 'No one has that class yet!
'; return; } fetchedPeople = data; // Store the fetched people matchesContainer.innerHTML = ''; // Clear the matches container renderPeople(fetchedPeople, classes); // Render matches }) .catch(error => { console.error("Error fetching matches:", error); matchesContainer.innerHTML = 'No one has that class yet!
'; // Fallback message in case of any error }); } function renderPeople(people, filterClasses = []) { matchesContainer.innerHTML = ''; // Clear current people list people.forEach(person => { const personDiv = document.createElement('div'); personDiv.classList.add('person'); // Render all classes: shared ones in bold, others in gray let classesHtml = person.classes.map(classname => { // Check if the classname is in the currently selected filters if (filterClasses.includes(classname.trim())) { // Shared classes: bold return `${classname}`; } else { // Non-shared classes: gray out return `${classname}`; } }).join(', '); // Display the person's name, email, and full class list personDiv.innerHTML = `${person.name}