Things are working better with the version changes.

This commit is contained in:
Scott Idem
2025-04-25 16:03:16 -04:00
parent 15ee3da76d
commit f1dc6bd3dc
2 changed files with 125 additions and 30 deletions

View File

@@ -51,9 +51,10 @@ let ver = '2025-04-18_1335'; // KEEP: 2025-04-18_1335
let ver_idb = '2025-04-18_1100'; // Not used
// *** BEGIN *** Longer-term app data. This should be stored to local storage.
export let ae_app_local_data_struct: key_val = {
last_idb_reload: null,
ver: ver, // '2025-04-18_1100',
const ae_app_local_data_defaults: key_val = {
last_page_reload: null,
// last_idb_reload: null,
ver: ver, // ver, // '2025-04-18_1100',
ver_idb: ver_idb, // '2025-04-18_1100',
name: 'Aether - App Hub (SvelteKit 2.x Svelte 4.x)',
theme: 'light',
@@ -238,27 +239,59 @@ export let ae_app_local_data_struct: key_val = {
submit_status: null, // 'saving', 'created', 'updated'
},
'testing': {},
// testing: {},
},
test: true,
}
// console.log(`AE Stores - App Local Storage Data:`, ae_app_local_data_struct);
if (!ae_app_local_data_struct.ver1) {
console.log(`AE Stores - App Local Storage Data:`, ae_app_local_data_struct);
// testing: true,
// ver_testing: true,
}
// let ae_app_local_data_struct: key_val = {
// ...ae_app_local_data_defaults,
// };
// // {
// // // ...ae_app_local_data_defaults,
// // };
// // console.log(`AE Stores - App Local Storage Data:`, ae_app_local_data_struct);
// if (!ae_app_local_data_defaults?.ver_testing) {
// console.log(`TEST: AE Stores - ver_testing missing:`, ae_app_local_data_defaults);
// // ae_app_local_data_struct = {
// // ...ae_app_local_data_defaults,
// // ...ae_app_local_data_struct,
// // };
// } else {
// console.log(`TEST: AE Stores - ver_testing found`);
// }
// if (ae_app_local_data_struct?.ver !== ae_app_local_data_defaults?.ver) {
// console.log(`TEST: AE Stores - ver not match:`, ae_app_local_data_struct);
// ae_app_local_data_struct = {
// ...ae_app_local_data_defaults,
// };
// } else {
// console.log(`TEST: AE Stores - ver match: ${ae_app_local_data_struct.ver} === ${ae_app_local_data_defaults.ver}`);
// }
// if (!ae_app_local_data_struct?.app_cfg) {
// console.log(`TEST: AE Stores - app_cfg missing:`, ae_app_local_data_struct);
// ae_app_local_data_struct = {
// ...ae_app_local_data_defaults,
// ...ae_app_local_data_struct,
// };
// }
// This works, but does not uses local storage:
// export let ae_loc = writable(ae_app_local_data_struct);
// This works and uses local storage:
export let ae_loc: Writable<key_val> = localStorageStore('ae_loc', ae_app_local_data_struct);
export let ae_loc: Writable<key_val> = localStorageStore('ae_loc', ae_app_local_data_defaults);
// console.log(`AE Stores - App Local Storage Data:`, get(ae_loc));
// *** BEGIN *** Temporary app data. This should be stored to session storage.
export let ae_app_session_data_struct: key_val = {
ver: ver, // '2025-04-18_1100',
let ae_app_session_data_defaults: key_val = {
// ver: '2025-04-18_1335', // ver, // '2025-04-18_1100',
ver: ver,
ver_idb: ver_idb,
log_lvl: 0,
@@ -333,8 +366,8 @@ export let ae_app_session_data_struct: key_val = {
test: true,
};
// console.log(`AE Stores - App Session Storage Data:`, ae_app_session_data_struct);
export let ae_sess = writable(ae_app_session_data_struct);
// console.log(`AE Stores - App Session Storage Data:`, ae_app_session_data_defaults);
export let ae_sess = writable(ae_app_session_data_defaults);
// *** BEGIN *** Temporary API data. This should be stored to session storage.

View File

@@ -118,6 +118,21 @@ if (log_lvl > 1) {
// $ae_loc.app_cfg.show_element__menu = false;
// }
// if (!$ae_loc?.ver_testing) {
// console.log(`TEST: AE Stores - ver_testing missing:`, $ae_loc);
// // ae_app_local_data_struct = {
// // ...$ae_loc,
// // ...ae_app_local_data_struct,
// // };
// // $ae_loc.ver_testing = true; // test
// } else {
// console.log(`TEST: AE Stores - ver_testing found`);
// // $ae_loc.ver_testing = false; // test 2
// }
// // This should only be temporary. || !$ae_loc?.person || !$ae_loc?.user
// if (!$ae_loc) {
// console.log('No ae_loc. Reloading page...');
@@ -171,9 +186,13 @@ if (log_lvl > 1) {
// $ae_loc.app_cfg.show_element__menu = false;
// }
// IDB caches - Check if the last reload timestamp for $ae_loc.last_idb_reload is no more than 15 minutes ago.
let default_idb_reload_time = 120 * 60 * 1000; // 15 minutes?
let trusted_idb_reload_time = 4 * 60 * 60 * 1000; // 4 hours or 120 minutes?
// localStorage caches - Check if the last refresh timestamp for $ae_loc.last_refresh is no more than 48 hours ago.
let default_refresh_time = 48 * 60 * 60 * 1000; // 48 hours or 2880 minutes? 48 * 60 *
let trusted_refresh_time = 168 * 60 * 60 * 1000; // 1 week or 10080 minutes?
// IDB caches - Check if the last refresh timestamp for $ae_loc.last_cache_refresh is no more than 15 minutes ago.
let default_idb_refresh_time = 120 * 60 * 1000; // 15 minutes?
let trusted_idb_refresh_time = 4 * 60 * 60 * 1000; // 4 hours or 120 minutes?
// There should almost always be an event_id set.
if ($ae_loc?.site_cfg_json?.slct__event_id) {
@@ -248,22 +267,22 @@ if (browser) {
console.log('No ae_loc. Reloading page...');
// window.location.reload();
} else if ($ae_loc && $ae_sess && ($ae_loc.ver != $ae_sess.ver)) {
console.log('New version of the ae_loc (core local storage) available!!!');
console.log('TEST: New version of the ae_loc (core local storage) available!!!');
console.log(`$ae_loc.ver: ${$ae_loc.ver} != $ae_sess.ver: ${$ae_sess.ver}`);
// alert('New version available!!!');
// WARNING: The page should still manually be reloaded.
// $ae_loc.ver = $ae_sess.ver;
// console.log('Clearing localStorage...');
// $ae_loc = null;
// $ae_loc = {};
// localStorage.removeItem('ae_loc');
// localStorage.removeItem('ae_idaa_loc');
// localStorage.removeItem('ae_journals_loc');
// localStorage.removeItem('ae_events_loc');
localStorage.clear();
// WARNING: The page should still manually be reloaded.
// sessionStorage.removeItem('ae_sess');
// sessionStorage.removeItem('events_sess');
// console.log('Clearing sessionStorage...');
@@ -273,6 +292,7 @@ if (browser) {
// goto(data.route.id, {replaceState: true, invalidateAll: true});
// } catch (e) {
// console.log('Error going to root page:', e);
// goto('/', {replaceState: true, invalidateAll: true});
// }
// Go to root if not already there. Do this in case things have significantly changed, including routes. We need them to manually click the Reload and Clear Cache button.
@@ -280,6 +300,8 @@ if (browser) {
// if (data.route.id !== '/') {
// goto('/', {replaceState: true, invalidateAll: true});
// }
// WARNING: The page should still manually be reloaded.
} else if (!$ae_loc?.app_cfg) {
console.log('No ae_loc.app_cfg. Reloading page...?');
@@ -338,12 +360,12 @@ if (browser) {
// location.reload();
// }
if (!$ae_loc.last_idb_reload) {
if (!$ae_loc?.last_cache_refresh) {
if (log_lvl) {
console.log(`Last reload not found. Need to set!`);
}
$ae_loc.last_idb_reload = Date.now();
$ae_loc.last_cache_refresh = Date.now();
// Clear Indexed DB as well
indexedDB.deleteDatabase('ae_archives_db');
@@ -352,12 +374,52 @@ if (browser) {
indexedDB.deleteDatabase('ae_journals_db');
indexedDB.deleteDatabase('ae_notes_db');
indexedDB.deleteDatabase('ae_posts_db');
} else if ($ae_loc.last_idb_reload && $ae_loc.trusted_access && (Date.now() - $ae_loc.last_idb_reload) > trusted_idb_reload_time) {
} else if ($ae_loc?.last_cache_refresh && $ae_loc?.trusted_access && (Date.now() - $ae_loc?.last_cache_refresh) > trusted_refresh_time) {
if (log_lvl) {
console.log(`Last (trusted) reload too old: ${$ae_loc.last_idb_reload}`);
console.log(`Last (trusted) reload too old: ${$ae_loc.last_cache_refresh}`);
}
$ae_loc.last_idb_reload = Date.now();
$ae_loc.last_cache_refresh = Date.now();
// Clear Indexed DB as well
indexedDB.deleteDatabase('ae_archives_db');
indexedDB.deleteDatabase('ae_core_db');
indexedDB.deleteDatabase('ae_events_db');
indexedDB.deleteDatabase('ae_journals_db');
indexedDB.deleteDatabase('ae_notes_db');
indexedDB.deleteDatabase('ae_posts_db');
// localStorage.removeItem('ae_loc');
// localStorage.removeItem('events_loc');
localStorage.clear();
window.location.reload();
} else if ($ae_loc?.last_cache_refresh && (Date.now() - $ae_loc?.last_cache_refresh) > default_refresh_time) {
// if (log_lvl) {
console.log(`Last (default) reload too old: ${$ae_loc.last_cache_refresh}`);
// }
$ae_loc.last_cache_refresh = Date.now();
// Clear Indexed DB as well
indexedDB.deleteDatabase('ae_archives_db');
indexedDB.deleteDatabase('ae_core_db');
indexedDB.deleteDatabase('ae_events_db');
indexedDB.deleteDatabase('ae_journals_db');
indexedDB.deleteDatabase('ae_notes_db');
indexedDB.deleteDatabase('ae_posts_db');
// localStorage.removeItem('ae_loc');
// localStorage.removeItem('events_loc');
localStorage.clear();
window.location.reload();
} else if ($ae_loc?.last_cache_refresh && $ae_loc?.trusted_access && (Date.now() - $ae_loc?.last_cache_refresh) > trusted_idb_refresh_time) {
if (log_lvl) {
console.log(`Last (trusted) reload too old: ${$ae_loc.last_cache_refresh}`);
}
$ae_loc.last_cache_refresh = Date.now();
// Clear Indexed DB as well
indexedDB.deleteDatabase('ae_archives_db');
@@ -371,12 +433,12 @@ if (browser) {
// localStorage.removeItem('events_loc');
window.location.reload();
} else if ($ae_loc.last_idb_reload && (Date.now() - $ae_loc.last_idb_reload) > default_idb_reload_time) {
} else if ($ae_loc.last_cache_refresh && (Date.now() - $ae_loc.last_cache_refresh) > default_idb_refresh_time) {
if (log_lvl) {
console.log(`Last (default) reload too old: ${$ae_loc.last_idb_reload}`);
console.log(`Last (default) reload too old: ${$ae_loc.last_cache_refresh}`);
}
$ae_loc.last_idb_reload = Date.now();
$ae_loc.last_cache_refresh = Date.now();
// Clear Indexed DB as well
indexedDB.deleteDatabase('ae_archives_db');
@@ -392,7 +454,7 @@ if (browser) {
window.location.reload();
} else {
if (log_lvl > 1) {
console.log(`Last reload is recent: ${$ae_loc.last_idb_reload}`);
console.log(`Last reload is recent: ${$ae_loc.last_cache_refresh}`);
}
}