JSON import pagination

This commit is contained in:
erew123 authored and GitHub committed 2024-01-08 01:13:36 +00:00
1 parent 13b2eb5fe3
commit 70d385133d
1 file changed
+30 -6
@@ -1510,7 +1510,7 @@
input.type = 'file';
input.accept = '.json';
input.onchange = (e) => {
input.onchange = async (e) => {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
@@ -1518,13 +1518,11 @@
reader.onload = (e) => {
try {
const jsonData = JSON.parse(e.target.result);
console.log('JSON data imported:', jsonData);
// Update the ttsList with the imported data
ttsList = jsonData;
// Refresh the on-screen list
updateUIList(); // This function updates the UI with the contents of ttsList
currentPage = 1; // Reset to the first page
updateUIList();
updatePaginationControls(); // Update pagination controls
} catch (error) {
console.error('Error parsing JSON:', error);
}
@@ -1533,8 +1531,34 @@
};
input.click();
}
function updatePaginationControls() {
const lastPage = Math.ceil(ttsList.length / itemsPerPage);
const pageIndicator = document.getElementById('pageIndicator');
if (pageIndicator) {
pageIndicator.textContent = `Page ${currentPage} of ${lastPage}`;
}
const prevPageButton = document.getElementById('prevPage');
if (prevPageButton) {
prevPageButton.disabled = (currentPage === 1);
}
const nextPageButton = document.getElementById('nextPage');
if (nextPageButton) {
nextPageButton.disabled = (currentPage === lastPage);
}
// Similar updates for any additional pagination controls if you have them
// ...
}
//////////////////////////////
//////// Other Things ////////
//////////////////////////////