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.type = 'file';
input.accept = '.json'; input.accept = '.json';
input.onchange = (e) => { input.onchange = async (e) => {
const file = e.target.files[0]; const file = e.target.files[0];
if (file) { if (file) {
const reader = new FileReader(); const reader = new FileReader();
@@ -1518,13 +1518,11 @@
reader.onload = (e) => { reader.onload = (e) => {
try { try {
const jsonData = JSON.parse(e.target.result); const jsonData = JSON.parse(e.target.result);
console.log('JSON data imported:', jsonData);
// Update the ttsList with the imported data
ttsList = jsonData; ttsList = jsonData;
currentPage = 1; // Reset to the first page
// Refresh the on-screen list updateUIList();
updateUIList(); // This function updates the UI with the contents of ttsList updatePaginationControls(); // Update pagination controls
} catch (error) { } catch (error) {
console.error('Error parsing JSON:', error); console.error('Error parsing JSON:', error);
} }
@@ -1535,6 +1533,32 @@
input.click(); 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 //////// //////// Other Things ////////
////////////////////////////// //////////////////////////////