From 6d98758f3c38313c9ecc2eb84f11e90407dad389 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Thu, 5 Feb 2026 18:07:18 -0500 Subject: [PATCH] fix(idaa): modernize Bulletin Board reactivity and implement SWR for single posts --- src/routes/idaa/(idaa)/bb/+page.svelte | 91 +++++++++++++++++--------- 1 file changed, 59 insertions(+), 32 deletions(-) diff --git a/src/routes/idaa/(idaa)/bb/+page.svelte b/src/routes/idaa/(idaa)/bb/+page.svelte index 144de30c..e9d721aa 100644 --- a/src/routes/idaa/(idaa)/bb/+page.svelte +++ b/src/routes/idaa/(idaa)/bb/+page.svelte @@ -54,44 +54,71 @@ } // *** Functions and Logic - // Updated 2026-01-26 (Safety Refactor) - let lq__post_obj_li = $derived(liveQuery(async () => { - const now = new Date(); - const results = await db_posts.post - .where('account_id').equals($slct.account_id ?? '') - .filter((x) => { - if (!x.archive_on) return true; - const archiveDate = x.archive_on instanceof Date ? x.archive_on : new Date(x.archive_on); - return archiveDate > now; - }) - .toArray(); - return results; - })); + // Stable LiveQuery Pattern (Aether UI V3) + let lq__post_obj_li = $derived.by(() => { + // SVELTE 5 REACTIVITY: Track account selection synchronously + const account_id = $slct.account_id ?? ''; - // let lq__post_obj = $derived(liveQuery(async () => { - // let results = await db_posts.post - // .get($slct.post_id ?? ''); // null or undefined does not reset things like '' does + return liveQuery(async () => { + const now = new Date(); + const results = await db_posts.post + .where('account_id').equals(account_id) + .filter((x) => { + if (!x.archive_on) return true; + const archiveDate = x.archive_on instanceof Date ? x.archive_on : new Date(x.archive_on); + return archiveDate > now; + }) + .toArray(); + return results; + }); + }); - // return results; - // })); + let lq__post_obj = $derived.by(() => { + const post_id = $idaa_slct.post_id ?? ''; + return liveQuery(async () => { + if (!post_id) return null; + return await db_posts.post.get(post_id); + }); + }); - // let lq__post_comment_obj_li = $derived(liveQuery(async () => { - // let results = await db_posts.comment - // .where('post_id') - // .equals($slct.post_id ?? '') // null or undefined does not reset things like '' does - // .reverse() - // .sortBy('updated_on'); - // // .sortBy('title'); + let lq__post_comment_obj_li = $derived.by(() => { + const post_id = $idaa_slct.post_id ?? ''; + return liveQuery(async () => { + if (!post_id) return []; + return await db_posts.comment + .where('post_id') + .equals(post_id) + .reverse() + .sortBy('updated_on'); + }); + }); - // return results; - // })); + let lq__post_comment_obj = $derived.by(() => { + const comment_id = $idaa_slct.post_comment_id ?? ''; + return liveQuery(async () => { + if (!comment_id) return null; + return await db_posts.comment.get(comment_id); + }); + }); - // let lq__post_comment_obj = $derived(liveQuery(async () => { - // let results = await db_posts.comment - // .get($slct.post_comment_id ?? ''); // null or undefined does not reset things like '' does + // Handle Single Post Load Trigger + $effect(() => { + if ($idaa_trig.post_id) { + const post_id = $idaa_trig.post_id; + $idaa_trig.post_id = null; + + if (log_lvl) console.log(`Triggered: load post_id=${post_id}`); - // return results; - // })); + // Non-blocking background refresh + posts_func.load_ae_obj_id__post({ + api_cfg: $ae_api, + post_id: post_id, + inc_comment_li: true, + try_cache: true, + log_lvl + }); + } + }); $effect(() => { if ($idaa_trig.post_li) {