Working on IDAA BB Post Comment notifications and related.
This commit is contained in:
@@ -1,9 +1,25 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { preventDefault } from 'svelte/legacy';
|
interface Props {
|
||||||
|
log_lvl?: number;
|
||||||
|
lq__post_obj: any;
|
||||||
|
lq__post_comment_obj: any;
|
||||||
|
lq__post_comment_obj_li?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
let {
|
||||||
|
log_lvl = $bindable(1),
|
||||||
|
lq__post_obj,
|
||||||
|
lq__post_comment_obj,
|
||||||
|
lq__post_comment_obj_li
|
||||||
|
}: Props = $props();
|
||||||
|
|
||||||
|
// *** Import Svelte specific
|
||||||
// import { createEventDispatcher, onDestroy, onMount } from 'svelte';
|
// import { createEventDispatcher, onDestroy, onMount } from 'svelte';
|
||||||
import { fade } from 'svelte/transition';
|
import { fade } from 'svelte/transition';
|
||||||
|
|
||||||
|
// *** Import other supporting libraries
|
||||||
|
|
||||||
|
// *** Import Aether specific variables and functions
|
||||||
import type { key_val } from '$lib/ae_stores';
|
import type { key_val } from '$lib/ae_stores';
|
||||||
import { ae_util } from '$lib/ae_utils/ae_utils';
|
import { ae_util } from '$lib/ae_utils/ae_utils';
|
||||||
// import { core_func } from '$lib/ae_core/ae_core_functions';
|
// import { core_func } from '$lib/ae_core/ae_core_functions';
|
||||||
@@ -13,19 +29,22 @@ import { idaa_loc, idaa_sess, idaa_slct } from '$lib/ae_idaa_stores';
|
|||||||
import { posts_func } from '$lib/ae_posts/ae_posts_functions';
|
import { posts_func } from '$lib/ae_posts/ae_posts_functions';
|
||||||
import Tiptap_editor from '$lib/element_tiptap_editor.svelte';
|
import Tiptap_editor from '$lib/element_tiptap_editor.svelte';
|
||||||
|
|
||||||
interface Props {
|
|
||||||
log_lvl?: number;
|
|
||||||
lq__post_obj: any;
|
|
||||||
lq__post_comment_obj: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
let { log_lvl = $bindable(2), lq__post_obj, lq__post_comment_obj }: Props = $props();
|
|
||||||
|
|
||||||
let prom_api__post_comment_obj: any = $state();
|
let prom_api__post_comment_obj: any = $state();
|
||||||
|
|
||||||
|
let content_new_html = $state('');
|
||||||
|
let content_changed = $state(false);
|
||||||
|
// let notes_new_html = $state('');
|
||||||
|
// let notes_changed = $state(false);
|
||||||
let disable_submit_btn = $state(false);
|
let disable_submit_btn = $state(false);
|
||||||
|
|
||||||
|
|
||||||
|
function preventDefault(fn) {
|
||||||
|
return function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
fn.call(this, event);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
async function handle_submit_form(event: any) {
|
async function handle_submit_form(event: any) {
|
||||||
if (log_lvl > 1) {
|
if (log_lvl > 1) {
|
||||||
console.log('*** handle_submit_form() ***', event.target);
|
console.log('*** handle_submit_form() ***', event.target);
|
||||||
@@ -55,9 +74,9 @@ async function handle_submit_form(event: any) {
|
|||||||
// post_comment_do['title'] = post_comment_di.title;
|
// post_comment_do['title'] = post_comment_di.title;
|
||||||
|
|
||||||
// Check if the content_new_html exists and is a string
|
// Check if the content_new_html exists and is a string
|
||||||
if (typeof $idaa_slct.post_comment_obj.content_new_html === 'string') {
|
if (typeof content_new_html === 'string') {
|
||||||
console.log('New content is a string');
|
console.log('New content is a string');
|
||||||
post_comment_do['content'] = $idaa_slct.post_comment_obj.content_new_html;
|
post_comment_do['content'] = content_new_html;
|
||||||
} else {
|
} else {
|
||||||
console.log('New content is not a string. Do nothing.');
|
console.log('New content is not a string. Do nothing.');
|
||||||
// post_comment_do['content'] = event_meeting_fd.content;
|
// post_comment_do['content'] = event_meeting_fd.content;
|
||||||
@@ -106,41 +125,62 @@ async function handle_submit_form(event: any) {
|
|||||||
|
|
||||||
if (!$idaa_slct.post_comment_id) {
|
if (!$idaa_slct.post_comment_id) {
|
||||||
|
|
||||||
prom_api__post_comment_obj = posts_func.create_ae_obj__post_comment({
|
prom_api__post_comment_obj = await posts_func.create_ae_obj__post_comment({
|
||||||
api_cfg: $ae_api,
|
api_cfg: $ae_api,
|
||||||
post_id: $idaa_slct.post_id,
|
post_id: $idaa_slct.post_id,
|
||||||
data_kv: post_comment_do,
|
data_kv: post_comment_do,
|
||||||
log_lvl: log_lvl
|
log_lvl: log_lvl
|
||||||
})
|
})
|
||||||
.then(function (post_comment_obj_create_result) {
|
// .then(function (post_comment_obj_create_result) {
|
||||||
if (!post_comment_obj_create_result) {
|
// if (!post_comment_obj_create_result) {
|
||||||
console.log('The result was null or false.');
|
// console.log('The result was null or false.');
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
|
||||||
$idaa_slct.post_comment_id = post_comment_obj_create_result.post_comment_id_random;
|
// $idaa_slct.post_comment_id = post_comment_obj_create_result.post_comment_id_random;
|
||||||
$idaa_slct.post_comment_obj = post_comment_obj_create_result;
|
// $idaa_slct.post_comment_obj = post_comment_obj_create_result;
|
||||||
|
|
||||||
return post_comment_obj_create_result;
|
// return post_comment_obj_create_result;
|
||||||
})
|
// })
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
console.log('Something went wrong.');
|
console.log('Something went wrong.');
|
||||||
console.log(error);
|
console.log(error);
|
||||||
return false;
|
return false;
|
||||||
})
|
// })
|
||||||
.finally(async () => {
|
// .finally(async () => {
|
||||||
disable_submit_btn = false;
|
|
||||||
$idaa_sess.bb.show__inline_edit__post_comment_id = false;
|
|
||||||
|
|
||||||
if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_new_email) {
|
|
||||||
send_staff_notification_email();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_poster_email && $idaa_slct.post_obj.notify) {
|
|
||||||
send_poster_notification_email();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$idaa_slct.post_comment_id = prom_api__post_comment_obj.post_comment_id_random;
|
||||||
|
$idaa_slct.post_comment_obj = prom_api__post_comment_obj;
|
||||||
|
|
||||||
|
disable_submit_btn = false;
|
||||||
|
$idaa_sess.bb.show__inline_edit__post_comment_id = false;
|
||||||
|
|
||||||
|
// Send notification to staff
|
||||||
|
if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_new_email) {
|
||||||
|
send_staff_notification_email();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send notification to the original poster
|
||||||
|
if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_poster_email && $idaa_slct.post_obj.notify) {
|
||||||
|
send_poster_notification_email();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send a notification to any other post commenters
|
||||||
|
console.log(`Sending notification email to post commenters...: ${$lq__post_comment_obj_li?.length}`);
|
||||||
|
if ($lq__post_comment_obj_li && $lq__post_comment_obj_li.length > 0) {
|
||||||
|
for (const post_comment of $lq__post_comment_obj_li) {
|
||||||
|
console.log('Post Comment ID:', post_comment.post_comment_id);
|
||||||
|
if (post_comment.post_comment_id !== $idaa_slct.post_comment_id) {
|
||||||
|
console.log('Sending notification email to post commenter:', post_comment.full_name);
|
||||||
|
// send_poster_commenters_notification_email({
|
||||||
|
// post_comment_obj: post_comment,
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return prom_api__post_comment_obj;
|
return prom_api__post_comment_obj;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -280,6 +320,7 @@ function send_staff_notification_email() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function send_poster_notification_email() {
|
function send_poster_notification_email() {
|
||||||
|
log_lvl = 1;
|
||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
console.log(`*** send_poster_notification_email() *** Post ID: ${$idaa_slct.post_id}`);
|
console.log(`*** send_poster_notification_email() *** Post ID: ${$idaa_slct.post_id}`);
|
||||||
}
|
}
|
||||||
@@ -314,6 +355,48 @@ function send_poster_notification_email() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function send_poster_commenters_notification_email(
|
||||||
|
{
|
||||||
|
post_comment_obj = $idaa_slct.post_comment_obj
|
||||||
|
}: {
|
||||||
|
post_comment_obj?: any
|
||||||
|
} = {}
|
||||||
|
) {
|
||||||
|
log_lvl = 1;
|
||||||
|
if (log_lvl) {
|
||||||
|
console.log(`*** send_poster_commenters_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 = `
|
||||||
|
<div>${post_comment_obj.full_name ?? '-- not set --'},
|
||||||
|
<p>The BB post named "${$idaa_slct.post_obj.title ?? '-- not set --'}" has been commented on.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<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="${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_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: $idaa_slct.post_obj.email,
|
||||||
|
// to_email: 'scott+idaabb@oneskyit.com',
|
||||||
|
to_name: $idaa_slct.post_obj.full_name ?? 'IDAA BB Post Commenter',
|
||||||
|
subject: subject,
|
||||||
|
body_html: body_html,
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
@@ -376,9 +459,10 @@ function send_poster_notification_email() {
|
|||||||
|
|
||||||
<Tiptap_editor
|
<Tiptap_editor
|
||||||
default_minimal={true}
|
default_minimal={true}
|
||||||
bind:html_text={$idaa_slct.post_comment_obj.content}
|
html_text={$idaa_slct.post_comment_obj?.content}
|
||||||
show_button_kv={{'heading__h1': false, 'heading__h2': false, 'heading__h3': false}}
|
show_button_kv={{'heading__h1': false, 'heading__h2': false, 'heading__h3': false}}
|
||||||
bind:new_html={$idaa_slct.post_comment_obj.content_new_html}
|
bind:new_html={content_new_html}
|
||||||
|
bind:changed={content_changed}
|
||||||
classes="bg-gray-100 dark:bg-gray-800"
|
classes="bg-gray-100 dark:bg-gray-800"
|
||||||
placeholder="Your post content here..."
|
placeholder="Your post content here..."
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -247,12 +247,15 @@ $effect(() => {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onclick={() => {
|
onclick={() => {
|
||||||
if (confirm('Are you sure you want to add a new comment?')) {
|
if (!confirm('Are you sure you want to add a new comment?')) {
|
||||||
$idaa_slct.post_comment_id = null;
|
return;
|
||||||
$idaa_slct.post_comment_obj = {};
|
|
||||||
|
|
||||||
$idaa_sess.bb.show__inline_edit__post_comment_id = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$idaa_slct.post_comment_id = null;
|
||||||
|
$idaa_slct.post_comment_obj = {};
|
||||||
|
|
||||||
|
$idaa_sess.bb.show__inline_edit__post_comment_id = true;
|
||||||
|
|
||||||
}}
|
}}
|
||||||
class="
|
class="
|
||||||
novi_btn btn-primary
|
novi_btn btn-primary
|
||||||
@@ -301,6 +304,7 @@ $effect(() => {
|
|||||||
<Comp__post_comment_obj_id_edit
|
<Comp__post_comment_obj_id_edit
|
||||||
lq__post_obj={lq__post_obj}
|
lq__post_obj={lq__post_obj}
|
||||||
lq__post_comment_obj={lq__post_comment_obj}
|
lq__post_comment_obj={lq__post_comment_obj}
|
||||||
|
lq__post_comment_obj_li={lq__post_comment_obj_li}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
@@ -315,9 +319,11 @@ $effect(() => {
|
|||||||
>
|
>
|
||||||
|
|
||||||
{#if $idaa_sess.bb.show__inline_edit__post_comment_id == post_comment_obj.post_comment_id}
|
{#if $idaa_sess.bb.show__inline_edit__post_comment_id == post_comment_obj.post_comment_id}
|
||||||
|
{$lq__post_comment_obj_li.length ?? 'unknown???'}
|
||||||
<Comp__post_comment_obj_id_edit
|
<Comp__post_comment_obj_id_edit
|
||||||
lq__post_obj={lq__post_obj}
|
lq__post_obj={lq__post_obj}
|
||||||
lq__post_comment_obj={lq__post_comment_obj}
|
lq__post_comment_obj={lq__post_comment_obj}
|
||||||
|
lq__post_comment_obj_li={lq__post_comment_obj_li}
|
||||||
/>
|
/>
|
||||||
{:else}
|
{:else}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user