Bug fix for saving a post comment and the post data not being ready.

This commit is contained in:
Scott Idem
2025-03-04 12:26:45 -05:00
parent 7e92613536
commit 33bc99c2bd
4 changed files with 159 additions and 125 deletions

View File

@@ -364,7 +364,7 @@ if (browser) {
// Check if in the array of: super > manager > administrator > trusted > public > authenticated > anonymous // Check if in the array of: super > manager > administrator > trusted > public > authenticated > anonymous
const access_type_li = ['super', 'manager', 'administrator', 'trusted', 'public', 'authenticated', 'anonymous']; const access_type_li = ['super', 'manager', 'administrator', 'trusted', 'public', 'authenticated', 'anonymous'];
$effect(() => { $effect(() => {
if (browser && $ae_loc.access_type && access_type_li.includes($ae_loc.access_type)) { if (browser && $ae_loc.access_type && access_type_li.includes($ae_loc.access_type)) {
document.getElementsByTagName('html')[0].classList.remove('super_access', 'manager_access', 'administrator_access', 'trusted_access', 'public_access', 'authenticated_access', 'anonymous_access'); document.getElementsByTagName('html')[0].classList.remove('super_access', 'manager_access', 'administrator_access', 'trusted_access', 'public_access', 'authenticated_access', 'anonymous_access');
document.getElementsByTagName('html')[0].classList.add(`${$ae_loc.access_type}_access`); document.getElementsByTagName('html')[0].classList.add(`${$ae_loc.access_type}_access`);
} else if (browser) { } else if (browser) {

View File

@@ -1,6 +1,14 @@
<script lang="ts"> <script lang="ts">
/** @type {import('./$types').PageData} */ import { run } from 'svelte/legacy';
export let data: any;
import { page } from '$app/state';
interface Props {
/** @type {import('./$types').PageData} */
data: any;
}
let { data }: Props = $props();
let log_lvl: number = 0; let log_lvl: number = 0;
if (log_lvl) { if (log_lvl) {
console.log(`ae_idaa_bb +page.svelte data:`, data); console.log(`ae_idaa_bb +page.svelte data:`, data);
@@ -25,8 +33,6 @@ 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 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; let post_id = page.url.searchParams.get('post_id') ?? null;
if (!post_id) { if (!post_id) {
$idaa_slct.post_id = null; $idaa_slct.post_id = null;
@@ -37,7 +43,7 @@ if (!post_id) {
} }
$: lq__post_obj_li = liveQuery(async () => { let lq__post_obj_li = $derived(liveQuery(async () => {
let results = await db_posts.post let results = await db_posts.post
.where('account_id') .where('account_id')
.equals($slct.account_id) .equals($slct.account_id)
@@ -51,16 +57,16 @@ $: lq__post_obj_li = liveQuery(async () => {
// .sortBy('[created_on+updated_on]'); // .sortBy('[created_on+updated_on]');
return results; return results;
}); }));
$: lq__post_obj = liveQuery(async () => { let lq__post_obj = $derived(liveQuery(async () => {
let results = await db_posts.post let results = await db_posts.post
.get($idaa_slct.post_id ?? ''); // null or undefined does not reset things like '' does .get($idaa_slct.post_id ?? ''); // null or undefined does not reset things like '' does
return results; return results;
}); }));
$: lq__post_comment_obj_li = liveQuery(async () => { let lq__post_comment_obj_li = $derived(liveQuery(async () => {
let results = await db_posts.comment let results = await db_posts.comment
.where('post_id') .where('post_id')
.equals($idaa_slct.post_id ?? '') // null or undefined does not reset things like '' does .equals($idaa_slct.post_id ?? '') // null or undefined does not reset things like '' does
@@ -69,84 +75,100 @@ $: lq__post_comment_obj_li = liveQuery(async () => {
// .sortBy('title'); // .sortBy('title');
return results; return results;
}); }));
$: lq__post_comment_obj = liveQuery(async () => { let lq__post_comment_obj = $derived(liveQuery(async () => {
let results = await db_posts.comment let results = await db_posts.comment
.get($idaa_slct.post_comment_id ?? ''); // null or undefined does not reset things like '' does .get($idaa_slct.post_comment_id ?? ''); // null or undefined does not reset things like '' does
return results; return results;
}));
$effect(() => {
if ($idaa_trig.post_li) {
$idaa_trig.post_li = false;
if (log_lvl) {
console.log(`Triggered: $idaa_trig.post_li`);
}
// This may need to be rethought... For now things are cleared if query is anything but 'all' for enabled and hidden.
if ($idaa_loc.bb.qry__enabled !== 'all' || $idaa_loc.bb.qry__hidden !== 'all' || $idaa_loc.bb.qry__limit < 50) {
console.log(`Deleting disabled or hidden post.`);
let results = db_posts.post
.clear();
console.log(`Deleted ${results} disabled post.`);
console.log(`Deleting disabled or hidden post comments.`);
results = db_posts.comment
.clear();
console.log(`Deleted ${results} disabled post comments.`);
}
$idaa_prom.load__post_obj_li = posts_func.load_ae_obj_li__post({
api_cfg: $ae_api,
for_obj_type: 'account',
for_obj_id: $idaa_slct.account_id,
inc_comment_li: true,
enabled: $idaa_loc.bb.qry__enabled,
hidden: $idaa_loc.bb.qry__hidden,
limit: $idaa_loc.bb.qry__limit,
order_by_li: $idaa_loc.bb.qry__order_by_li,
try_cache: true,
log_lvl: log_lvl,
});
}
}); });
$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 ($idaa_trig.post_li) { $idaa_prom.load__post_obj = posts_func.load_ae_obj_id__post({
$idaa_trig.post_li = false; 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);
}
if (log_lvl) { $idaa_slct.post_obj = post_obj;
console.log(`Triggered: $idaa_trig.post_li`); $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_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;
} }
});
// This may need to be rethought... For now things are cleared if query is anything but 'all' for enabled and hidden.
if ($idaa_loc.bb.qry__enabled !== 'all' || $idaa_loc.bb.qry__hidden !== 'all' || $idaa_loc.bb.qry__limit < 50) {
console.log(`Deleting disabled or hidden post.`);
let results = db_posts.post
.clear();
console.log(`Deleted ${results} disabled post.`);
console.log(`Deleting disabled or hidden post comments.`);
results = db_posts.comment
.clear();
console.log(`Deleted ${results} disabled post comments.`);
}
$idaa_prom.load__post_obj_li = posts_func.load_ae_obj_li__post({
api_cfg: $ae_api,
for_obj_type: 'account',
for_obj_id: $idaa_slct.account_id,
inc_comment_li: true,
enabled: $idaa_loc.bb.qry__enabled,
hidden: $idaa_loc.bb.qry__hidden,
limit: $idaa_loc.bb.qry__limit,
order_by_li: $idaa_loc.bb.qry__order_by_li,
try_cache: true,
log_lvl: log_lvl,
});
}
$: if ($idaa_trig.post_id) {
// log_lvl = 1;
$idaa_trig.post_id = false;
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,
});
$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> </script>
@@ -177,7 +199,7 @@ $: if ($idaa_trig.post_id) {
<!-- <h1>Bulletin Board {$lq__post_obj_li?.length}</h1> --> <!-- <h1>Bulletin Board {$lq__post_obj_li?.length}</h1> -->
{#if $lq__post_obj_li && $lq__post_obj_li?.length } {#if $lq__post_obj_li && $lq__post_obj_li?.length}
<Comp__post_obj_li <Comp__post_obj_li
lq__post_obj_li={lq__post_obj_li} lq__post_obj_li={lq__post_obj_li}
/> />
@@ -204,13 +226,14 @@ $: if ($idaa_trig.post_id) {
}} }}
> >
<svelte:fragment slot="header"> {#snippet header()}
<div class="flex flex-row items-center justify-between w-full">
<h3 class="text-lg font-semibold"> <div class="flex flex-row items-center justify-between w-full">
{#if $ae_loc.trusted_access || $lq__post_obj?.external_person_id === $idaa_loc.novi_uuid} <h3 class="text-lg font-semibold">
<button {#if $ae_loc.trusted_access || $lq__post_obj?.external_person_id === $idaa_loc.novi_uuid}
on:click={() => { <button
onclick={() => {
// const url = new URL(location); // const url = new URL(location);
// url.searchParams.set('post_id', $lq__post_obj?.post_id_random); // url.searchParams.set('post_id', $lq__post_obj?.post_id_random);
// history.pushState({}, '', url); // history.pushState({}, '', url);
@@ -222,26 +245,27 @@ $: if ($idaa_trig.post_id) {
$idaa_sess.bb.show__inline_edit__post_obj = true; $idaa_sess.bb.show__inline_edit__post_obj = true;
} }
}} }}
class="novi_btn btn btn-sm variant-ghost-warning hover:variant-filled-warning transition" class="novi_btn btn btn-sm variant-ghost-warning hover:variant-filled-warning transition"
title={`Edit meeting: ${$lq__post_obj?.title}`} title={`Edit meeting: ${$lq__post_obj?.title}`}
> >
{#if $idaa_sess.bb.show__inline_edit__post_obj} {#if $idaa_sess.bb.show__inline_edit__post_obj}
<span class="fas fa-times m-1"></span> Cancel Edit <span class="fas fa-times m-1"></span> Cancel Edit
{:else} {:else}
<span class="fas fa-edit m-1"></span> Edit <span class="fas fa-edit m-1"></span> Edit
{/if} {/if}
</button> </button>
{/if} {/if}
<!-- {$lq__post_obj?.title ?? 'New Post'} --> <!-- {$lq__post_obj?.title ?? 'New Post'} -->
<span class=""> <span class="">
<span class="fas fa-comment-alt m-1"></span> <span class="fas fa-comment-alt m-1"></span>
{@html $lq__post_obj?.title ?? 'New Post'} {@html $lq__post_obj?.title ?? 'New Post'}
<!-- - {$lq__post_obj?.id ?? 'Not Yet Saved'} --> <!-- - {$lq__post_obj?.id ?? 'Not Yet Saved'} -->
</span> </span>
{#if $lq__post_obj?.topic_id}<span class="badge badge-info variant-glass-secondary"><span class="fas fa-user-md m-1"></span> {$lq__post_obj?.topic_name}</span>{/if} {#if $lq__post_obj?.topic_id}<span class="badge badge-info variant-glass-secondary"><span class="fas fa-user-md m-1"></span> {$lq__post_obj?.topic_name}</span>{/if}
</h3> </h3>
</div> </div>
</svelte:fragment>
{/snippet}
<Comp__post_obj_id_view <Comp__post_obj_id_view
lq__post_obj={lq__post_obj} lq__post_obj={lq__post_obj}

View File

@@ -1,5 +1,6 @@
<script lang="ts"> <script lang="ts">
export let log_lvl: number = 0; import { preventDefault } from 'svelte/legacy';
// import { createEventDispatcher, onDestroy, onMount } from 'svelte'; // import { createEventDispatcher, onDestroy, onMount } from 'svelte';
import { fade } from 'svelte/transition'; import { fade } from 'svelte/transition';
@@ -12,17 +13,24 @@ 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';
export let lq__post_obj: any; interface Props {
export let lq__post_comment_obj: any; log_lvl?: number;
lq__post_obj: any;
lq__post_comment_obj: any;
}
let prom_api__post_comment_obj: any; let { log_lvl = $bindable(2), lq__post_obj, lq__post_comment_obj }: Props = $props();
let disable_submit_btn = false; let prom_api__post_comment_obj: any = $state();
let disable_submit_btn = $state(false);
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);
console.log($lq__post_obj);
console.log($lq__post_comment_obj);
} }
disable_submit_btn = true; disable_submit_btn = true;
@@ -217,7 +225,7 @@ async function handle_delete_post_comment_obj(
function send_staff_notification_email() { function send_staff_notification_email() {
log_lvl = 2; log_lvl = 1;
if (log_lvl) { if (log_lvl) {
console.log(`*** send_staff_notification_email() *** Post ID: ${$idaa_slct.post_id} Post Title: ${$idaa_slct?.post_obj?.title}`); console.log(`*** send_staff_notification_email() *** Post ID: ${$idaa_slct.post_id} Post Title: ${$idaa_slct?.post_obj?.title}`);
} }
@@ -225,8 +233,9 @@ function send_staff_notification_email() {
console.log(`Selected Post Object:`, $idaa_slct.post_obj); console.log(`Selected Post Object:`, $idaa_slct.post_obj);
console.log(`Selected Post Comment Object:`, $idaa_slct.post_comment_obj); console.log(`Selected Post Comment Object:`, $idaa_slct.post_comment_obj);
console.log($lq__post_obj?.title); // console.log($lq__post_obj);
console.log($lq__post_obj?.content); // console.log($lq__post_obj?.title);
// console.log($lq__post_obj?.content);
} }
let link_base_url = $ae_loc.site_cfg_json.novi_bb_base_url ?? `${$ae_loc.url_origin}/idaa/bb`; let link_base_url = $ae_loc.site_cfg_json.novi_bb_base_url ?? `${$ae_loc.url_origin}/idaa/bb`;
@@ -262,8 +271,8 @@ function send_staff_notification_email() {
api_cfg: $ae_api, api_cfg: $ae_api,
from_email: $ae_loc.site_cfg_json?.noreply_email ?? 'noreply+idaabb@oneskyit.com', 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', from_name: $ae_loc.site_cfg_json?.noreply_name ?? 'IDAA BB NoReply',
// to_email: $ae_loc.site_cfg_json?.admin_email ?? 'admin+bbcomment@oneskyit.com', // 'scott+idaabb@oneskyit.com', // $idaa_slct.post_comment_obj.email, to_email: $ae_loc.site_cfg_json?.admin_email ?? 'admin+bbcomment@oneskyit.com', // 'scott+idaabb@oneskyit.com', // $idaa_slct.post_comment_obj.email,
to_email: 'scott+idaabbstaff@oneskyit.com', // to_email: 'scott+idaabbstaff@oneskyit.com',
to_name: $ae_loc.site_cfg_json?.admin_name ?? 'IDAA BB Admin', to_name: $ae_loc.site_cfg_json?.admin_name ?? 'IDAA BB Admin',
subject: subject, subject: subject,
body_html: body_html, body_html: body_html,
@@ -297,8 +306,8 @@ function send_poster_notification_email() {
from_email: $ae_loc.site_cfg_json?.noreply_email ?? 'noreply+idaabb@oneskyit.com', 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', 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', // 'scott+idaabb@oneskyit.com',
// to_email: $idaa_slct.post_obj.email, to_email: $idaa_slct.post_obj.email,
to_email: 'scott+idaabb@oneskyit.com', // to_email: 'scott+idaabb@oneskyit.com',
to_name: $idaa_slct.post_obj.full_name ?? 'IDAA BB Poster', to_name: $idaa_slct.post_obj.full_name ?? 'IDAA BB Poster',
subject: subject, subject: subject,
body_html: body_html, body_html: body_html,
@@ -314,7 +323,7 @@ function send_poster_notification_email() {
bind:clientHeight={$ae_loc.iframe_height_modal_body} bind:clientHeight={$ae_loc.iframe_height_modal_body}
> >
<form on:submit|preventDefault={handle_submit_form} class="space-y-1"> <form onsubmit={preventDefault(handle_submit_form)} class="space-y-1">
{#await prom_api__post_comment_obj} {#await prom_api__post_comment_obj}
<div class="awaiting alert_msg_pulse" out:fade={{ duration: 2000 }}>Saving...</div> <div class="awaiting alert_msg_pulse" out:fade={{ duration: 2000 }}>Saving...</div>
@@ -329,7 +338,7 @@ function send_poster_notification_email() {
<section class="text-center"> <!-- BEGIN: section post__options --> <section class="text-center"> <!-- BEGIN: section post__options -->
<button <button
type="button" type="button"
on:click={() => { onclick={() => {
$idaa_sess.bb.show__inline_edit__post_comment_id = false; $idaa_sess.bb.show__inline_edit__post_comment_id = false;
}} }}
class="novi_btn btn btn-sm variant-ghost-warning hover:variant-filled-warning transition" class="novi_btn btn btn-sm variant-ghost-warning hover:variant-filled-warning transition"
@@ -463,7 +472,7 @@ function send_poster_notification_email() {
<button <button
type="button" type="button"
class="novi_btn btn btn-sm variant-soft-warning float-right" class="novi_btn btn btn-sm variant-soft-warning float-right"
on:click={() => { onclick={() => {
$idaa_loc.bb.show__admin_options = !$idaa_loc.bb.show__admin_options; $idaa_loc.bb.show__admin_options = !$idaa_loc.bb.show__admin_options;
}} }}
> >
@@ -614,7 +623,7 @@ function send_poster_notification_email() {
<button <button
type="submit" type="submit"
disabled={(disable_submit_btn)} disabled={(disable_submit_btn)}
on:click={() => { onclick={() => {
if (!confirm('Are you sure you want to create this post?')) {return false;} if (!confirm('Are you sure you want to create this post?')) {return false;}
// handle_save_post_comment_obj({post_id: $idaa_slct.post_id, method: 'create'}); // handle_save_post_comment_obj({post_id: $idaa_slct.post_id, method: 'create'});
}} }}
@@ -632,7 +641,7 @@ function send_poster_notification_email() {
{#if $ae_loc.administrator_access} {#if $ae_loc.administrator_access}
<button <button
type="button" type="button"
on:click={() => { onclick={() => {
if (!confirm('Are you sure you want to delete this post comment?')) {return false;} if (!confirm('Are you sure you want to delete this post comment?')) {return false;}
handle_delete_post_comment_obj({post_comment_id: $idaa_slct.post_comment_id, method: 'delete'}); handle_delete_post_comment_obj({post_comment_id: $idaa_slct.post_comment_id, method: 'delete'});
}} }}
@@ -644,7 +653,7 @@ function send_poster_notification_email() {
{:else if $ae_loc.trusted_access} {:else if $ae_loc.trusted_access}
<button <button
type="button" type="button"
on:click={() => { onclick={() => {
if (!confirm('Are you sure you want to disable this post comment?')) {return false;} if (!confirm('Are you sure you want to disable this post comment?')) {return false;}
handle_delete_post_comment_obj({post_comment_id: $idaa_slct.post_comment_id, method: 'disable'}); handle_delete_post_comment_obj({post_comment_id: $idaa_slct.post_comment_id, method: 'disable'});
}} }}
@@ -656,7 +665,7 @@ function send_poster_notification_email() {
{:else} {:else}
<button <button
type="button" type="button"
on:click={() => { onclick={() => {
if (!confirm('Are you sure you want to hide this post comment?')) {return false;} if (!confirm('Are you sure you want to hide this post comment?')) {return false;}
handle_delete_post_comment_obj({post_comment_id: $idaa_slct.post_comment_id, method: 'hide'}); handle_delete_post_comment_obj({post_comment_id: $idaa_slct.post_comment_id, method: 'hide'});
}} }}
@@ -672,7 +681,7 @@ function send_poster_notification_email() {
<div> <div>
<button <button
type="button" type="button"
on:click={() => { onclick={() => {
$idaa_sess.bb.show__inline_edit__post_comment_id = false; $idaa_sess.bb.show__inline_edit__post_comment_id = false;
}} }}
class="novi_btn btn btn-sm variant-ghost-warning hover:variant-filled-warning transition" class="novi_btn btn btn-sm variant-ghost-warning hover:variant-filled-warning transition"

View File

@@ -20,7 +20,8 @@ let ae_promises: key_val = {};
if ($idaa_slct.post_id) { if ($idaa_slct.post_id) {
console.log(`Post ID selected: ${$idaa_slct.post_id}`); console.log(`Post ID selected: ${$idaa_slct.post_id}`);
console.log(`Post Object selected: ${$lq__post_obj}`); console.log(`Post Object selected: ${lq__post_obj}`);
console.log(`Post Object title: ${$lq__post_obj?.title}`);
$idaa_trig.post_id = $idaa_slct.post_id; $idaa_trig.post_id = $idaa_slct.post_id;
} }