This is a mostly working state again. Some files were backed up to ~/tmp/Aether_UI_UX_app. Things are slowly being merged back in. Not easy.
This commit is contained in:
@@ -48,14 +48,19 @@
|
||||
// import { api } from '$lib/api';
|
||||
import { ae_loc, ae_sess, ae_api, slct, slct_trigger } from '$lib/stores/ae_stores';
|
||||
import { events_loc, events_slct } from '$lib/stores/ae_events_stores';
|
||||
import type { LayoutData } from './$types';
|
||||
// import type { key_val } from '$lib/ae_stores';
|
||||
|
||||
import MyClipboard from '$lib/app_components/e_app_clipboard.svelte';
|
||||
import E_app_debug_menu from '$lib/app_components/e_app_debug_menu.svelte';
|
||||
import E_app_sys_menu from '$lib/app_components/e_app_sys_menu.svelte';
|
||||
// import Element_access_type from '$lib/element_access_type.svelte';
|
||||
// import Element_app_cfg from '$lib/element_app_cfg.svelte';
|
||||
// import Element_sign_in_out from '$lib/element_sign_in_out.svelte';
|
||||
|
||||
// import Element_data_store from '$lib/element_data_store_v2.svelte';
|
||||
|
||||
interface Props {
|
||||
data: LayoutData;
|
||||
data: any;
|
||||
children?: import('svelte').Snippet;
|
||||
}
|
||||
|
||||
@@ -65,36 +70,51 @@
|
||||
console.log(`ae_root +layout.svelte data:`, data);
|
||||
}
|
||||
|
||||
// Define ae_acct as a derived rune so it's reactive and available globally in the component
|
||||
let ae_acct = $derived(data.account_id ? (data as any)[data.account_id] : null);
|
||||
// Quickly save the data passed from the parent(s) to the Svelte stores, localStorage, and other. This should catch anything that is a child of this layout.svelte file.
|
||||
$slct.account_id = data.account_id;
|
||||
if (log_lvl) {
|
||||
console.log(`*ae_root +layout.svelte* $slct.account_id = ${$slct.account_id}`);
|
||||
}
|
||||
let ae_acct = data[$slct.account_id];
|
||||
|
||||
// Use an effect to sync data to stores whenever it changes
|
||||
import { untrack } from 'svelte';
|
||||
$effect(() => {
|
||||
const account_id = data.account_id;
|
||||
const acct_data = ae_acct;
|
||||
|
||||
if (account_id) {
|
||||
untrack(() => {
|
||||
if ($slct.account_id !== account_id) {
|
||||
$slct.account_id = account_id;
|
||||
}
|
||||
|
||||
if (acct_data) {
|
||||
// Merging stores with untracked reads to prevent loops
|
||||
if (acct_data.api) {
|
||||
$ae_api = { ...untrack(() => $ae_api), ...acct_data.api };
|
||||
}
|
||||
if (acct_data.loc) {
|
||||
$ae_loc = { ...untrack(() => $ae_loc), ...acct_data.loc };
|
||||
}
|
||||
if (acct_data.slct) {
|
||||
$slct = { ...untrack(() => $slct), ...acct_data.slct };
|
||||
}
|
||||
}
|
||||
});
|
||||
if (ae_acct) {
|
||||
$ae_api = {
|
||||
...$ae_api,
|
||||
...(ae_acct.api || {})
|
||||
};
|
||||
if (log_lvl > 1) {
|
||||
console.log(`$ae_api = `, $ae_api);
|
||||
}
|
||||
});
|
||||
|
||||
// FORCE UPDATE: If the incoming data is a valid site (not a fallback ghost),
|
||||
// we must ensure the ae_loc store is updated regardless of what's in localStorage.
|
||||
if (ae_acct.loc?.account_id && ae_acct.loc.account_id !== 'ghost') {
|
||||
$ae_loc = {
|
||||
...$ae_loc,
|
||||
...(ae_acct.loc || {})
|
||||
};
|
||||
} else {
|
||||
// If it IS a ghost, we still update it to show the correct fallback message
|
||||
$ae_loc = {
|
||||
...$ae_loc,
|
||||
...(ae_acct.loc || {})
|
||||
};
|
||||
}
|
||||
|
||||
if (log_lvl > 1) {
|
||||
console.log(`$ae_loc = `, $ae_loc);
|
||||
}
|
||||
|
||||
$slct = {
|
||||
...$slct,
|
||||
...(ae_acct.slct || {})
|
||||
};
|
||||
if (log_lvl > 1) {
|
||||
console.log(`$slct = `, $slct);
|
||||
}
|
||||
} else {
|
||||
console.warn('ae_root +layout.svelte: ae_acct not found for account_id:', $slct.account_id);
|
||||
}
|
||||
|
||||
let flag_clear_idb: boolean = $state(false);
|
||||
let flag_clear_local: boolean = $state(false);
|
||||
@@ -689,16 +709,13 @@
|
||||
|
||||
// Sync JWT from local storage to API config for V3 endpoints
|
||||
$effect(() => {
|
||||
const loc_jwt = $ae_loc.jwt;
|
||||
untrack(() => {
|
||||
if ($ae_api.jwt !== loc_jwt) {
|
||||
if (log_lvl) console.log('ROOT: Syncing JWT to API config');
|
||||
$ae_api = {
|
||||
...$ae_api,
|
||||
jwt: loc_jwt
|
||||
};
|
||||
}
|
||||
});
|
||||
if ($ae_api.jwt !== $ae_loc.jwt) {
|
||||
if (log_lvl) console.log('ROOT: Syncing JWT to API config');
|
||||
$ae_api = {
|
||||
...$ae_api,
|
||||
jwt: $ae_loc.jwt
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
let is_hydrating = $state(true);
|
||||
@@ -826,7 +843,7 @@
|
||||
{/if}
|
||||
</span>
|
||||
<span class="hidden md:inline">Viewing cached data. Changes may not be saved.</span>
|
||||
|
||||
|
||||
<div class="flex flex-row gap-2">
|
||||
<button
|
||||
class="btn btn-sm variant-filled-white text-orange-600 font-bold"
|
||||
@@ -835,7 +852,7 @@
|
||||
<RefreshCw class="inline-block mr-1 size-4" />
|
||||
Retry
|
||||
</button>
|
||||
|
||||
|
||||
<button
|
||||
class="btn btn-sm variant-soft-white font-bold"
|
||||
onclick={() => show_connection_details = false}
|
||||
@@ -963,7 +980,7 @@
|
||||
title="Reload and clear the page cache"
|
||||
onclick={() => {
|
||||
clear_idb();
|
||||
window.location.reload();
|
||||
window.location.reload(true);
|
||||
}}
|
||||
>
|
||||
<!-- <span class="fas fa-sync mx-1"></span> -->
|
||||
|
||||
96
src/routes/testing/data_store_v3/+page.svelte
Normal file
96
src/routes/testing/data_store_v3/+page.svelte
Normal file
@@ -0,0 +1,96 @@
|
||||
<script lang="ts">
|
||||
import AE_Element_Data_Store_V3 from '$lib/elements/element_data_store_v3_alpha.svelte';
|
||||
import { ae_loc } from '$lib/stores/ae_stores';
|
||||
import { db_core } from '$lib/ae_core/db_core';
|
||||
|
||||
let test_code_global = 'hub__site__root_page_header'; // Expected to be a global default
|
||||
let test_name_global = 'Global Header Test - hub__site__root_page_header';
|
||||
let test_code_account = 'hub__site__root_page_header';
|
||||
let test_name_account = 'Account Header Test - hub__site__root_page_header';
|
||||
let test_code_specific = 'event_launcher_main_info';
|
||||
let test_name_specific = 'Event Specific Test - event_launcher_main_info';
|
||||
let test_event_id = 'pjrcghqwert';
|
||||
|
||||
let log_lvl = 2;
|
||||
let refresh_trigger = $state(0);
|
||||
|
||||
async function clear_cache() {
|
||||
if (confirm('Are you sure you want to clear the local Data Store cache?')) {
|
||||
await db_core.data_store.clear();
|
||||
refresh_trigger++;
|
||||
alert('Cache cleared.');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="p-8 space-y-8 max-w-4xl mx-auto h-full overflow-y-auto">
|
||||
<header class="border-b border-surface-500/30 pb-4 flex justify-between items-center">
|
||||
<div>
|
||||
<h1 class="h1">Data Store V3 Test Page</h1>
|
||||
<p class="opacity-70">Testing cascading lookup: Specific → Account → Global</p>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<button class="btn variant-filled-warning" onclick={clear_cache}>
|
||||
<span class="fas fa-trash mr-2"></span> Clear Cache
|
||||
</button>
|
||||
<button class="btn variant-filled-primary" onclick={() => refresh_trigger++}>
|
||||
<span class="fas fa-sync mr-2"></span> Force Refresh
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{#key refresh_trigger}
|
||||
<section class="card p-4 space-y-4 variant-soft-primary">
|
||||
<h2 class="h3">Scenario 1: Global Default</h2>
|
||||
<p class="text-sm">Fetching code <code>{test_code_global}</code>. Should fall back to <code>account_id = NULL</code> if not found for account.</p>
|
||||
<div class="bg-surface-100-800-token p-4 rounded-lg border border-surface-500/20">
|
||||
<!-- <AE_Element_Data_Store_V3
|
||||
ds_code={test_code_global}
|
||||
ds_name={test_name_global}
|
||||
{log_lvl}
|
||||
debug={true}
|
||||
/> -->
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card p-4 space-y-4 variant-soft-secondary">
|
||||
<h2 class="h3">Scenario 2: Account Default</h2>
|
||||
<p class="text-sm">Fetching code <code>{test_code_account}</code> for Account ID: <code>{$ae_loc.account_id}</code>.</p>
|
||||
<div class="bg-surface-100-800-token p-4 rounded-lg border border-surface-500/20">
|
||||
<!-- <AE_Element_Data_Store_V3
|
||||
ds_code={test_code_account}
|
||||
ds_name={test_name_account}
|
||||
{log_lvl}
|
||||
debug={true}
|
||||
/> -->
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card p-4 space-y-4 variant-soft-tertiary">
|
||||
<h2 class="h3">Scenario 3: Specific Record (Event Override)</h2>
|
||||
<p class="text-sm">Fetching code <code>{test_code_specific}</code> linked to <code>for_type: event</code> and <code>for_id: {test_event_id}</code>.</p>
|
||||
<div class="bg-surface-100-800-token p-4 rounded-lg border border-surface-500/20">
|
||||
<!-- <AE_Element_Data_Store_V3
|
||||
ds_code={test_code_specific}
|
||||
ds_name={test_name_specific}
|
||||
for_type="event"
|
||||
for_id={test_event_id}
|
||||
{log_lvl}
|
||||
debug={true}
|
||||
/> -->
|
||||
</div>
|
||||
</section>
|
||||
{/key}
|
||||
|
||||
<section class="card p-4 space-y-4">
|
||||
<h2 class="h3">Current Context</h2>
|
||||
<div class="grid grid-cols-2 gap-4 text-xs font-mono">
|
||||
<div class="bg-surface-900 text-success-500 p-2 rounded">
|
||||
<strong>Account ID:</strong> {$ae_loc.account_id || 'NULL'}
|
||||
</div>
|
||||
<div class="bg-surface-900 text-success-500 p-2 rounded">
|
||||
<strong>Edit Mode:</strong> {$ae_loc.edit_mode}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
Reference in New Issue
Block a user