Bug fix for saving a post comment and the post data not being ready.
This commit is contained in:
@@ -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,18 +75,19 @@ $: 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;
|
||||||
});
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$: if ($idaa_trig.post_li) {
|
$effect(() => {
|
||||||
|
if ($idaa_trig.post_li) {
|
||||||
$idaa_trig.post_li = false;
|
$idaa_trig.post_li = false;
|
||||||
|
|
||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
@@ -112,9 +119,11 @@ $: if ($idaa_trig.post_li) {
|
|||||||
try_cache: true,
|
try_cache: true,
|
||||||
log_lvl: log_lvl,
|
log_lvl: log_lvl,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$: if ($idaa_trig.post_id) {
|
$effect(() => {
|
||||||
|
if ($idaa_trig.post_id) {
|
||||||
// log_lvl = 1;
|
// log_lvl = 1;
|
||||||
$idaa_trig.post_id = false;
|
$idaa_trig.post_id = false;
|
||||||
|
|
||||||
@@ -131,9 +140,21 @@ $: if ($idaa_trig.post_id) {
|
|||||||
inc_comment_li: true,
|
inc_comment_li: true,
|
||||||
try_cache: true,
|
try_cache: true,
|
||||||
log_lvl: log_lvl,
|
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_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')) {
|
if (!page.url.searchParams.get('post_id')) {
|
||||||
const url = new URL(location);
|
const url = new URL(location);
|
||||||
@@ -146,7 +167,8 @@ $: if ($idaa_trig.post_id) {
|
|||||||
|
|
||||||
$idaa_sess.bb.show__modal_view__post_id = $idaa_slct.post_id;
|
$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_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">
|
<div class="flex flex-row items-center justify-between w-full">
|
||||||
<h3 class="text-lg font-semibold">
|
<h3 class="text-lg font-semibold">
|
||||||
{#if $ae_loc.trusted_access || $lq__post_obj?.external_person_id === $idaa_loc.novi_uuid}
|
{#if $ae_loc.trusted_access || $lq__post_obj?.external_person_id === $idaa_loc.novi_uuid}
|
||||||
<button
|
<button
|
||||||
on:click={() => {
|
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);
|
||||||
@@ -241,7 +264,8 @@ $: if ($idaa_trig.post_id) {
|
|||||||
{#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}
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user