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

@@ -1,6 +1,14 @@
<script lang="ts">
/** @type {import('./$types').PageData} */
export let data: any;
import { run } from 'svelte/legacy';
import { page } from '$app/state';
interface Props {
/** @type {import('./$types').PageData} */
data: any;
}
let { data }: Props = $props();
let log_lvl: number = 0;
if (log_lvl) {
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 { page } from '$app/state';
let post_id = page.url.searchParams.get('post_id') ?? null;
if (!post_id) {
$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
.where('account_id')
.equals($slct.account_id)
@@ -51,16 +57,16 @@ $: lq__post_obj_li = liveQuery(async () => {
// .sortBy('[created_on+updated_on]');
return results;
});
}));
$: lq__post_obj = liveQuery(async () => {
let lq__post_obj = $derived(liveQuery(async () => {
let results = await db_posts.post
.get($idaa_slct.post_id ?? ''); // null or undefined does not reset things like '' does
return results;
});
}));
$: lq__post_comment_obj_li = liveQuery(async () => {
let lq__post_comment_obj_li = $derived(liveQuery(async () => {
let results = await db_posts.comment
.where('post_id')
.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');
return results;
});
}));
$: lq__post_comment_obj = liveQuery(async () => {
let lq__post_comment_obj = $derived(liveQuery(async () => {
let results = await db_posts.comment
.get($idaa_slct.post_comment_id ?? ''); // null or undefined does not reset things like '' does
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_trig.post_li = false;
$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,
})
.then((post_obj) => {
if (log_lvl) {
console.log(`Post object loaded: `, post_obj);
}
if (log_lvl) {
console.log(`Triggered: $idaa_trig.post_li`);
$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;
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>
@@ -177,7 +199,7 @@ $: if ($idaa_trig.post_id) {
<!-- <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
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">
{#if $ae_loc.trusted_access || $lq__post_obj?.external_person_id === $idaa_loc.novi_uuid}
<button
on:click={() => {
<div class="flex flex-row items-center justify-between w-full">
<h3 class="text-lg font-semibold">
{#if $ae_loc.trusted_access || $lq__post_obj?.external_person_id === $idaa_loc.novi_uuid}
<button
onclick={() => {
// const url = new URL(location);
// url.searchParams.set('post_id', $lq__post_obj?.post_id_random);
// history.pushState({}, '', url);
@@ -222,26 +245,27 @@ $: if ($idaa_trig.post_id) {
$idaa_sess.bb.show__inline_edit__post_obj = true;
}
}}
class="novi_btn btn btn-sm variant-ghost-warning hover:variant-filled-warning transition"
title={`Edit meeting: ${$lq__post_obj?.title}`}
>
{#if $idaa_sess.bb.show__inline_edit__post_obj}
<span class="fas fa-times m-1"></span> Cancel Edit
{:else}
<span class="fas fa-edit m-1"></span> Edit
{/if}
</button>
{/if}
<!-- {$lq__post_obj?.title ?? 'New Post'} -->
<span class="">
<span class="fas fa-comment-alt m-1"></span>
{@html $lq__post_obj?.title ?? 'New Post'}
<!-- - {$lq__post_obj?.id ?? 'Not Yet Saved'} -->
</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}
</h3>
</div>
</svelte:fragment>
class="novi_btn btn btn-sm variant-ghost-warning hover:variant-filled-warning transition"
title={`Edit meeting: ${$lq__post_obj?.title}`}
>
{#if $idaa_sess.bb.show__inline_edit__post_obj}
<span class="fas fa-times m-1"></span> Cancel Edit
{:else}
<span class="fas fa-edit m-1"></span> Edit
{/if}
</button>
{/if}
<!-- {$lq__post_obj?.title ?? 'New Post'} -->
<span class="">
<span class="fas fa-comment-alt m-1"></span>
{@html $lq__post_obj?.title ?? 'New Post'}
<!-- - {$lq__post_obj?.id ?? 'Not Yet Saved'} -->
</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}
</h3>
</div>
{/snippet}
<Comp__post_obj_id_view
lq__post_obj={lq__post_obj}