feat(offline): implement Dexie fallbacks and fix type stability in Events module
- Offline Resilience: Added local Dexie fallbacks to load_ae_obj_id__* and load_ae_obj_li__* functions for Events, Sessions, Locations, Exhibits, and Badges. - Type Safety: Standardized ae_Event and ae_EventSession interfaces in ae_types.ts; resolved Promise assignment errors in load functions (+page.ts). - Bug Fixes: Corrected duplication in ae_events__event_location.ts and ae_events__event_badge_template.ts; fixed missing try_cache parameters. - UI Stability: Fixed Dexie LiveQuery subscription pattern in bulk print view and ensured proper property access in layout load functions.
This commit is contained in:
@@ -38,45 +38,57 @@ export async function load_ae_obj_id__event({
|
||||
console.log(`*** load_ae_obj_id__event() *** event_id=${event_id}`);
|
||||
}
|
||||
|
||||
ae_promises.load__event_obj = await api
|
||||
.get_ae_obj_v3({
|
||||
try {
|
||||
const event_obj_get_result = await api.get_ae_obj_v3({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'event',
|
||||
obj_id: event_id,
|
||||
view,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(async function (event_obj_get_result) {
|
||||
if (event_obj_get_result) {
|
||||
if (try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__event_props({
|
||||
obj_li: [event_obj_get_result],
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_events,
|
||||
table_name: 'event',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
}
|
||||
return event_obj_get_result;
|
||||
} else {
|
||||
console.log('No results returned.');
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error: any) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
|
||||
if (event_obj_get_result) {
|
||||
if (try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__event_props({
|
||||
obj_li: [event_obj_get_result],
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_events,
|
||||
table_name: 'event',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
}
|
||||
ae_promises.load__event_obj = event_obj_get_result;
|
||||
} else {
|
||||
console.log('No results returned from API.');
|
||||
if (try_cache) {
|
||||
if (log_lvl) console.log('Attempting to load from local cache...');
|
||||
ae_promises.load__event_obj = await db_events.event.get(event_id);
|
||||
} else {
|
||||
ae_promises.load__event_obj = null;
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.log('API request failed.', error);
|
||||
if (try_cache) {
|
||||
if (log_lvl) console.log('Attempting to load from local cache after error...');
|
||||
ae_promises.load__event_obj = await db_events.event.get(event_id);
|
||||
} else {
|
||||
ae_promises.load__event_obj = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (ae_promises.load__event_obj) {
|
||||
const current_event_id = ae_promises.load__event_obj.event_id || ae_promises.load__event_obj.id;
|
||||
|
||||
if (inc_device_li) {
|
||||
ae_promises.load__event_obj.event_device_obj_li = await load_ae_obj_li__event_device({
|
||||
api_cfg,
|
||||
for_obj_type: 'event',
|
||||
for_obj_id: event_id,
|
||||
for_obj_id: current_event_id,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
@@ -84,7 +96,7 @@ export async function load_ae_obj_id__event({
|
||||
ae_promises.load__event_obj.event_location_obj_li = await load_ae_obj_li__event_location({
|
||||
api_cfg,
|
||||
for_obj_type: 'event',
|
||||
for_obj_id: event_id,
|
||||
for_obj_id: current_event_id,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
@@ -92,7 +104,7 @@ export async function load_ae_obj_id__event({
|
||||
ae_promises.load__event_obj.event_session_obj_li = await load_ae_obj_li__event_session({
|
||||
api_cfg,
|
||||
for_obj_type: 'event',
|
||||
for_obj_id: event_id,
|
||||
for_obj_id: current_event_id,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
@@ -100,7 +112,7 @@ export async function load_ae_obj_id__event({
|
||||
ae_promises.load__event_obj.event_badge_template_obj_li =
|
||||
await load_ae_obj_li__event_badge_template({
|
||||
api_cfg,
|
||||
event_id,
|
||||
event_id: current_event_id,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
@@ -118,6 +130,7 @@ export async function load_ae_obj_li__event({
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
view = 'default',
|
||||
inc_session_li = false,
|
||||
limit = 99,
|
||||
offset = 0,
|
||||
order_by_li = { start_datetime: 'DESC' } as const,
|
||||
@@ -131,6 +144,7 @@ export async function load_ae_obj_li__event({
|
||||
enabled?: 'enabled' | 'all' | 'not_enabled';
|
||||
hidden?: 'hidden' | 'all' | 'not_hidden';
|
||||
view?: string;
|
||||
inc_session_li?: boolean;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
order_by_li?: Record<string, 'ASC' | 'DESC'> | Record<string, 'ASC' | 'DESC'>[];
|
||||
@@ -176,7 +190,8 @@ export async function load_ae_obj_li__event({
|
||||
});
|
||||
}
|
||||
|
||||
ae_promises.load__event_obj_li = await promise.then(async function (event_obj_li_get_result) {
|
||||
try {
|
||||
const event_obj_li_get_result = await promise;
|
||||
if (event_obj_li_get_result) {
|
||||
let filtered_results = event_obj_li_get_result;
|
||||
|
||||
@@ -198,11 +213,41 @@ export async function load_ae_obj_li__event({
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
}
|
||||
return filtered_results;
|
||||
ae_promises.load__event_obj_li = filtered_results;
|
||||
} else {
|
||||
return [];
|
||||
console.log('No results returned from API.');
|
||||
if (try_cache) {
|
||||
if (log_lvl) console.log('Attempting to load from local cache...');
|
||||
ae_promises.load__event_obj_li = await db_events.event
|
||||
.where('account_id').equals(for_obj_id)
|
||||
.toArray();
|
||||
} else {
|
||||
ae_promises.load__event_obj_li = [];
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.log('API request failed.', error);
|
||||
if (try_cache) {
|
||||
if (log_lvl) console.log('Attempting to load from local cache after error...');
|
||||
ae_promises.load__event_obj_li = await db_events.event
|
||||
.where('account_id').equals(for_obj_id)
|
||||
.toArray();
|
||||
} else {
|
||||
ae_promises.load__event_obj_li = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (inc_session_li && ae_promises.load__event_obj_li) {
|
||||
for (const event_obj of ae_promises.load__event_obj_li) {
|
||||
const current_event_id = event_obj.event_id || event_obj.id;
|
||||
event_obj.event_session_obj_li = await load_ae_obj_li__event_session({
|
||||
api_cfg,
|
||||
for_obj_type: 'event',
|
||||
for_obj_id: current_event_id,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return ae_promises.load__event_obj_li;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user