From 40061b92cae931366e047f30e8076963a4a42f01 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Wed, 2 Jul 2025 17:09:52 -0400 Subject: [PATCH] I have the new BB Posts working well for IDAA now. NOTE: I intentionally split the API calls that are triggered on layout and page loads. --- src/lib/ae_journals/ae_journals__journal.ts | 4 + src/lib/ae_posts/ae_posts__post.ts | 6 +- src/routes/idaa/(idaa)/bb/+layout.svelte | 56 +++++++++- src/routes/idaa/(idaa)/bb/+layout.ts | 100 +++++++++--------- src/routes/idaa/(idaa)/bb/+page.svelte | 80 +++++++------- src/routes/idaa/(idaa)/bb/+page.ts | 42 ++++++++ .../idaa/(idaa)/bb/[post_id]/+page.svelte | 5 +- src/routes/idaa/(idaa)/bb/[post_id]/+page.ts | 12 +++ .../bb/ae_idaa_comp__post_obj_id_edit.svelte | 18 ++-- src/routes/journals/[journal_id]/+layout.ts | 18 +++- .../entry/[journal_entry_id]/+page.ts | 10 +- 11 files changed, 247 insertions(+), 104 deletions(-) create mode 100644 src/routes/idaa/(idaa)/bb/+page.ts diff --git a/src/lib/ae_journals/ae_journals__journal.ts b/src/lib/ae_journals/ae_journals__journal.ts index 197ca389..543eaf46 100644 --- a/src/lib/ae_journals/ae_journals__journal.ts +++ b/src/lib/ae_journals/ae_journals__journal.ts @@ -98,6 +98,10 @@ export async function load_ae_obj_id__journal( if (log_lvl) { console.log('ae_promises.load__journal_obj:', ae_promises.load__journal_obj); } + if (!ae_promises.load__journal_obj) { + console.log(`ERROR: Journals - Journal - The journal with ID ${journal_id} was not found.`); + return ae_promises.load__journal_obj; // Return null if the journal was not found + } if (inc_entry_li) { // Load the entries for the journal diff --git a/src/lib/ae_posts/ae_posts__post.ts b/src/lib/ae_posts/ae_posts__post.ts index a6425f87..29103151 100644 --- a/src/lib/ae_posts/ae_posts__post.ts +++ b/src/lib/ae_posts/ae_posts__post.ts @@ -95,6 +95,10 @@ export async function load_ae_obj_id__post( if (log_lvl) { console.log('ae_promises.load__post_obj:', ae_promises.load__post_obj); } + if (!ae_promises.load__post_obj) { + console.log(`ERROR: Posts - Post - The post with ID ${post_id} was not found.`); + return ae_promises.load__post_obj; // Return null if the post was not found + } if (inc_comment_li) { // Load the comments for the post @@ -109,7 +113,7 @@ export async function load_ae_obj_id__post( hidden: hidden, // all, hidden, not_hidden limit: limit, // Limit for the comments offset: offset, - params: {qry__enabled: 'all', qry__limit: 25}, + params: params, try_cache: try_cache, log_lvl: log_lvl }) diff --git a/src/routes/idaa/(idaa)/bb/+layout.svelte b/src/routes/idaa/(idaa)/bb/+layout.svelte index b207dc33..7905d3b9 100644 --- a/src/routes/idaa/(idaa)/bb/+layout.svelte +++ b/src/routes/idaa/(idaa)/bb/+layout.svelte @@ -1,9 +1,13 @@ diff --git a/src/routes/idaa/(idaa)/bb/+layout.ts b/src/routes/idaa/(idaa)/bb/+layout.ts index 959c2f82..cbe5adef 100644 --- a/src/routes/idaa/(idaa)/bb/+layout.ts +++ b/src/routes/idaa/(idaa)/bb/+layout.ts @@ -7,60 +7,60 @@ import { browser } from '$app/environment'; import { posts_func } from '$lib/ae_posts/ae_posts_functions'; export async function load({ params, parent }) { // route - let log_lvl: number = 0; + // let log_lvl: number = 0; - let data = await parent(); - data.log_lvl = log_lvl; + // let data = await parent(); + // data.log_lvl = log_lvl; - let account_id = data.account_id; - let ae_acct = data[account_id]; - // console.log(`ae_acct = `, ae_acct); + // let account_id = data.account_id; + // let ae_acct = data[account_id]; + // // console.log(`ae_acct = `, ae_acct); - // if (!account_id) { - // console.log(`ae IDAA BB - [account_id] +page.ts: The account_id was not found!!!`); - // error(404, { - // message: 'Account ID not found' - // }); + // // if (!account_id) { + // // console.log(`ae IDAA BB - [account_id] +page.ts: The account_id was not found!!!`); + // // error(404, { + // // message: 'Account ID not found' + // // }); + // // } + + // // ae_acct.slct.account_id = account_id; + + // // let post_id = params.post_id; + // // let post_id = page.url.searchParams.has('post_id') ?? null; + // // let post_id = page.url.searchParams.get('post_id') ?? null; + // // if (!post_id) { + // // console.log(`ae Posts - [post_id] +page.ts: The post_id was not found in the params.post_id!!!`); + // // // error(404, { + // // // message: 'Post ID not found' + // // // }); + // // } else { + // // console.log(`ae Posts - [post_id] +page.ts: post_id = `, post_id); + // // ae_acct.slct.post_id = post_id; + // // } + + // // ae_acct.slct.post_id = post_id; + + // if (browser) { + // let load_post_obj_li = posts_func.load_ae_obj_li__post({ + // api_cfg: ae_acct.api, + // for_obj_type: 'account', + // for_obj_id: account_id, + // inc_comment_li: true, + // enabled: 'enabled', + // hidden: 'not_hidden', + // limit: 29, + // order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'updated_on': 'DESC', 'created_on': 'DESC', 'title': 'ASC'}, + // try_cache: true, + // log_lvl: log_lvl + // }); + // if (log_lvl) { + // console.log(`load_post_obj_li = `, load_post_obj_li); + // } + // ae_acct.slct.post_obj_li = load_post_obj_li; // } - // ae_acct.slct.account_id = account_id; + // // WARNING: Precaution against shared data between sites and sessions. + // data[account_id] = ae_acct; - // let post_id = params.post_id; - // let post_id = page.url.searchParams.has('post_id') ?? null; - // let post_id = page.url.searchParams.get('post_id') ?? null; - // if (!post_id) { - // console.log(`ae Posts - [post_id] +page.ts: The post_id was not found in the params.post_id!!!`); - // // error(404, { - // // message: 'Post ID not found' - // // }); - // } else { - // console.log(`ae Posts - [post_id] +page.ts: post_id = `, post_id); - // ae_acct.slct.post_id = post_id; - // } - - // ae_acct.slct.post_id = post_id; - - if (browser) { - let load_post_obj_li = posts_func.load_ae_obj_li__post({ - api_cfg: ae_acct.api, - for_obj_type: 'account', - for_obj_id: account_id, - inc_comment_li: true, - enabled: 'enabled', - hidden: 'not_hidden', - limit: 29, - order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'updated_on': 'DESC', 'created_on': 'DESC', 'title': 'ASC'}, - try_cache: true, - log_lvl: log_lvl - }); - if (log_lvl) { - console.log(`load_post_obj_li = `, load_post_obj_li); - } - ae_acct.slct.post_obj_li = load_post_obj_li; - } - - // WARNING: Precaution against shared data between sites and sessions. - data[account_id] = ae_acct; - - return data; + // return data; } diff --git a/src/routes/idaa/(idaa)/bb/+page.svelte b/src/routes/idaa/(idaa)/bb/+page.svelte index bd1644cd..a03298f1 100644 --- a/src/routes/idaa/(idaa)/bb/+page.svelte +++ b/src/routes/idaa/(idaa)/bb/+page.svelte @@ -121,54 +121,54 @@ $effect(() => { } }); -$effect(() => { - if ($idaa_trig.post_id) { - // log_lvl = 1; - $idaa_trig.post_id = false; +// $effect(() => { +// if ($idaa_trig.post_id) { +// // log_lvl = 1; +// $idaa_trig.post_id = false; - if (log_lvl) { - console.log(`Triggered: $idaa_trig.post_id`); - } +// if (log_lvl) { +// console.log(`Triggered: $idaa_trig.post_id`); +// } - $idaa_prom.load__post_obj = posts_func.load_ae_obj_id__post({ - api_cfg: $ae_api, - post_id: $idaa_slct.post_id, - enabled: $idaa_loc.bb.qry__enabled, - hidden: $idaa_loc.bb.qry__hidden, - limit: $idaa_loc.bb.qry__limit, - inc_comment_li: true, - // try_cache: true, - log_lvl: log_lvl, - }) - .then((post_obj) => { - if (log_lvl) { - console.log(`Post object loaded: `, post_obj); - } +// $idaa_prom.load__post_obj = posts_func.load_ae_obj_id__post({ +// api_cfg: $ae_api, +// post_id: $idaa_slct.post_id, +// enabled: $idaa_loc.bb.qry__enabled, +// hidden: $idaa_loc.bb.qry__hidden, +// limit: $idaa_loc.bb.qry__limit, +// inc_comment_li: true, +// // try_cache: true, +// log_lvl: log_lvl, +// }) +// .then((post_obj) => { +// if (log_lvl) { +// console.log(`Post object loaded: `, post_obj); +// } - $idaa_slct.post_obj = post_obj; - $idaa_slct.post_comment_id = null; - $idaa_slct.post_comment_obj = null; +// $idaa_slct.post_obj = post_obj; +// $idaa_slct.post_comment_id = null; +// $idaa_slct.post_comment_obj = null; - // $idaa_sess.bb.show__modal_view__post_id = $idaa_slct.post_id; - // $idaa_sess.bb.show__modal_edit__post_id = false; - }); +// // $idaa_sess.bb.show__modal_view__post_id = $idaa_slct.post_id; +// // $idaa_sess.bb.show__modal_edit__post_id = false; +// }); - // $idaa_slct.post_obj = $idaa_prom.load__post_obj; +// // $idaa_slct.post_obj = $idaa_prom.load__post_obj; - if (!page.url.searchParams.get('post_id')) { - const url = new URL(location); - // url.searchParams.set('post_id', $idaa_slct.post_id); - url.searchParams.delete('post_id'); - history.pushState({}, '', url); +// if (!page.url.searchParams.get('post_id')) { +// const url = new URL(location); +// // url.searchParams.set('post_id', $idaa_slct.post_id); +// url.searchParams.delete('post_id'); +// history.pushState({}, '', url); - let message = {'post_id': $idaa_slct.post_id}; - window.parent.postMessage(message, "*"); - } +// let message = {'post_id': $idaa_slct.post_id}; +// window.parent.postMessage(message, "*"); +// } - $idaa_sess.bb.show__modal_view__post_id = $idaa_slct.post_id; - $idaa_sess.bb.show__modal_edit__post_id = false; - } -}); +// $idaa_sess.bb.show__modal_view__post_id = $idaa_slct.post_id; +// $idaa_sess.bb.show__modal_edit__post_id = false; +// } +// }); if (browser) { diff --git a/src/routes/idaa/(idaa)/bb/+page.ts b/src/routes/idaa/(idaa)/bb/+page.ts new file mode 100644 index 00000000..04554ba9 --- /dev/null +++ b/src/routes/idaa/(idaa)/bb/+page.ts @@ -0,0 +1,42 @@ +import type { PageLoad } from './$types'; + +console.log(`ae_idaa_bulletin_board [root] +page.ts start`); + +import { error } from '@sveltejs/kit'; +import { browser } from '$app/environment'; +import { posts_func } from '$lib/ae_posts/ae_posts_functions'; + +export const load = (async ({ params, parent }) => { // route + let log_lvl: number = 0; + + let data = await parent(); + data.log_lvl = log_lvl; + + let account_id = data.account_id; + let ae_acct = data[account_id]; + + if (browser) { + let load_post_obj_li = posts_func.load_ae_obj_li__post({ + api_cfg: ae_acct.api, + for_obj_type: 'account', + for_obj_id: account_id, + inc_comment_li: true, + enabled: 'enabled', + hidden: 'not_hidden', + limit: 29, + order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'updated_on': 'DESC', 'created_on': 'DESC', 'title': 'ASC'}, + try_cache: true, + log_lvl: log_lvl + }); + if (log_lvl) { + console.log(`load_post_obj_li = `, load_post_obj_li); + } + ae_acct.slct.post_obj_li = load_post_obj_li; + } + + // WARNING: Precaution against shared data between sites and sessions. + data[account_id] = ae_acct; + + return data; + +}) satisfies PageLoad; \ No newline at end of file diff --git a/src/routes/idaa/(idaa)/bb/[post_id]/+page.svelte b/src/routes/idaa/(idaa)/bb/[post_id]/+page.svelte index a603e9e9..2899c9a3 100644 --- a/src/routes/idaa/(idaa)/bb/[post_id]/+page.svelte +++ b/src/routes/idaa/(idaa)/bb/[post_id]/+page.svelte @@ -32,6 +32,7 @@ if (log_lvl) { $idaa_sess.bb.edit__post_obj = null; $idaa_slct.post_id = ae_acct.slct.post_id; +$idaa_trig.post_id = ae_acct.slct.post_id; // $idaa_slct.post_obj = ae_acct.slct.post_obj; // Functions and Logic @@ -94,8 +95,8 @@ onDestroy(() => { let message = {'post_id': null}; window.parent.postMessage(message, "*"); - $idaa_slct.post_id = null; - $idaa_slct.post_obj = null; + // $idaa_slct.post_id = null; + // $idaa_slct.post_obj = null; }); diff --git a/src/routes/idaa/(idaa)/bb/[post_id]/+page.ts b/src/routes/idaa/(idaa)/bb/[post_id]/+page.ts index 57f1e144..f82a1800 100644 --- a/src/routes/idaa/(idaa)/bb/[post_id]/+page.ts +++ b/src/routes/idaa/(idaa)/bb/[post_id]/+page.ts @@ -2,6 +2,7 @@ import type { PageLoad } from './$types'; console.log(`ae_idaa_bulletin_board [post_id] +page.ts start`); +import { error } from '@sveltejs/kit'; import { browser } from '$app/environment'; import { posts_func } from '$lib/ae_posts/ae_posts_functions'; @@ -28,13 +29,24 @@ export const load = (async ({ params, parent }) => { // route post_id: post_id, inc_comment_li: true, log_lvl: log_lvl + }) + .then((results) => { + if (!results) { + error(404, { + message: 'IDAA BB - Post not found' + }); + } else { + // ae_acct.slct.journal_obj = results; + } }); + if (log_lvl) { console.log(`load_post_obj = `, load_post_obj); } ae_acct.slct.post_obj = load_post_obj; } + // WARNING: Precaution against shared data between sites. data[account_id] = ae_acct; return data; diff --git a/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_obj_id_edit.svelte b/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_obj_id_edit.svelte index 0194b8c8..9d094df6 100644 --- a/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_obj_id_edit.svelte +++ b/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_obj_id_edit.svelte @@ -31,6 +31,9 @@ import Comp_hosted_files_upload from '$lib/ae_core/ae_comp__hosted_files_upload. // let obj_changed = $state(false); // let orig_post_obj: any = $state(null); // let orig_post_obj: any = $state({ ...$idaa_slct.post_obj }); // Create a copy of the post object +if (!$idaa_slct.post_obj) { + $idaa_slct.post_obj = {}; +} let orig_post_obj: any = { ...$idaa_slct.post_obj }; if (browser) { // console.log(`$lq__post_obj = `, $lq__post_obj); @@ -433,7 +436,7 @@ $effect(() => { {#if $ae_loc.administrator_access} { {:else} { - {#if $idaa_slct.post_obj.linked_li_json && $idaa_slct.post_obj.linked_li_json.length} + {#if $idaa_slct.post_obj?.linked_li_json && $idaa_slct.post_obj.linked_li_json.length}
Linked files: @@ -718,7 +721,8 @@ $effect(() => { type="text" id="external_person_id" name="external_person_id" - value={($idaa_slct.post_obj.external_person_id ? $idaa_slct.post_obj.external_person_id : '')} + value={($idaa_slct.post_obj?.external_person_id ? $idaa_slct.post_obj + ?.external_person_id : '')} readonly={!$ae_loc.administrator_access} class="input w-96" > @@ -738,7 +742,7 @@ $effect(() => { type="text" id="full_name" name="full_name" - value={($idaa_slct.post_obj.full_name ? $idaa_slct.post_obj.full_name : $idaa_loc.novi_full_name)} + value={($idaa_slct.post_obj?.full_name ? $idaa_slct?.post_obj.full_name : $idaa_loc.novi_full_name)} readonly={!$ae_loc.trusted_access} class="input w-96" > @@ -757,7 +761,7 @@ $effect(() => { @@ -766,7 +770,7 @@ $effect(() => { {:else} - + {/if} diff --git a/src/routes/journals/[journal_id]/+layout.ts b/src/routes/journals/[journal_id]/+layout.ts index 812297a1..89de1fa2 100644 --- a/src/routes/journals/[journal_id]/+layout.ts +++ b/src/routes/journals/[journal_id]/+layout.ts @@ -1,6 +1,7 @@ /** @type {import('./$types').LayoutLoad} */ console.log(`ae_l_journals [journal_id] +layout.ts start`); +import { error } from '@sveltejs/kit'; import { browser } from '$app/environment'; import { journals_func } from '$lib/ae_journals/ae_journals_functions'; @@ -30,7 +31,7 @@ export async function load({ params, parent }) { console.log(`ae_journals journals [journal_id] +page.ts: journal_id = `, journal_id); } // Load event journal object - let load_journal_obj = journals_func.load_ae_obj_id__journal({ + let load_journal_obj = await journals_func.load_ae_obj_id__journal({ api_cfg: ae_acct.api, journal_id: journal_id, inc_entry_li: true, @@ -39,6 +40,21 @@ export async function load({ params, parent }) { limit: 99, try_cache: true, log_lvl: log_lvl + }) + .then((results) => { + if (!results) { + error(404, { + message: 'Journals - Journal not found' + }); + } else { + // ae_acct.slct.journal_obj = results; + } + // }) + // .catch((err) => { + // console.error(`Error loading journal object:`, err); + // error(500, { + // message: 'Journals - Error loading journal object' + // }); }); ae_acct.slct.journal_obj = load_journal_obj; diff --git a/src/routes/journals/[journal_id]/entry/[journal_entry_id]/+page.ts b/src/routes/journals/[journal_id]/entry/[journal_entry_id]/+page.ts index 832bde94..8f73858b 100644 --- a/src/routes/journals/[journal_id]/entry/[journal_entry_id]/+page.ts +++ b/src/routes/journals/[journal_id]/entry/[journal_entry_id]/+page.ts @@ -34,14 +34,20 @@ export async function load({ params, parent }) { // route console.log(`ae_journals journals [journal_entry_id] +page.ts: journal_entry_id = `, journal_entry_id); } // Load event journal entry object - let load_journal_obj = journals_func.load_ae_obj_id__journal_entry({ + let load_journal_entry_obj = journals_func.load_ae_obj_id__journal_entry({ api_cfg: ae_acct.api, journal_entry_id: journal_entry_id, try_cache: true, log_lvl: log_lvl }); - ae_acct.slct.journal_obj = load_journal_obj; + if (!load_journal_entry_obj) { + error(404, { + message: 'Journals - Journal Entry not found' + }); + } else { + ae_acct.slct.journal_obj = load_journal_entry_obj; + } } // WARNING: Precaution against shared data between sites.