breed usage no longer has any duplicates

This commit is contained in:
Chris kerr 2024-02-24 14:30:47 -05:00
parent ac2f700ae1
commit d6565acc7f

View File

@ -1,32 +1,39 @@
function updateBreedingUsage() { function updateBreedingUsage() {
// Get the selected monster from the dropdown // Get the selected monster from the dropdown
var selectedMonster = document.getElementById("monsterDropdown").value; var selectedMonster = document.getElementById("monsterDropdown").value;
// Fetch data from the API // Fetch data from the API
fetch(`/api/breeding/usage/${selectedMonster}`) fetch(`/api/breeding/usage/${selectedMonster}`)
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
// Update the HTML with the list of offspring monsters // Update the HTML with the list of offspring monsters
renderOffspringList(data.used_in); renderOffspringList(data.used_in);
}) })
.catch(error => console.error('Error fetching data:', error)); .catch(error => console.error('Error fetching data:', error));
} }
function renderOffspringList(usageData) { function renderOffspringList(usageData) {
var offspringContainer = document.getElementById("offspringContainer"); var offspringContainer = document.getElementById("offspringContainer");
// Clear previous HTML content // Clear previous HTML content
offspringContainer.innerHTML = "<h2 class='text-xl font-bold'>Used to Breed: </h2><ul class='list-disc'>"; offspringContainer.innerHTML = "<h2 class='text-xl font-bold'>Used to Breed: </h2><ul class='list-disc'>";
// Create and append HTML for each offspring // Create a Set to store unique offspring monsters
usageData.forEach(item => { var uniqueOffspringSet = new Set();
var offspringHTML = `<li class='font-bold marker:text-slate-400 text-purple-300'>
${item.offspring} // Add unique offspring to the Set
</li> usageData.forEach(item => {
`; uniqueOffspringSet.add(item.offspring);
offspringContainer.innerHTML += offspringHTML; });
});
// Create and append HTML for each unique offspring
// Close the unordered list uniqueOffspringSet.forEach(offspring => {
offspringContainer.innerHTML += "</ul>"; var offspringHTML = `<li class='font-bold marker:text-slate-400 text-purple-300'>
${offspring}
</li>`;
offspringContainer.innerHTML += offspringHTML;
});
// Close the unordered list
offspringContainer.innerHTML += "</ul>";
} }