From dafe79b3c66f64fa362c6a7e2f4784a751d9b411 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Mon, 23 Mar 2026 18:23:24 -0400 Subject: [PATCH] ui(idaa): keep required asterisk inline with label text (embed in inline flex) --- .../ae_idaa_comp__event_obj_id_edit.svelte | 131 +++++------------- 1 file changed, 37 insertions(+), 94 deletions(-) diff --git a/src/routes/idaa/(idaa)/recovery_meetings/ae_idaa_comp__event_obj_id_edit.svelte b/src/routes/idaa/(idaa)/recovery_meetings/ae_idaa_comp__event_obj_id_edit.svelte index 35bfacf0..ae0118ec 100644 --- a/src/routes/idaa/(idaa)/recovery_meetings/ae_idaa_comp__event_obj_id_edit.svelte +++ b/src/routes/idaa/(idaa)/recovery_meetings/ae_idaa_comp__event_obj_id_edit.svelte @@ -39,6 +39,8 @@ } from '$lib/stores/ae_idaa_stores'; import { events_func } from '$lib/ae_events/ae_events_functions'; import AE_Comp_Editor_TipTap from '$lib/elements/element_editor_tiptap.svelte'; + import { liveQuery } from 'dexie'; + import { db_lookups } from '$lib/ae_core/db_lookups'; if (!$idaa_slct.event_obj) { $idaa_slct.event_obj = {}; @@ -185,92 +187,25 @@ console.log(`Event Object started: ${$idaa_slct.event_obj}`); } - // Load timezone lookup list (cached in $ae_loc, refreshed ~20% of the time) - let lu_time_zone_list = localStorage.getItem('lu_time_zone_list') - ? JSON.parse(localStorage.getItem('lu_time_zone_list') ?? '') - : []; - if ( - $ae_loc.lu_time_zone_list && - $ae_loc.lu_time_zone_list.length > 0 && - Math.random() < 0.8 - ) { - console.log('Already have time zone list!', $ae_loc.lu_time_zone_list); - } else { - core_func - .load_ae_obj_li__time_zone({ - api_cfg: $ae_api, - only_priority: true, - log_lvl: log_lvl - }) - .then(function (result) { - if (result) { - $ae_loc.lu_time_zone_list = result; - } else { - $ae_loc.lu_time_zone_list = []; - } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); - }); - } - - // Load country lookup list (cached in localStorage, refreshed ~20% of the time) - let lu_country_list = $state( - localStorage.getItem('lu_country_list') - ? JSON.parse(localStorage.getItem('lu_country_list') ?? '') - : [] + // Lookup lists — reactive IDB queries (SWR via db_lookups + liveQuery) + // Data persists in IndexedDB with a 24h TTL; onMount triggers a background + // refresh if IDB is empty or stale. No localStorage or $ae_loc involved. + const lq__lu_country = liveQuery(() => + db_lookups.lu_country.orderBy('english_short_name').toArray() ); - - // Load country subdivision lookup list (states/provinces, cached in localStorage) - let lu_country_subdivision_list = $state( - localStorage.getItem('lu_country_subdivision_list') - ? JSON.parse(localStorage.getItem('lu_country_subdivision_list') ?? '') - : [] + const lq__lu_country_subdivision = liveQuery(() => + db_lookups.lu_country_subdivision.orderBy('name').toArray() + ); + const lq__lu_time_zone = liveQuery(() => + db_lookups.lu_time_zone.orderBy('name').toArray() ); onMount(() => { - // These reads of $state runes must be inside a closure (onMount) to avoid - // Svelte's state_referenced_locally warning — the values are valid at mount. - if (lu_country_list && lu_country_list.length > 50 && Math.random() < 0.8) { - console.log(`Already have country list! ${lu_country_list.length}`); - } else { - core_func - .load_ae_obj_li__country({ api_cfg: $ae_api, log_lvl: log_lvl }) - .then(function (result) { - if (result) { - lu_country_list = result; - localStorage.setItem('lu_country_list', JSON.stringify(result)); - } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); - }); - } - - if ( - lu_country_subdivision_list && - lu_country_subdivision_list.length > 50 && - Math.random() < 0.8 - ) { - console.log( - `Already have country subdivision list! ${lu_country_subdivision_list.length}` - ); - } else { - core_func - .load_ae_obj_li__country_subdivision({ api_cfg: $ae_api, log_lvl: log_lvl }) - .then(function (result) { - if (result) { - lu_country_subdivision_list = result; - localStorage.setItem( - 'lu_country_subdivision_list', - JSON.stringify(result) - ); - } - }) - .catch(function (error: any) { - console.log('No results returned or failed.', error); - }); - } + // Trigger background IDB refresh for all three lookup lists if stale/empty. + // liveQuery subscribers above will react automatically when IDB is written. + core_func.load_ae_obj_li__country({ api_cfg: $ae_api, log_lvl }); + core_func.load_ae_obj_li__country_subdivision({ api_cfg: $ae_api, log_lvl }); + core_func.load_ae_obj_li__time_zone({ api_cfg: $ae_api, log_lvl }); }); $effect(() => { @@ -334,7 +269,7 @@ address['country_subdivision_code'] = event_meeting_fd.address_country_subdivision_code; let country_subdivision_data = ae_util.get_obj_li_w_match_prop({ - obj_li: lu_country_subdivision_list, + obj_li: $lq__lu_country_subdivision ?? [], property: 'code', value: event_meeting_fd.address_country_subdivision_code }); @@ -345,7 +280,7 @@ address['country_alpha_2_code'] = event_meeting_fd.address_country_alpha_2_code; let country_data = ae_util.get_obj_li_w_match_prop({ - obj_li: lu_country_list, + obj_li: $lq__lu_country ?? [], property: 'alpha_2_code', value: event_meeting_fd.address_country_alpha_2_code }); @@ -798,8 +733,10 @@ Copy and paste link: ${ ${ ${ {#if $idaa_sess.recovery_meetings.attend_platform === 'Zoom' && $idaa_slct.event_obj.attend_json?.zoom}