Sort of bug fix and improvements for IDAA BB notifications and loading a post based on the URL param.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -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() {
|
||||
<div>
|
||||
IDAA BB Post ID: ${$idaa_slct.post_id}<br>
|
||||
<p>Use this link to view the post.<br>
|
||||
Copy and paste link: <a href="${$ae_loc.url_origin}/idaa/bb?post_id=${$idaa_slct.post_id}">${$ae_loc.url_origin}/idaa/bb?post_id=${$idaa_slct.post_id}</a></p>
|
||||
Copy and paste link: <a href="${link_base_url}?post_id=${$idaa_slct.post_id}">${link_base_url}?post_id=${$idaa_slct.post_id}</a></p>
|
||||
</div>`;
|
||||
|
||||
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() {
|
||||
<div>
|
||||
IDAA BB Post ID: ${$idaa_slct.post_id}<br>
|
||||
<p>Use this link to view the post.<br>
|
||||
Copy and paste link: <a href="${$ae_loc.url_origin}/idaa/bb?post_id=${$idaa_slct.post_id}">${$ae_loc.url_origin}/idaa/bb?post_id=${$idaa_slct.post_id}</a></p>
|
||||
Copy and paste link: <a href="${link_base_url}?post_id=${$idaa_slct.post_id}">${link_base_url}?post_id=${$idaa_slct.post_id}</a></p>
|
||||
</div>`;
|
||||
|
||||
api.send_email({
|
||||
|
||||
@@ -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() {
|
||||
<div>
|
||||
IDAA BB Post ID: ${$idaa_slct.post_id}<br>
|
||||
<p>Use this link to view the post.<br>
|
||||
Copy and paste link: <a href="${$ae_loc.url_origin}/idaa/bb?post_id=${$idaa_slct.post_id}">${$ae_loc.url_origin}/idaa/bb?post_id=${$idaa_slct.post_id}</a></p>
|
||||
Copy and paste link: <a href="${link_base_url}?post_id=${$idaa_slct.post_id}">${link_base_url}?post_id=${$idaa_slct.post_id}</a></p>
|
||||
</div>`;
|
||||
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user