diff --git a/src/lib/ae_events/ae_events__event.ts b/src/lib/ae_events/ae_events__event.ts index 2dc68ff0..d18634cf 100644 --- a/src/lib/ae_events/ae_events__event.ts +++ b/src/lib/ae_events/ae_events__event.ts @@ -326,6 +326,10 @@ export async function qry_ae_obj_li__event( inc_presentation_li: inc_presentation_li, inc_presenter_li: inc_presenter_li, inc_session_li: inc_session_li, + enabled: enabled, + hidden: hidden, + limit: limit, + offset: offset, order_by_li: order_by_li, params_json: params_json, params: params, diff --git a/src/routes/idaa/(idaa)/bb/+page.svelte b/src/routes/idaa/(idaa)/bb/+page.svelte index 4b54a0bd..9008d10b 100644 --- a/src/routes/idaa/(idaa)/bb/+page.svelte +++ b/src/routes/idaa/(idaa)/bb/+page.svelte @@ -72,12 +72,17 @@ $: if ($idaa_trig.post_li) { console.log(`Triggered: $idaa_trig.post_li`); } - if ($idaa_loc.bb.qry__enabled !== 'all' || $idaa_loc.bb.qry__hidden !== 'all') { + // This may need to be rethought... For now things are cleared if query is anything but 'all' for enabled and hidden. + if ($idaa_loc.bb.qry__enabled !== 'all' || $idaa_loc.bb.qry__hidden !== 'all' || $idaa_loc.bb.qry__limit < 50) { console.log(`Deleting disabled or hidden post.`); let results = db_posts.post .clear(); console.log(`Deleted ${results} disabled post.`); + console.log(`Deleting disabled or hidden post comments.`); + results = db_posts.comment + .clear(); + console.log(`Deleted ${results} disabled post comments.`); } $idaa_prom.load__post_obj_li = posts_func.load_ae_obj_li__post({ diff --git a/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_options.svelte b/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_options.svelte index 5bd40c5d..452f2ec1 100644 --- a/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_options.svelte +++ b/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_options.svelte @@ -36,6 +36,7 @@ let search_submit_results: any = null; id="qry_limit__posts" bind:value={$idaa_loc.bb.qry__limit} on:change={() => { + $idaa_trig.post_li = true; }} class="select w-20 text-sm" > @@ -53,24 +54,8 @@ let search_submit_results: any = null; type="button" on:click={() => { $idaa_loc.bb.qry__hidden = 'all'; - // $idaa_loc.bb.qry__limit = 200; + $idaa_loc.bb.qry__limit = 100; $idaa_trig.post_li = true; - - // let load_post_obj_li = posts_func.load_ae_obj_li__post({ - // api_cfg: $ae_api, - // for_obj_type: 'account', - // for_obj_id: $ae_loc.account_id, - // inc_comment_li: true, - // enabled: $idaa_loc.bb.qry__enabled, - // hidden: $idaa_loc.bb.qry__hidden, - // limit: $idaa_loc.bb.qry__limit, - // order_by_li: $idaa_loc.bb.qry__order_by_li, - // try_cache: true, - // log_lvl: log_lvl - // }); - // console.log(`load_post_obj_li = `, load_post_obj_li); - // $idaa_slct.post_obj_li = load_post_obj_li; - }} class="btn_show_bb_post ae_btn btn btn-info btn-sm variant-ghost-secondary" > @@ -81,23 +66,7 @@ let search_submit_results: any = null; type="button" on:click={() => { $idaa_loc.bb.qry__hidden = 'not_hidden'; - // $idaa_loc.bb.qry__limit = 100; $idaa_trig.post_li = true; - - // let load_post_obj_li = posts_func.load_ae_obj_li__post({ - // api_cfg: $ae_api, - // for_obj_type: 'account', - // for_obj_id: $ae_loc.account_id, - // inc_comment_li: true, - // enabled: $idaa_loc.bb.qry__enabled, - // hidden: $idaa_loc.bb.qry__hidden, - // limit: $idaa_loc.bb.qry__limit, - // order_by_li: $idaa_loc.bb.qry__order_by_li, - // try_cache: true, - // log_lvl: log_lvl - // }); - // console.log(`load_post_obj_li = `, load_post_obj_li); - // $idaa_slct.post_obj_li = load_post_obj_li; }} class="btn_hide_bb_post ae_btn btn btn-info btn-sm variant-ghost-secondary" > @@ -113,21 +82,6 @@ let search_submit_results: any = null; $idaa_loc.bb.qry__enabled = 'all'; $idaa_loc.bb.qry__limit = 500; $idaa_trig.post_li = true; - - // let load_post_obj_li = posts_func.load_ae_obj_li__post({ - // api_cfg: $ae_api, - // for_obj_type: 'account', - // for_obj_id: $ae_loc.account_id, - // inc_comment_li: true, - // enabled: $idaa_loc.bb.qry__enabled, - // hidden: $idaa_loc.bb.qry__hidden, - // limit: $idaa_loc.bb.qry__limit, - // order_by_li: $idaa_loc.bb.qry__order_by_li, - // try_cache: true, - // log_lvl: log_lvl - // }); - // console.log(`load_post_obj_li = `, load_post_obj_li); - // $idaa_slct.post_obj_li = load_post_obj_li; }} class="btn_show_bb_post ae_btn btn btn-warning btn-sm variant-ghost-secondary" > @@ -139,21 +93,6 @@ let search_submit_results: any = null; on:click={() => { $idaa_loc.bb.qry__enabled = 'enabled'; $idaa_trig.post_li = true; - - // let load_post_obj_li = posts_func.load_ae_obj_li__post({ - // api_cfg: $ae_api, - // for_obj_type: 'account', - // for_obj_id: $ae_loc.account_id, - // inc_comment_li: true, - // enabled: $idaa_loc.bb.qry__enabled, - // hidden: $idaa_loc.bb.qry__hidden, - // limit: $idaa_loc.bb.qry__limit, - // order_by_li: $idaa_loc.bb.qry__order_by_li, - // try_cache: true, - // log_lvl: log_lvl - // }); - // console.log(`load_post_obj_li = `, load_post_obj_li); - // $idaa_slct.post_obj_li = load_post_obj_li; }} class="btn_hide_bb_post ae_btn btn btn-warning btn-sm variant-ghost-secondary" > diff --git a/src/routes/idaa/(idaa)/recovery_meetings/+page.svelte b/src/routes/idaa/(idaa)/recovery_meetings/+page.svelte index e896b688..09755e9d 100644 --- a/src/routes/idaa/(idaa)/recovery_meetings/+page.svelte +++ b/src/routes/idaa/(idaa)/recovery_meetings/+page.svelte @@ -106,6 +106,139 @@ $: if ($idaa_trig.event_li) { log_lvl: log_lvl, }); } + + +$: if ($idaa_trig.event_li_qry) { + $idaa_trig.event_li_qry = false; + + if (log_lvl) { + console.log(`Triggered: $idaa_trig.event_li_qry`); + } + + 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 search_delay = 15; + let max_tries = 5; + let try_cache = true; + + let params = { + 'qry__enabled': $idaa_loc.recovery_meetings.qry__enabled ?? 'enabled', + 'qry__hidden': $idaa_loc.recovery_meetings.qry__hidden ?? 'not_hidden', + 'qry__limit': $idaa_loc.recovery_meetings.qry__limit ?? 35, + }; + + + 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_sess.recovery_meetings?.qry__status != null && $idaa_sess.recovery_meetings?.qry__status != 'done') { + console.log('*** TEST SEARCH - $idaa_sess.recovery_meetings.qry__status != done ***'); + // WARNING: This is a temporary fix for the search string. It needs to be fixed in the future. Using lk_search_str for now. + $idaa_sess.recovery_meetings.status_qry__last_request_str = $idaa_loc.recovery_meetings.qry__fulltext_str; + + // We want to delay the initial search request to give the previous search request to finish. + let random_delay = Math.floor(Math.random() * 50); + search_delay += 50+random_delay; + } + + log_lvl = 1; + + let count = 0; + let request_loop = setInterval(() => { + count++; + if (log_lvl) { + console.log(`*** TEST SEARCH - Search delay: ${search_delay} *** loop count=${count}`); + } + if (count >= max_tries) { + console.log('*** TEST SEARCH - Max tries reached ***'); + clearInterval(request_loop); + } + + 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 ***'); + + $idaa_sess.recovery_meetings.qry__status = 'loading'; + + (and_physical) ?? null; + (and_virtual) ?? null; + (and_type) ?? null; + // if (and_type) and_type = and_type; + // if (!and_type) { + // and_type = null; + // } + + console.log(`TEST - and_physical: ${and_physical}; and_virtual: ${and_virtual}; and_type: ${and_type}; qry__fulltext_str: ${$idaa_loc.recovery_meetings.qry__fulltext_str}; params:`, params); + + $idaa_prom.load__event_obj_qry = events_func.qry_ae_obj_li__event({ + api_cfg: $ae_api, + for_obj_type: 'account', + for_obj_id: $ae_loc.account_id, + order_by_li: order_by_li, + qry_conference: false, + qry_physical: and_physical, + qry_virtual: and_virtual, + qry_type: and_type, + qry_str: $idaa_loc.recovery_meetings.qry__fulltext_str, + params: params, + 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); + // $idaa_sess.recovery_meetings.qry__status = 'done'; + + if (log_lvl) { + console.log('TEST SEARCH - Search done. Pulling out the event_id_randoms.'); + } + // 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; + }) + .finally(() => { + + + // event_id_random_li = $idaa_slct.event_obj_li.map(session_obj => session_obj.event_id_random); + + // Finally done with the search. + $idaa_sess.recovery_meetings.qry__status = 'done'; + + if (log_lvl > 1) { + console.log(`TEST SEARCH - event_id_random_li:`, event_id_random_li); + // console.log(`TEST SEARCH - search live query: ${$lq_kv__event_obj_li}`); + } + + }); + clearInterval(request_loop); + } + }, search_delay); + +} + + diff --git a/src/routes/idaa/(idaa)/recovery_meetings/ae_idaa_comp__event_obj_qry.svelte b/src/routes/idaa/(idaa)/recovery_meetings/ae_idaa_comp__event_obj_qry.svelte index 1053b061..70f91cdb 100644 --- a/src/routes/idaa/(idaa)/recovery_meetings/ae_idaa_comp__event_obj_qry.svelte +++ b/src/routes/idaa/(idaa)/recovery_meetings/ae_idaa_comp__event_obj_qry.svelte @@ -7,7 +7,7 @@ import type { key_val } from '$lib/ae_stores'; import { ae_util } from '$lib/ae_utils/ae_utils'; import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/ae_stores'; import { core_func } from '$lib/ae_core/ae_core_functions'; -import { idaa_loc, idaa_sess, idaa_slct } from '$lib/ae_idaa_stores'; +import { idaa_loc, idaa_sess, idaa_slct, idaa_trig, idaa_prom } from '$lib/ae_idaa_stores'; import { events_func } from '$lib/ae_events_functions'; export let log_lvl = 0; @@ -27,7 +27,7 @@ onMount(() => { }); if ($idaa_loc.recovery_meetings.qry__fulltext_str && $idaa_loc.recovery_meetings.qry__fulltext_str.length) { - ae_trigger = 'load__event_obj_li'; + $idaa_trig.event_li_qry = true; } @@ -43,12 +43,14 @@ $: if (ae_trigger == 'load__event_obj_li') { setTimeout(() => { console.log("Delayed for X second."); // ae_trigger = null; - handle_qry__event({ft_qry_str: $idaa_loc.recovery_meetings.qry__fulltext_str}); + // handle_qry__event({ft_qry_str: $idaa_loc.recovery_meetings.qry__fulltext_str}); + $idaa_trig.event_li_qry = true; }, 250); } else { console.log('*** $idaa_sess.recovery_meetings.qry_status != loading ***'); // ae_trigger = null; - handle_qry__event({ft_qry_str: $idaa_loc.recovery_meetings.qry__fulltext_str}); + // handle_qry__event({ft_qry_str: $idaa_loc.recovery_meetings.qry__fulltext_str}); + $idaa_trig.event_li_qry = true; } } @@ -126,57 +128,57 @@ async function handle_qry__event( console.log(`TEST - and_physical: ${and_physical}; and_virtual: ${and_virtual}; and_type: ${and_type}; ft_qry_str: ${ft_qry_str}; params:`, params); - search_submit_results = events_func.qry_ae_obj_li__event({ - api_cfg: $ae_api, - for_obj_type: 'account', - for_obj_id: $ae_loc.account_id, - order_by_li: order_by_li, - qry_conference: false, - qry_physical: and_physical, - qry_virtual: and_virtual, - qry_type: and_type, - qry_str: ft_qry_str, - params: params, - 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); - // $idaa_sess.recovery_meetings.qry__status = 'done'; + // search_submit_results = events_func.qry_ae_obj_li__event({ + // api_cfg: $ae_api, + // for_obj_type: 'account', + // for_obj_id: $ae_loc.account_id, + // order_by_li: order_by_li, + // qry_conference: false, + // qry_physical: and_physical, + // qry_virtual: and_virtual, + // qry_type: and_type, + // qry_str: ft_qry_str, + // params: params, + // 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); + // // $idaa_sess.recovery_meetings.qry__status = 'done'; - if (log_lvl) { - console.log('TEST SEARCH - Search done. Pulling out the event_id_randoms.'); - } - // console.log(`TEST search: ${$lq_kv__event_obj_li}`); + // if (log_lvl) { + // console.log('TEST SEARCH - Search done. Pulling out the event_id_randoms.'); + // } + // // console.log(`TEST search: ${$lq_kv__event_obj_li}`); - // event_id_random_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; - }) - .finally(() => { + // // 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(() => { - // event_id_random_li = $idaa_slct.event_obj_li.map(session_obj => session_obj.event_id_random); + // // event_id_random_li = $idaa_slct.event_obj_li.map(session_obj => session_obj.event_id_random); - // Finally done with the search. - $idaa_sess.recovery_meetings.qry__status = 'done'; + // // Finally done with the search. + // $idaa_sess.recovery_meetings.qry__status = 'done'; - if (log_lvl > 1) { - console.log(`TEST SEARCH - event_id_random_li:`, event_id_random_li); - // console.log(`TEST SEARCH - search live query: ${$lq_kv__event_obj_li}`); - } + // if (log_lvl > 1) { + // console.log(`TEST SEARCH - event_id_random_li:`, event_id_random_li); + // // console.log(`TEST SEARCH - search live query: ${$lq_kv__event_obj_li}`); + // } - }); + // }); clearInterval(request_loop); } }, search_delay); @@ -192,7 +194,7 @@ async function handle_qry__event(
{ - ae_trigger = 'load__event_obj_li'; + $idaa_trig.event_li_qry = true; }} class="search_form flex flex-col gap-1 w-full" > @@ -212,7 +214,8 @@ async function handle_qry__event( class="btn btn-sm variant-ghost-warning hover:variant-filled-warning transition-all" on:click={() => { $idaa_loc.recovery_meetings.qry__fulltext_str = ''; - ae_trigger = 'load__event_obj_li'; + // $idaa_trig.event_li_qry = true; + $idaa_trig.event_li_qry = true; }} title="Clear search text" > @@ -227,6 +230,11 @@ async function handle_qry__event( id="meeting_qry__fulltext_str" name="qry__fulltext_str" bind:value={$idaa_loc.recovery_meetings.qry__fulltext_str} + on:keyup={ + () => { + $idaa_trig.event_li_qry = true; + } + } style="width: 50%;" class="bs-input input text-sm hover:text-2xl font-bold font-mono w-80 transition-all" > @@ -258,7 +266,7 @@ async function handle_qry__event( name="qry_virtual" type="checkbox" bind:checked={$idaa_loc.recovery_meetings.qry__virtual} - on:change={() => {ae_trigger = 'load__event_obj_li';}} + on:change={() => {$idaa_trig.event_li_qry = true;}} class="checkbox" > @@ -268,7 +276,7 @@ async function handle_qry__event( name="qry_physical" type="checkbox" bind:checked={$idaa_loc.recovery_meetings.qry__physical} - on:change={() => {ae_trigger = 'load__event_obj_li';}} + on:change={() => {$idaa_trig.event_li_qry = true;}} class="checkbox" > @@ -286,7 +294,7 @@ async function handle_qry__event( type="radio" value="" bind:group={$idaa_loc.recovery_meetings.qry__type} - on:change={() => {ae_trigger = 'load__event_obj_li';}} + on:change={() => {$idaa_trig.event_li_qry = true;}} class="radio" title="Show all meeting types" > @@ -297,7 +305,7 @@ async function handle_qry__event( type="radio" value="IDAA" bind:group={$idaa_loc.recovery_meetings.qry__type} - on:change={() => {ae_trigger = 'load__event_obj_li';}} + on:change={() => {$idaa_trig.event_li_qry = true;}} class="radio" title="Open to IDAA members only" > @@ -308,7 +316,7 @@ async function handle_qry__event( type="radio" value="Caduceus" bind:group={$idaa_loc.recovery_meetings.qry__type} - on:change={() => {ae_trigger = 'load__event_obj_li';}} + on:change={() => {$idaa_trig.event_li_qry = true;}} class="radio" title="Open to all healthcare workers including those who do not qualify for IDAA" > @@ -319,7 +327,7 @@ async function handle_qry__event( type="radio" value="Family Recovery" bind:group={$idaa_loc.recovery_meetings.qry__type} - on:change={() => {ae_trigger = 'load__event_obj_li';}} + on:change={() => {$idaa_trig.event_li_qry = true;}} class="radio" title="Open to spouses, parents, and children of medical professionals who have substance use disorder." > @@ -331,7 +339,7 @@ async function handle_qry__event( type="radio" value="Al-Anon" bind:group={$idaa_loc.recovery_meetings.qry__type} - on:change={() => {ae_trigger = 'load__event_obj_li';}} + on:change={() => {$idaa_trig.event_li_qry = true;}} > {/if} --> @@ -370,7 +378,7 @@ async function handle_qry__event( id="qry_limit__events" bind:value={$idaa_loc.recovery_meetings.qry__limit} on:change={() => { - ae_trigger = 'load__event_obj_li'; + $idaa_trig.event_li_qry = true; // search__event_presenter({ // api_cfg: $ae_api, // event_id: $events_slct.event_id, @@ -417,7 +425,7 @@ async function handle_qry__event( $idaa_loc.recovery_meetings.qry__order_by = 'name'; $idaa_loc.recovery_meetings.qry__order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'}; } - ae_trigger = 'load__event_obj_li'; + $idaa_trig.event_li_qry = true; }} class="select w-40 text-sm" > @@ -435,7 +443,7 @@ async function handle_qry__event( on:click={() => { $idaa_loc.recovery_meetings.qry__hidden = 'all'; $idaa_loc.recovery_meetings.qry__limit = 200; - ae_trigger = 'load__event_obj_li'; + $idaa_trig.event_li_qry = true; }} class="btn_show_bb_post ae_btn btn btn-info btn-sm variant-ghost-secondary" > @@ -446,8 +454,8 @@ async function handle_qry__event( type="button" on:click={() => { $idaa_loc.recovery_meetings.qry__hidden = 'not_hidden'; - $idaa_loc.recovery_meetings.qry__limit = 100; - ae_trigger = 'load__event_obj_li'; + // $idaa_loc.recovery_meetings.qry__limit = 100; + $idaa_trig.event_li_qry = true; }} class="btn_hide_bb_post ae_btn btn btn-info btn-sm variant-ghost-secondary" > @@ -462,7 +470,7 @@ async function handle_qry__event( $idaa_loc.recovery_meetings.qry__hidden = 'all'; $idaa_loc.recovery_meetings.qry__enabled = 'all'; $idaa_loc.recovery_meetings.qry__limit = 500; - ae_trigger = 'load__event_obj_li'; + $idaa_trig.event_li_qry = true; }} class="btn_show_bb_post ae_btn btn btn-warning btn-sm variant-ghost-secondary" > @@ -473,7 +481,7 @@ async function handle_qry__event( type="button" on:click={() => { $idaa_loc.recovery_meetings.qry__enabled = 'enabled'; - ae_trigger = 'load__event_obj_li'; + $idaa_trig.event_li_qry = true; }} class="btn_hide_bb_post ae_btn btn btn-warning btn-sm variant-ghost-secondary" >