fix(idaa): modernize Bulletin Board reactivity and implement SWR for single posts
This commit is contained in:
@@ -54,44 +54,71 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// *** Functions and Logic
|
// *** Functions and Logic
|
||||||
// Updated 2026-01-26 (Safety Refactor)
|
// Stable LiveQuery Pattern (Aether UI V3)
|
||||||
let lq__post_obj_li = $derived(liveQuery(async () => {
|
let lq__post_obj_li = $derived.by(() => {
|
||||||
const now = new Date();
|
// SVELTE 5 REACTIVITY: Track account selection synchronously
|
||||||
const results = await db_posts.post
|
const account_id = $slct.account_id ?? '';
|
||||||
.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;
|
|
||||||
}));
|
|
||||||
|
|
||||||
// let lq__post_obj = $derived(liveQuery(async () => {
|
return liveQuery(async () => {
|
||||||
// let results = await db_posts.post
|
const now = new Date();
|
||||||
// .get($slct.post_id ?? ''); // null or undefined does not reset things like '' does
|
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 lq__post_comment_obj_li = $derived.by(() => {
|
||||||
// let results = await db_posts.comment
|
const post_id = $idaa_slct.post_id ?? '';
|
||||||
// .where('post_id')
|
return liveQuery(async () => {
|
||||||
// .equals($slct.post_id ?? '') // null or undefined does not reset things like '' does
|
if (!post_id) return [];
|
||||||
// .reverse()
|
return await db_posts.comment
|
||||||
// .sortBy('updated_on');
|
.where('post_id')
|
||||||
// // .sortBy('title');
|
.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 () => {
|
// Handle Single Post Load Trigger
|
||||||
// let results = await db_posts.comment
|
$effect(() => {
|
||||||
// .get($slct.post_comment_id ?? ''); // null or undefined does not reset things like '' does
|
if ($idaa_trig.post_id) {
|
||||||
|
const post_id = $idaa_trig.post_id;
|
||||||
|
$idaa_trig.post_id = null;
|
||||||
|
|
||||||
// return results;
|
if (log_lvl) console.log(`Triggered: load post_id=${post_id}`);
|
||||||
// }));
|
|
||||||
|
// 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(() => {
|
$effect(() => {
|
||||||
if ($idaa_trig.post_li) {
|
if ($idaa_trig.post_li) {
|
||||||
|
|||||||
Reference in New Issue
Block a user