From 9674c195d149d687487a212a2b89de9e20ca9101 Mon Sep 17 00:00:00 2001 From: Rim Date: Thu, 17 Apr 2025 10:02:06 -0400 Subject: [PATCH] fix: ensure processing of locally returned json data --- src/js/backend.js | 3 +++ src/js/frontend.js | 22 ++++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/js/backend.js b/src/js/backend.js index ecc1fa5..d88726e 100644 --- a/src/js/backend.js +++ b/src/js/backend.js @@ -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); } diff --git a/src/js/frontend.js b/src/js/frontend.js index b8ab6f4..1481237 100644 --- a/src/js/frontend.js +++ b/src/js/frontend.js @@ -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); } }); }