Rework of the IDAA Recovery Meetings search. Other related updates and bug fixes. Added preventDefault()

This commit is contained in:
Scott Idem
2025-07-10 15:45:48 -04:00
parent 770e48842b
commit 8bf9d488cd
8 changed files with 318 additions and 131 deletions

View File

@@ -29,7 +29,7 @@ import { events_func } from '$lib/ae_events_functions';
import Element_data_store from '$lib/element_data_store_v2.svelte';
import Comp__event_obj_qry from './ae_idaa_comp__event_obj_qry.svelte';
import Comp__event_obj_li from './ae_idaa_comp__event_obj_li.svelte';
import Comp__event_obj_li_wrapper from './ae_idaa_comp__event_obj_li_wrapper.svelte';
// import Comp__event_obj_id_edit from './ae_idaa_comp__event_obj_id_edit.svelte';
// import Comp__event_obj_id_view from './ae_idaa_comp__event_obj_id_view.svelte';
@@ -43,7 +43,7 @@ if (!event_id) {
$idaa_trig.event_id = event_id;
}
let event_id_random_li: Array<string> = $state();
let event_id_random_li: Array<string> = $state([]);
// Functions and Logic
let lq_new__event_obj_li = $derived(liveQuery(async () => {
@@ -110,36 +110,36 @@ let lq_new__event_obj_li = $derived(liveQuery(async () => {
// This (event_li trigger for IDAA) is not currently being used.
// Updated 2024-11-19
$effect(() => {
if ($idaa_trig.event_li) {
$idaa_trig.event_li = false;
// $effect(() => {
// if ($idaa_trig.event_li) {
// $idaa_trig.event_li = false;
if (log_lvl) {
console.log(`Triggered: $idaa_trig.event_li`);
}
// if (log_lvl) {
// console.log(`Triggered: $idaa_trig.event_li`);
// }
if ($idaa_loc.recovery_meetings.qry__enabled !== 'all' || $idaa_loc.recovery_meetings.qry__hidden !== 'all') {
console.log(`Deleting disabled or hidden event.`);
let results = db_events.events
.clear();
console.log(`Deleted ${results} disabled event.`);
// if ($idaa_loc.recovery_meetings.qry__enabled !== 'all' || $idaa_loc.recovery_meetings.qry__hidden !== 'all') {
// console.log(`Deleting disabled or hidden event.`);
// let results = db_events.events
// .clear();
// console.log(`Deleted ${results} disabled event.`);
}
// }
$idaa_prom.load__event_obj_li = events_func.load_ae_obj_li__event({
api_cfg: $ae_api,
for_obj_type: 'account',
for_obj_id: $idaa_slct.account_id,
qry_conference: false,
enabled: $idaa_loc.recovery_meetings.qry__enabled,
hidden: $idaa_loc.recovery_meetings.qry__hidden,
limit: $idaa_loc.recovery_meetings.qry__limit,
order_by_li: $idaa_loc.recovery_meetings.qry__order_by_li,
try_cache: true,
log_lvl: log_lvl,
});
}
});
// $idaa_prom.load__event_obj_li = events_func.load_ae_obj_li__event({
// api_cfg: $ae_api,
// for_obj_type: 'account',
// for_obj_id: $idaa_slct.account_id,
// qry_conference: false,
// enabled: $idaa_loc.recovery_meetings.qry__enabled,
// hidden: $idaa_loc.recovery_meetings.qry__hidden,
// limit: $idaa_loc.recovery_meetings.qry__limit,
// order_by_li: $idaa_loc.recovery_meetings.qry__order_by_li,
// try_cache: true,
// log_lvl: log_lvl,
// });
// }
// });
// Updated 2024-11-19
@@ -156,10 +156,10 @@ $effect(() => {
let and_physical = $idaa_loc.recovery_meetings.qry__physical;
let and_virtual = $idaa_loc.recovery_meetings.qry__virtual;
let and_type = $idaa_loc.recovery_meetings.qry__type;
let order_by_li = $idaa_loc.recovery_meetings.qry__order_by_li;
// let order_by_li = $idaa_loc.recovery_meetings.qry__order_by_li;
let search_delay = 15;
let max_tries = 5;
let try_cache = true;
// let try_cache = true;
// let params = {
// 'qry__enabled': $idaa_loc.recovery_meetings.qry__enabled ?? 'enabled',
@@ -186,7 +186,7 @@ $effect(() => {
search_delay += 50+random_delay;
}
log_lvl = 0;
log_lvl = 1;
let count = 0;
let request_loop = setInterval(() => {
@@ -200,10 +200,12 @@ $effect(() => {
}
if ($idaa_sess.recovery_meetings?.qry__status != null && $idaa_sess.recovery_meetings?.qry__status != 'done') {
let random_delay = Math.floor(Math.random() * 25);
search_delay += 25+random_delay;
console.log(`*** TEST SEARCH - $idaa_sess.recovery_meetings.qry__status == loading wait *** search_delay=${search_delay}`);
// $idaa_sess.status_qry__last_request_str = $idaa_loc.recovery_meetings.qry__fulltext_str;
} else {
console.log('*** TEST SEARCH - $idaa_sess.recovery_meetings.qry__status != loading ***');
@@ -233,31 +235,36 @@ $effect(() => {
hidden: $idaa_loc.recovery_meetings.qry__hidden,
order_by_li: $idaa_loc.recovery_meetings.qry__order_by_li,
limit: $idaa_loc.recovery_meetings.qry__limit,
try_cache: try_cache,
log_lvl: log_lvl,
})
.then(function (search_results) {
// Processing the results from the search.
$idaa_sess.recovery_meetings.qry__status = 'processing';
$idaa_slct.event_obj_li = search_results;
console.log(search_results);
if (log_lvl) {
console.log(`Found ${search_results.length} matching events.`);
console.log('TEST SEARCH - Search done. Need to pull out the id_random list for bulk load.');
}
event_id_random_li = generate_id_random_li({event_obj_li: search_results});
// $idaa_sess.recovery_meetings.qry__status = 'done';
if (log_lvl) {
console.log('TEST SEARCH - Search done. Pulling out the event_id_randoms.');
}
// if (log_lvl) {
//
// }
// console.log(`TEST search: ${$lq_kv__event_obj_li}`);
// event_id_random_li = [];
// We need to loop through the array of objects and get the event_id_random from each object a new list of event_id_randoms. Then we can use this list to get the full objects from the database.
let tmp_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
if (search_results && search_results.length) {
for (let i = 0; i < search_results.length; i++) {
tmp_li.push($idaa_slct.event_obj_li[i].event_id_random);
}
}
event_id_random_li = tmp_li;
// // We need to loop through the array of objects and get the event_id_random from each object a new list of event_id_randoms. Then we can use this list to get the full objects from the database.
// let tmp_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
// if (search_results && search_results.length) {
// for (let i = 0; i < search_results.length; i++) {
// tmp_li.push($idaa_slct.event_obj_li[i].event_id_random);
// }
// }
// event_id_random_li = tmp_li;
})
.finally(() => {
@@ -279,6 +286,48 @@ $effect(() => {
}
});
// $effect(() => {
// if ($idaa_sess.recovery_meetings.qry__status == 'done') {
// if (log_lvl) {
// console.log(`*** TEST SEARCH - $idaa_sess.recovery_meetings.qry__status == done ***`);
// }
// // We are done with the search.
// $idaa_sess.recovery_meetings.qry__status = null;
// // We need to loop through the array of objects and get the event_id_random from each object a new list of event_id_randoms. Then we can use this list to get the full objects from the database.
// let tmp_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
// if ($idaa_slct.event_obj_li && $idaa_slct.event_obj_li.length) {
// event_id_random_li = [];
// // console.log(`TEST SEARCH - Get ids:`, $idaa_slct.event_obj_li);
// for (let i = 0; i < $idaa_slct.event_obj_li.length; i++) {
// tmp_li.push($idaa_slct.event_obj_li[i].event_id_random);
// }
// }
// event_id_random_li = tmp_li;
// // console.log(`TEST search: event_id_random_li`, $state.snapshot(event_id_random_li));
// }
// });
function generate_id_random_li({
event_obj_li = $idaa_slct.event_obj_li
}: {
event_obj_li?: Array<any>,
} = {}) {
let tmp_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
// We need to loop through the array of objects and get the id_random from each object a new list of id_randoms. Then we can use this list to get the full objects from the database.
if (event_obj_li && event_obj_li.length) {
for (let i = 0; i < event_obj_li.length; i++) {
tmp_li.push(event_obj_li[i].event_id_random);
}
}
if (log_lvl) {
console.log(`generate_id_random_li:`, tmp_li);
}
return tmp_li;
}
if (browser) {
console.log('Browser environment detected.');
@@ -402,8 +451,9 @@ function add_activity_log(
"
> -->
<!-- bind:event_id_random_li={event_id_random_li} -->
<Comp__event_obj_qry
bind:event_id_random_li={event_id_random_li}
/>
<Element_data_store
@@ -418,9 +468,14 @@ function add_activity_log(
show_edit_btn={true}
/>
{#if $lq_new__event_obj_li && $lq_new__event_obj_li?.length}
<Comp__event_obj_li
lq__event_obj_li={lq_new__event_obj_li}
<!-- {#if $lq_new__event_obj_li && $lq_new__event_obj_li?.length} -->
<!-- lq__event_obj_li={lq_new__event_obj_li} -->
{#if event_id_random_li}
<Comp__event_obj_li_wrapper
event_id_random_li={event_id_random_li}
link_to_type={'account'}
link_to_id={$slct.account_id}
log_lvl={log_lvl}
/>
{:else}
<p>No recovery meetings available to show.</p>