fix(idaa): modernize Bulletin Board reactivity and implement SWR for single posts

This commit is contained in:
Scott Idem
2026-02-05 18:07:18 -05:00
parent 6c2c37ff06
commit 6d98758f3c

View File

@@ -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) {