Trying to make this LiveQuery work.

This commit is contained in:
Scott Idem
2024-08-19 17:56:32 -04:00
parent 4871464adf
commit c61d3a4dca
3 changed files with 139 additions and 55 deletions

View File

@@ -16,16 +16,35 @@ import Element_manage_event_file_li from '$lib/element_manage_event_file_li_all.
// Exports
// export let container_class_li: string|Array<string> = [];
// export let event_presentation_id_random_li: Array<string>;
export let lq__event_obj: any;
export let lq__event_presentation_obj_li: any;
// It is important that these not be set to a value! It messes with the Dexie LiveQuery.
// export let event_presentation_id_random_li: Array<string>;
let event_presentation_id_random_li: Array<string>;
// Variables
// Variables
// let ae_promises: key_val = {};
// let ae_tmp: key_val = {};
// let ae_triggers: key_val = {};
let tmp_li: Array<string> = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
if (!event_presentation_id_random_li?.length) {
console.log(`No ID list was passed to the component. Loading all presentations for the session.`);
if ($lq__event_presentation_obj_li?.length) {
console.log(`Count: ${$lq__event_presentation_obj_li?.length}`, $lq__event_presentation_obj_li);
for (let i = 0; i < $lq__event_presentation_obj_li?.length; i++) {
tmp_li.push($lq__event_presentation_obj_li[i].event_presentation_id_random);
}
event_presentation_id_random_li = tmp_li;
} else {
console.log(`No presentations found for the session!`);
}
console.log(`event_presentation_id_random_li:`, event_presentation_id_random_li);
}
// Functions and Logic
import { browser } from '$app/environment';
@@ -33,13 +52,35 @@ if (browser) {
console.log('Browser environment detected.');
}
// let lq_kv__event_presentation_obj_li = liveQuery(
// () => db_events.presentations
// .bulkGet(event_presentation_id_random_li)
// );
let lq_kv__event_presentation_obj_li = liveQuery(
() => db_events.presentations
.bulkGet(event_presentation_id_random_li)
);
// Pull the IDs out of the object list. This may need to be an async function.
let lq_fancy__event_presentation_obj_li = liveQuery(
() => db_events.presentations
.bulkGet(async () => {
console.log('DO STUFF?');
await $lq__event_presentation_obj_li;
console.log(`Count: ${$lq__event_presentation_obj_li?.length}`, $lq__event_presentation_obj_li);
let tmp_li: Array<string> = [];
if ($lq__event_presentation_obj_li?.length) {
for (let i = 0; i < $lq__event_presentation_obj_li?.length; i++) {
tmp_li.push($lq__event_presentation_obj_li[i].event_presentation_id_random);
}
}
return tmp_li;
}
)
);
</script>
<div class="float-right space-2 flex flex-row items-center">
{#if $ae_loc.trusted_access && $ae_loc.edit_mode}
<button
@@ -84,6 +125,39 @@ if (browser) {
</span>
</h3>
<!-- Testing!? -->
<hr>
{#await $lq_kv__event_presentation_obj_li}
waiting
{:then event_presentation_obj_li}
done
{#if $lq_kv__event_presentation_obj_li && $lq_kv__event_presentation_obj_li?.length > 0}
length: {$lq_kv__event_presentation_obj_li?.length}
{/if}
{event_presentation_obj_li?.length}
{:catch}
error
{/await}
<hr>
{#await $lq_fancy__event_presentation_obj_li}
waiting
{:then event_presentation_obj_li}
done
{#if $lq_fancy__event_presentation_obj_li && $lq_fancy__event_presentation_obj_li?.length > 0}
length: {$lq_fancy__event_presentation_obj_li?.length}
{/if}
{event_presentation_obj_li?.length}
{:catch}
error
{/await}
<hr>
<!-- Testing!? -->
<!-- {#await lq__event_presentation_obj_li}
Loading...
{:then} -->
{#if $lq__event_presentation_obj_li && $lq__event_presentation_obj_li?.length > 0}
<ul
class="space-y-4 p-4 m-2 bg-gray-100 rounded-md"
@@ -106,7 +180,7 @@ if (browser) {
let presenter_data = {
event_id_random: $events_slct.event_id,
event_session_id_random: $events_slct.event_session_id,
event_presentation_id_random: event_presentation_obj.event_presentation_id_random,
event_presentation_id_random: event_presentation_obj?.event_presentation_id_random,
given_name: 'New',
family_name: 'Presenter',
email: 'test+newpres@oneskyit.com',
@@ -137,10 +211,10 @@ if (browser) {
<Element_ae_crud
api_cfg={$ae_api}
object_type={'event_presentation'}
object_id={event_presentation_obj.event_presentation_id_random}
object_id={event_presentation_obj?.event_presentation_id_random}
field_name={'name'}
field_type={'text'}
field_value={event_presentation_obj.name}
field_value={event_presentation_obj?.name}
allow_null={false}
hide_edit_btn={!$ae_loc.trusted_access || !$ae_loc.edit_mode}
outline_element={false}
@@ -163,15 +237,15 @@ if (browser) {
}}
>
<!-- <strong class="text-sm">Name/Title:</strong> -->
"{event_presentation_obj.name}"
"{event_presentation_obj?.name}"
</Element_ae_crud>
<!-- "{event_presentation_obj.name}" -->
{#if event_presentation_obj.code || event_presentation_obj.abstract_code}
{#if event_presentation_obj?.code || event_presentation_obj?.abstract_code}
<span class="text-sm text-gray-500 bg-yellow-100 p-1 rounded-md border border-yellow-200"
title="Presentation code {event_presentation_obj.code} and abstract code {event_presentation_obj.abstract_code}"
title="Presentation code {event_presentation_obj?.code} and abstract code {event_presentation_obj?.abstract_code}"
>
<span class="fas fa-barcode"></span>
{event_presentation_obj.code ?? ''} {event_presentation_obj.abstract_code ?? ''}
{event_presentation_obj?.code ?? ''} {event_presentation_obj?.abstract_code ?? ''}
</span>
{/if}
</h4>
@@ -180,10 +254,10 @@ if (browser) {
<Element_ae_crud
api_cfg={$ae_api}
object_type={'event_presentation'}
object_id={event_presentation_obj.event_presentation_id_random}
object_id={event_presentation_obj?.event_presentation_id_random}
field_name={'description'}
field_type={'textarea'}
field_value={event_presentation_obj.description}
field_value={event_presentation_obj?.description}
allow_null={false}
hide_edit_btn={!$ae_loc.trusted_access || !$ae_loc.edit_mode}
outline_element={false}
@@ -202,7 +276,7 @@ if (browser) {
Description:
</strong>
{#if event_presentation_obj.description}
{#if event_presentation_obj?.description}
<button
type="button"
on:click={() => {
@@ -250,11 +324,11 @@ if (browser) {
</div>
<!-- Show presenters for this presentation -->
{#if event_presentation_obj.event_presentation_id_random}
{#if event_presentation_obj?.event_presentation_id_random}
<Comp_event_presenter_obj_li
lq__event_obj={lq__event_obj}
link_to_type={'event_presentation'}
link_to_id={event_presentation_obj.event_presentation_id_random}
link_to_id={event_presentation_obj?.event_presentation_id_random}
>
</Comp_event_presenter_obj_li>
{/if}
@@ -263,7 +337,7 @@ if (browser) {
<!-- Show files for this presentation -->
<Element_manage_event_file_li
link_to_type={'event_presentation'}
link_to_id={event_presentation_obj.event_presentation_id_random}
link_to_id={event_presentation_obj?.event_presentation_id_random}
allow_basic={$events_loc.auth__kv.session[$events_slct.event_session_id] || $events_loc.auth__kv.presenter[$events_slct.event_presenter_id]}
allow_moderator={$events_loc.auth__kv.session[$events_slct.event_session_id]}
container_class_li={''}
@@ -274,4 +348,6 @@ if (browser) {
</ul>
{:else}
Nothing to show yet...!
{/if}
{/if}
<!-- {/await} -->

View File

@@ -60,36 +60,36 @@ let lq__event_presentation_obj = liveQuery(
() => db_events.presentations.get($events_slct.event_presentation_id)
);
let lq_kv__event_presenter_obj_li_2 = liveQuery(
() => db_events.presenters
.bulkGet(event_presenter_id_random_li)
.then(results => {
// console.log(`LQ Results:`, results);
// If the results are an array
if (results.length == 1) {
// If the first item is undefined we need to do something.
if (results[0] == undefined) {
console.log('Something went wrong! No presenters found?');
// return [];
// return [{ id: '' }];
// return 'NOTHING???';
}
return results;
}else if (results.length > 1) {
return results;
} else {
return ['No presenters found.'];
}
// return results;
})
.catch(error => {
console.error(`LQ Error: ${error}`);
return ['No presenters found.'];
})
.finally(() => {
console.log(`LQ Finally:`, $lq_kv__event_presenter_obj_li_2);
})
);
// let lq_kv__event_presenter_obj_li_2 = liveQuery(
// () => db_events.presenters
// .bulkGet(event_presenter_id_random_li)
// .then(results => {
// // console.log(`LQ Results:`, results);
// // If the results are an array
// if (results.length == 1) {
// // If the first item is undefined we need to do something.
// if (results[0] == undefined) {
// console.log('Something went wrong! No presenters found?');
// // return [];
// // return [{ id: '' }];
// // return 'NOTHING???';
// }
// return results;
// }else if (results.length > 1) {
// return results;
// } else {
// return ['No presenters found.'];
// }
// // return results;
// })
// .catch(error => {
// console.error(`LQ Error: ${error}`);
// return ['No presenters found.'];
// })
// .finally(() => {
// console.log(`LQ Finally:`, $lq_kv__event_presenter_obj_li_2);
// })
// );
// let lq__event_presentation_obj_li = liveQuery(
// () => db_events.presentations

View File

@@ -793,12 +793,20 @@ $: if ($lq__event_session_obj) {
<!-- Presentations in the session -->
<section>
{#await $lq__event_presentation_obj_li}
Loading....
{:then event_presentation_obj_li}
{#if $lq__event_presentation_obj_li && $lq__event_presentation_obj_li?.length > 0}
<!-- {$lq__event_presentation_obj_li?.length} Presentations -->
<Comp_event_presentation_obj_li
lq__event_obj={lq__event_obj}
lq__event_presentation_obj_li={lq__event_presentation_obj_li}
>
<!-- event_presentation_id_random_li={[]} -->
</Comp_event_presentation_obj_li>
{/if}
{/await}
<Comp_event_presentation_obj_li
lq__event_obj={lq__event_obj}
lq__event_presentation_obj_li={lq__event_presentation_obj_li}
>
</Comp_event_presentation_obj_li>
</section>