Skip to content

Commit

Permalink
Adding all option
Browse files Browse the repository at this point in the history
  • Loading branch information
leizzle committed Aug 25, 2024
1 parent 5d2b9d5 commit 518a55d
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@
}
}

async function fetchAllWords(files) {
try {
const allWords = await Promise.all(files.map(file => fetchWords(file)));
return allWords.flat();
} catch (error) {
console.error("Failed to fetch all words:", error);
return [];
}
}

function populateWordBankOptions(category) {
const wordBankSelect = document.getElementById('wordBank');
wordBankSelect.innerHTML = '';
Expand All @@ -160,6 +170,11 @@
option.textContent = file.replace('Words_', '').replace('.txt', '');
wordBankSelect.appendChild(option);
});

const allOption = document.createElement('option');
allOption.value = "All";
allOption.textContent = "All";
wordBankSelect.appendChild(allOption);
}

document.getElementById('category').addEventListener('change', function () {
Expand All @@ -174,8 +189,16 @@
const interval = parseFloat(document.getElementById('interval').value);
const randomize = document.getElementById('randomize').checked;

console.log(`Fetching words from: ${wordBank}`);
currentWordBank = await fetchWords(wordBank);
if (wordBank === "All") {
const selectedCategory = document.getElementById('category').value;
const files = categories[selectedCategory].map(file => `${categoriesPath}/${selectedCategory}/${file}`);
console.log(`Fetching all words from category: ${selectedCategory}`);
currentWordBank = await fetchAllWords(files);
} else {
console.log(`Fetching words from: ${wordBank}`);
currentWordBank = await fetchWords(wordBank);
}

if (currentWordBank.length === 0) {
console.error("Word bank is empty, cannot start animation.");
return;
Expand Down

0 comments on commit 518a55d

Please sign in to comment.