fix: ensure processing of locally returned json data

This commit is contained in:
Rim 2025-04-17 10:02:06 -04:00
parent 92df420819
commit 9674c195d1
2 changed files with 15 additions and 10 deletions

View File

@ -1,5 +1,6 @@
window.appState = {
currentData: null,
originalData: null, // Store original unprocessed data
outputFormat: 'json',
tutorialDismissed: false,
};
@ -255,6 +256,8 @@ async function fetchData(endpoint, requestData) {
} else if (data.status === 'error') {
window.uiAPI.displayError(data.message || 'An error occurred');
} else {
// Store both original and current data
window.appState.originalData = structuredClone(data);
window.appState.currentData = data;
window.uiAPI.displayResults(data);
}

View File

@ -13,13 +13,18 @@ function displayResults(data) {
const replaceKeys = document.getElementById('replaceKeysOption').checked;
let displayData = data;
// Use the original data stored in appState for processing
if (convertTime || replaceKeys) {
const timezone = document.getElementById('timezoneSelect').value;
// Use the original unprocessed data for processing
const sourceData = window.appState.originalData || data;
displayData = window.backendAPI.processTimestamps(
structuredClone(data),
structuredClone(sourceData),
timezone
); // Use structured clone API instead of JSON.parse/stringify
// displayData = window.backendAPI.processTimestamps(JSON.parse(JSON.stringify(data)), timezone);
);
} else if (window.appState.originalData) {
// If no processing is selected, use original data
displayData = structuredClone(window.appState.originalData);
}
// Format the data
@ -313,10 +318,8 @@ function setupProcessingOptions() {
.getElementById('sanitizeOption')
.addEventListener('change', function () {
if (window.appState.currentData) {
// Call window.appState
// Re-fetch with new options
document.querySelector('.tab.active').getAttribute('data-tab');
triggerActiveTabButton();
// Process current data without re-fetching
displayResults(window.appState.currentData);
}
});
@ -324,9 +327,8 @@ function setupProcessingOptions() {
.getElementById('replaceKeysOption')
.addEventListener('change', function () {
if (window.appState.currentData) {
// Re-fetch with new options
document.querySelector('.tab.active').getAttribute('data-tab');
triggerActiveTabButton();
// Process current data without re-fetching
displayResults(window.appState.currentData);
}
});
}