From 477fc16f16af661dd2eeb469687cf0733d413bc5 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Wed, 11 Mar 2026 14:06:33 -0400 Subject: [PATCH] fix: derive poster session type from Dexie chain for presenter-linked files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit v_event_file joins event_session only via event_file.event_session_id. Files with for_type='event_presenter' have event_session_id=NULL on the file record itself, so event_session_type_code is structurally always NULL from the API for these files — no amount of refreshing can fix it. Instead of relying on the file's event_session_type_code, derive the session type in element_manage_event_file_li_direct via the Dexie chain: presenter.event_presentation_id → presentation.event_session_id → session.type_code Pass the result as context_session_type_code to element_manage_event_file_li, which now checks EITHER the file's own event_session_type_code OR the context prop against 'poster' to show the PDF→Image convert button. Sessions are guaranteed in Dexie because the pres_mgmt layout loads inc_session_li:true on every navigation. Co-Authored-By: Claude Sonnet 4.6 --- .../element_manage_event_file_li.svelte | 14 +++++- ...element_manage_event_file_li_direct.svelte | 46 ++++++++----------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/lib/elements/element_manage_event_file_li.svelte b/src/lib/elements/element_manage_event_file_li.svelte index 3585a246..c1de6083 100644 --- a/src/lib/elements/element_manage_event_file_li.svelte +++ b/src/lib/elements/element_manage_event_file_li.svelte @@ -35,6 +35,11 @@ allow_basic?: boolean; allow_moderator?: boolean; display_mode?: string; // 'default', 'compact', 'minimal', 'launcher' + // WHY: event_file.event_session_type_code is NULL for presenter-linked files because + // v_event_file joins event_session only via event_file.event_session_id, which is NULL + // when for_type='event_presenter'. The wrapper derives the correct type from the + // presenter → presentation → session chain and passes it here as context. + context_session_type_code?: string | null; } let { @@ -45,7 +50,8 @@ link_to_id, allow_basic = false, allow_moderator = false, - display_mode = 'default' + display_mode = 'default', + context_session_type_code = null }: Props = $props(); // export let show_convert_btn: null|boolean = null; @@ -239,7 +245,7 @@ /> - {#if $ae_loc.edit_mode && event_file_obj?.extension === 'pdf' && event_file_obj?.event_session_type_code === 'poster'} + {#if $ae_loc.edit_mode && event_file_obj?.extension === 'pdf' && (event_file_obj?.event_session_type_code === 'poster' || context_session_type_code === 'poster')}
{#if !convert_status_kv[event_file_obj.event_file_id] || convert_status_kv[event_file_obj.event_file_id] === 'idle'}
+ {:else} + + test test test + {/if} {#if ae_tmp.show__direct_download} diff --git a/src/lib/elements/element_manage_event_file_li_direct.svelte b/src/lib/elements/element_manage_event_file_li_direct.svelte index 91b7f85a..a8c1068e 100644 --- a/src/lib/elements/element_manage_event_file_li_direct.svelte +++ b/src/lib/elements/element_manage_event_file_li_direct.svelte @@ -21,16 +21,13 @@ }: Props = $props(); import { liveQuery } from 'dexie'; - import { untrack } from 'svelte'; import type { key_val } from '$lib/stores/ae_stores'; - import { ae_api } from '$lib/stores/ae_stores'; // import { ae_util } from '$lib/ae_utils/ae_utils'; import Element_manage_event_file_li from '$lib/elements/element_manage_event_file_li.svelte'; // import { core_func } from '$lib/ae_core_functions'; import { db_events } from '$lib/ae_events/db_events'; - import { events_func } from '$lib/ae_events_functions'; // import { events_loc, events_sess, events_slct, events_trigger } from '$lib/stores/ae_events_stores'; // export let show_convert_btn: null|boolean = null; @@ -41,30 +38,26 @@ ae_tmp.show__direct_download = false; // let ae_triggers: key_val = {}; - // WHY: When a parent page loads with try_cache:false (e.g. presenter detail), - // the fresh API data (including event_session_type_code) is NOT written to Dexie. - // The liveQuery below then sees stale Dexie records missing that field, so - // the PDF→image convert button condition silently fails. + // WHY: v_event_file joins event_session only via event_file.event_session_id. + // Files with for_type='event_presenter' have event_session_id=NULL on the file record + // itself, so event_session_type_code is structurally always NULL from the API for these + // files — even if the presenter is in a poster session. Refreshing from the API does not + // help; the view cannot join session type for presenter-linked files. // - // Using $effect (not onMount) because link_to_id arrives AFTER mount when the - // parent presenter liveQuery resolves — onMount fires too early and misses it. - // untrack() prevents the function body's internals from registering as deps. - $effect(() => { - if (!link_to_id) return; - const _id = link_to_id; - const _type = link_to_type; - const _cfg = $ae_api; - untrack(() => { - events_func.load_ae_obj_li__event_file({ - api_cfg: _cfg, - for_obj_type: _type, - for_obj_id: _id, - enabled: 'all', - hidden: 'all', - try_cache: true - }); - }); - }); + // Solution: derive the session type via the Dexie chain: + // presenter.event_presentation_id → presentation.event_session_id → session.type_code + // Sessions are guaranteed in Dexie because the pres_mgmt layout loads inc_session_li:true. + let lq__context_session_type_code = $derived( + liveQuery(async () => { + if (link_to_type !== 'event_presenter' || !link_to_id) return null; + const presenter = await db_events.presenter.get(link_to_id); + if (!presenter?.event_presentation_id) return null; + const presentation = await db_events.presentation.get(presenter.event_presentation_id); + if (!presentation?.event_session_id) return null; + const session = await db_events.session.get(presentation.event_session_id); + return session?.type_code ?? null; + }) + ); let dq__where_val: string = `for_type`; let dq__where_eq_val = $derived(link_to_type); @@ -97,6 +90,7 @@ {allow_moderator} {container_class_li} {display_mode} + context_session_type_code={$lq__context_session_type_code ?? null} {log_lvl} /> {:catch error}