From c62507d4845cb9e898ab66d98d3e431f34e69307 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Tue, 28 Jan 2025 11:51:27 -0500 Subject: [PATCH] Sort of bug fix and improvements for IDAA BB notifications and loading a post based on the URL param. --- src/lib/ae_idaa_stores.ts | 6 +++++ src/lib/ae_posts/ae_posts__post.ts | 8 +++--- src/lib/ae_posts/ae_posts__post_comment.ts | 6 ++--- src/routes/idaa/(idaa)/bb/+layout.ts | 16 +++++++++++ src/routes/idaa/(idaa)/bb/+page.svelte | 27 +++++++++++++++++++ ...idaa_comp__post_comment_obj_id_edit.svelte | 8 ++++-- .../bb/ae_idaa_comp__post_obj_id_edit.svelte | 10 +++++-- static/idaa_novi_iframe_bulletin_board.html | 2 +- 8 files changed, 71 insertions(+), 12 deletions(-) diff --git a/src/lib/ae_idaa_stores.ts b/src/lib/ae_idaa_stores.ts index 604447ea..8e733ac2 100644 --- a/src/lib/ae_idaa_stores.ts +++ b/src/lib/ae_idaa_stores.ts @@ -31,6 +31,10 @@ let idaa_local_data_struct: key_val = { "58db22ee-4b0a-49a7-9f34-53d2ba85a84b", ], + novi_archives_base_url: "https://www.idaa.org/idaa-archives", + novi_bb_base_url: "https://www.idaa.org/idaa-bulletin-board", + novi_meetings_base_url: "https://www.idaa.org/idaa-meetings", + 'ds': {}, 'idaa_cfg_json': {}, @@ -158,6 +162,7 @@ let idaa_trig_template: key_val = { archive_id: false, archive_content_li: false, event_id: false, + post_id: false, }; export let idaa_trig: any = writable(idaa_trig_template); // console.log(`AE IDAA Stores - IDAA Trigger:`, idaa_trig); @@ -170,6 +175,7 @@ let idaa_prom_template: key_val = { archive_id: false, archive_content_li: false, event_id: false, + post_id: false, }; export let idaa_prom: any = writable(idaa_prom_template); // console.log(`AE IDAA Stores - IDAA Trigger:`, idaa_prom); diff --git a/src/lib/ae_posts/ae_posts__post.ts b/src/lib/ae_posts/ae_posts__post.ts index bad9170b..6ea2d0a3 100644 --- a/src/lib/ae_posts/ae_posts__post.ts +++ b/src/lib/ae_posts/ae_posts__post.ts @@ -41,9 +41,9 @@ export async function load_ae_obj_id__post( ae_promises.load__post_obj = await api.get_ae_obj_id_crud({ api_cfg: api_cfg, obj_type: 'post', - obj_id: post_id, // NOTE: This is the FQDN, not normally the ID. - use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. - use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config. + obj_id: post_id, + use_alt_table: true, + use_alt_base: false, params: params, log_lvl: log_lvl }) @@ -71,7 +71,7 @@ export async function load_ae_obj_id__post( console.log('ae_promises.load__post_obj:', ae_promises.load__post_obj); } - if (inc_comment_li) { + if (inc_comment_li && ae_promises.load__post_obj) { // Load the comments for the post if (log_lvl) { console.log(`Need to load the comment list for the post now`); diff --git a/src/lib/ae_posts/ae_posts__post_comment.ts b/src/lib/ae_posts/ae_posts__post_comment.ts index aad42bb9..ebaa9c38 100644 --- a/src/lib/ae_posts/ae_posts__post_comment.ts +++ b/src/lib/ae_posts/ae_posts__post_comment.ts @@ -37,9 +37,9 @@ export async function load_ae_obj_id__post_comment( ae_promises.load__post_comment_obj = await api.get_ae_obj_id_crud({ api_cfg: api_cfg, obj_type: 'post_comment', - obj_id: post_comment_id, // NOTE: This is the FQDN, not normally the ID. - use_alt_table: false, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. - use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value + obj_id: post_comment_id, + use_alt_table: false, + use_alt_base: false, params: params, log_lvl: log_lvl }) diff --git a/src/routes/idaa/(idaa)/bb/+layout.ts b/src/routes/idaa/(idaa)/bb/+layout.ts index 8b460bc2..e71bc916 100644 --- a/src/routes/idaa/(idaa)/bb/+layout.ts +++ b/src/routes/idaa/(idaa)/bb/+layout.ts @@ -3,6 +3,7 @@ console.log(`IDAA BB - [account_id] +layout.ts start`); import { error } from '@sveltejs/kit'; import { browser } from '$app/environment'; +// import { page } from '$app/state'; import { posts_func } from '$lib/ae_posts/ae_posts_functions'; export async function load({ params, parent }) { // route @@ -24,6 +25,21 @@ export async function load({ params, parent }) { // route 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, diff --git a/src/routes/idaa/(idaa)/bb/+page.svelte b/src/routes/idaa/(idaa)/bb/+page.svelte index dc9c946f..e4b8b4ea 100644 --- a/src/routes/idaa/(idaa)/bb/+page.svelte +++ b/src/routes/idaa/(idaa)/bb/+page.svelte @@ -25,6 +25,18 @@ import Comp__post_obj_id_view from './ae_idaa_comp__post_obj_id_view.svelte'; import Comp__post_options from './ae_idaa_comp__post_options.svelte'; +import { page } from '$app/state'; + +let post_id = page.url.searchParams.get('post_id') ?? null; +if (!post_id) { + $idaa_slct.post_id = null; +} else { + console.log(`ae Posts - [post_id] +page.ts: post_id = `, post_id); + $idaa_slct.post_id = post_id; + $idaa_trig.post_id = post_id; +} + + $: lq__post_obj_li = liveQuery(async () => { let results = await db_posts.post .where('account_id') @@ -103,6 +115,7 @@ $: if ($idaa_trig.post_li) { } $: if ($idaa_trig.post_id) { + // log_lvl = 1; $idaa_trig.post_id = false; if (log_lvl) { @@ -119,6 +132,20 @@ $: if ($idaa_trig.post_id) { try_cache: true, log_lvl: log_lvl, }); + + $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); + history.pushState({}, '', url); + + 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; } diff --git a/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_comment_obj_id_edit.svelte b/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_comment_obj_id_edit.svelte index ae8348b2..35551c8e 100644 --- a/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_comment_obj_id_edit.svelte +++ b/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_comment_obj_id_edit.svelte @@ -220,6 +220,8 @@ function send_staff_notification_email() { console.log(`*** send_staff_notification_email() *** Post ID: ${$idaa_slct.post_id}`); } + let link_base_url = $ae_loc.site_cfg_json.novi_bb_base_url ?? `${$ae_loc.url_origin}/idaa/bb`; + let subject = `IDAA BB Post Comment on: ${$idaa_slct.post_obj.title ?? '-- not set --'} (ID: ${$idaa_slct.post_id})`; let body_html = ` @@ -244,7 +246,7 @@ function send_staff_notification_email() {
IDAA BB Post ID: ${$idaa_slct.post_id}

Use this link to view the post.
- Copy and paste link: ${$ae_loc.url_origin}/idaa/bb?post_id=${$idaa_slct.post_id}

+ Copy and paste link: ${link_base_url}?post_id=${$idaa_slct.post_id}

`; api.send_email({ @@ -263,6 +265,8 @@ function send_poster_notification_email() { console.log(`*** send_poster_notification_email() *** Post ID: ${$idaa_slct.post_id}`); } + let link_base_url = $ae_loc.site_cfg_json.novi_bb_base_url ?? `${$ae_loc.url_origin}/idaa/bb`; + let subject = `IDAA BB Post Comment on: ${$idaa_slct.post_obj.title ?? '-- not set --'} (ID: ${$idaa_slct.post_id})`; let body_html = ` @@ -275,7 +279,7 @@ function send_poster_notification_email() {
IDAA BB Post ID: ${$idaa_slct.post_id}

Use this link to view the post.
- Copy and paste link: ${$ae_loc.url_origin}/idaa/bb?post_id=${$idaa_slct.post_id}

+ Copy and paste link: ${link_base_url}?post_id=${$idaa_slct.post_id}

`; api.send_email({ 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 f42e13cb..aae6cdad 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 @@ -110,6 +110,8 @@ async function handle_submit_form(event: any) { console.log(post_do); + log_lvl = 1; + if (!$idaa_slct.post_id) { prom_api__post_obj = posts_func.create_ae_obj__post({ api_cfg: $ae_api, @@ -270,6 +272,8 @@ function send_staff_notification_email() { console.log(`*** send_staff_notification_email() *** Post ID: ${$idaa_slct.post_id}`); } + let link_base_url = $ae_loc.site_cfg_json.novi_bb_base_url ?? `${$ae_loc.url_origin}/idaa/bb`; + let subject = `IDAA BB Post: ${$idaa_slct.post_obj.title} (ID: ${$idaa_slct.post_id})`; let body_html = ` @@ -288,14 +292,16 @@ function send_staff_notification_email() {
IDAA BB Post ID: ${$idaa_slct.post_id}

Use this link to view the post.
- Copy and paste link: ${$ae_loc.url_origin}/idaa/bb?post_id=${$idaa_slct.post_id}

+ Copy and paste link: ${link_base_url}?post_id=${$idaa_slct.post_id}

`; api.send_email({ api_cfg: $ae_api, from_email: $ae_loc.site_cfg_json?.noreply_email ?? 'noreply+idaabb@oneskyit.com', + // from_email: 'noreply+idaabb@oneskyit.com', from_name: $ae_loc.site_cfg_json?.noreply_name ?? 'IDAA BB NoReply', - to_email: $ae_loc.site_cfg_json?.admin_email ?? 'admin+bbpost@oneskyit.com', // 'scott+idaabb@oneskyit.com' + to_email: $ae_loc.site_cfg_json?.admin_email ?? 'admin+bbpost@oneskyit.com', + // to_email: 'test+idaabb@oneskyit.com', // 'scott+idaabb@oneskyit.com' to_name: $ae_loc.site_cfg_json?.admin_name ?? 'IDAA BB Admin', subject: subject, body_html: body_html, diff --git a/static/idaa_novi_iframe_bulletin_board.html b/static/idaa_novi_iframe_bulletin_board.html index 5e16200b..aaa73391 100644 --- a/static/idaa_novi_iframe_bulletin_board.html +++ b/static/idaa_novi_iframe_bulletin_board.html @@ -52,7 +52,7 @@ fetch(novi_api_get_customer_endpoint, requestOptions) let idaa_ae_iframe_element = document.getElementById('ae_idaa_bb_iframe'); if (idaa_ae_slct_post_id) { - // console.log(`Loading AE Post ID: ${idaa_ae_slct_post_id}`); + console.log(`Loading AE Post ID: ${idaa_ae_slct_post_id}`); idaa_ae_iframe_element.src = `${idaa_ae_api_root_url}?uuid=${novi_customer_uid}&email=${novi_current_user_obj.Email}&full_name=${novi_current_user_obj.Name}&post_id=${idaa_ae_slct_post_id}&iframe=true&key=${idaa_osit_site_key}`; } else { idaa_ae_iframe_element.src = `${idaa_ae_api_root_url}?uuid=${novi_customer_uid}&email=${novi_current_user_obj.Email}&full_name=${novi_current_user_obj.Name}&iframe=true&key=${idaa_osit_site_key}`;