@@ -262,6 +262,7 @@ export function saveApiResponseToStorage(eid, apiData) {
262262
263263 try {
264264 // Store the API response data as a JSON string using a single key
265+ // Store the raw API data directly without any wrapper
265266 localStorage . setItem ( 'apiData' , JSON . stringify ( apiData ) ) ;
266267 console . log ( `Saved API data to localStorage` ) ;
267268 } catch ( e ) {
@@ -276,10 +277,11 @@ export function saveApiResponseToStorage(eid, apiData) {
276277 */
277278export function getSavedApiResponse ( eid ) {
278279 try {
279- const savedData = localStorage . getItem ( 'apiData' ) ;
280- if ( ! savedData ) return null ;
280+ const savedDataString = localStorage . getItem ( 'apiData' ) ;
281+ if ( ! savedDataString ) return null ;
281282
282- const parsedData = JSON . parse ( savedData ) ;
283+ // Parse the stored data directly - no format wrapper
284+ const parsedData = JSON . parse ( savedDataString ) ;
283285
284286 // If eid is provided, verify it matches the stored data's EID
285287 if ( eid && parsedData . eid &&
@@ -332,13 +334,39 @@ export function clearSavedEid() {
332334/**
333335 * Initialize the module and auto-load saved EID if available
334336 */
337+ /**
338+ * Refresh data in the background
339+ * @param {string } eid - The EID to refresh data for
340+ */
341+ async function refreshDataInBackground ( eid ) {
342+ if ( ! eid ) return ;
343+
344+ console . log ( `Starting background refresh for EID: ${ eid } ` ) ;
345+
346+ try {
347+ // Make a fresh API call to get updated data
348+ const result = await fetchDataFromAppsScript ( GOOGLE_APPS_SCRIPT_URL , eid , null ) ; // Pass null for statusElementId to avoid UI updates
349+
350+ if ( result . success && result . format === 'json' ) {
351+ // Process the API response and update storage
352+ processApiResponse ( result . data ) ;
353+ console . log ( `Background refresh completed for EID: ${ eid } ` ) ;
354+ } else {
355+ console . warn ( `Background refresh failed for EID: ${ eid } ` ) ;
356+ }
357+ } catch ( error ) {
358+ console . warn ( `Error during background refresh for EID: ${ eid } ` , error ) ;
359+ }
360+ }
361+
335362function initializeModule ( ) {
336363 // Run this once when the script is loaded
337364 try {
338365 // Check if we have saved API data
339366 const savedApiData = localStorage . getItem ( 'apiData' ) ;
340367 if ( savedApiData ) {
341368 try {
369+ // Parse the stored data directly - no format wrapper
342370 const apiData = JSON . parse ( savedApiData ) ;
343371
344372 // Check if the API data has an EID
@@ -364,6 +392,12 @@ function initializeModule() {
364392 memberExists : memberExists
365393 }
366394 } ) ) ;
395+
396+ // After loading data from localStorage, refresh it in the background
397+ // Use a short delay to ensure page is rendered first
398+ setTimeout ( ( ) => {
399+ refreshDataInBackground ( currentEid ) ;
400+ } , 1000 ) ;
367401 } , 0 ) ;
368402 }
369403 } catch ( parseError ) {
@@ -379,7 +413,7 @@ function initializeModule() {
379413 * Fetch data from arbitrary Apps Script URL with EID parameter
380414 * @param {string } url - The Apps Script URL to fetch from
381415 * @param {string } eid - The EID to fetch data for
382- * @param {string } [statusElementId='dataStatus'] - ID of status element to update
416+ * @param {string|null } [statusElementId='dataStatus'] - ID of status element to update, or null to skip UI updates
383417 * @returns {Promise<Object> } - Promise resolving to the response data
384418 */
385419export async function fetchDataFromAppsScript ( url , eid , statusElementId = 'dataStatus' ) {
@@ -390,8 +424,8 @@ export async function fetchDataFromAppsScript(url, eid, statusElementId = 'dataS
390424 // Get status element if ID provided
391425 const statusElement = statusElementId ? document . getElementById ( statusElementId ) : null ;
392426
393- // Update status if element exists
394- if ( statusElement ) {
427+ // Update status if element exists and statusElementId is not null
428+ if ( statusElement && statusElementId !== null ) {
395429 statusElement . textContent = 'Loading data...' ;
396430 statusElement . className = 'status-message loading' ;
397431 }
@@ -422,8 +456,8 @@ export async function fetchDataFromAppsScript(url, eid, statusElementId = 'dataS
422456 // Save API response to localStorage
423457 saveApiResponseToStorage ( eid , jsonData ) ;
424458
425- // Update status if element exists
426- if ( statusElement ) {
459+ // Update status if element exists and statusElementId is not null
460+ if ( statusElement && statusElementId !== null ) {
427461 statusElement . textContent = 'Data loaded successfully!' ;
428462 statusElement . className = 'status-message success' ;
429463 }
@@ -443,8 +477,8 @@ export async function fetchDataFromAppsScript(url, eid, statusElementId = 'dataS
443477 } catch ( error ) {
444478 console . error ( 'Error fetching data from Apps Script:' , error ) ;
445479
446- // Update status element if it exists
447- if ( statusElement ) {
480+ // Update status element if it exists and statusElementId is not null
481+ if ( statusElement && statusElementId !== null ) {
448482 statusElement . textContent = 'Error loading data. Please try again.' ;
449483 statusElement . className = 'status-message error' ;
450484 }
0 commit comments