More work on the BB Posts for IDAA. Can now edit, update, and create now posts.
This commit is contained in:
@@ -3,7 +3,7 @@ import type { PageData } from './$types';
|
||||
|
||||
let { data }: { data: PageData } = $props();
|
||||
|
||||
let log_lvl: number = 0;
|
||||
let log_lvl: number = 1;
|
||||
|
||||
// *** Import Svelte specific
|
||||
import { onDestroy } from "svelte";
|
||||
@@ -30,7 +30,7 @@ if (log_lvl) {
|
||||
console.log(`ae_acct = `, ae_acct);
|
||||
}
|
||||
|
||||
$idaa_sess.bb.edit__post_id = null;
|
||||
$idaa_sess.bb.edit__post_obj = null;
|
||||
$idaa_slct.post_id = ae_acct.slct.post_id;
|
||||
// $idaa_slct.post_obj = ae_acct.slct.post_obj;
|
||||
|
||||
@@ -39,6 +39,18 @@ 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
|
||||
|
||||
// Check if results are different than the current $idaa_slct.post_obj
|
||||
if ($idaa_slct.post_obj && results) {
|
||||
if (JSON.stringify($idaa_slct.post_obj) !== JSON.stringify(results)) {
|
||||
$idaa_slct.post_obj = { ...results};
|
||||
} else {
|
||||
if (log_lvl) {
|
||||
console.log(`Post object has not changed for post_id: ${$idaa_slct.post_id}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// console.log(`$idaa_slct.post_obj = `, $idaa_slct.post_obj);
|
||||
return results;
|
||||
}));
|
||||
|
||||
@@ -57,6 +69,7 @@ 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
|
||||
|
||||
$idaa_slct.post_comment_obj = { ...results };
|
||||
return results;
|
||||
}));
|
||||
|
||||
@@ -155,16 +168,22 @@ onDestroy(() => {
|
||||
</a>
|
||||
|
||||
<!-- View (default)/Edit post_id toggle -->
|
||||
{#if $idaa_sess.bb.edit__post_id}
|
||||
{#if $idaa_sess.bb.edit__post_obj}
|
||||
<button
|
||||
type="button"
|
||||
class="novi_btn btn btn-warning btn-sm preset-tonal-tertiary border border-tertiary-500
|
||||
hover:preset-filled-tertiary-500 transition"
|
||||
onclick={() => {
|
||||
$idaa_sess.bb.edit__post_id = false;
|
||||
if (log_lvl) {
|
||||
console.log(`Toggle edit__post_id: ${$idaa_sess.bb.edit__post_id}`);
|
||||
if ($idaa_sess.bb.obj_changed) {
|
||||
if (confirm('You have unsaved changes. Are you sure you want to cancel?')) {
|
||||
$idaa_sess.bb.edit__post_obj = false;
|
||||
}
|
||||
} else {
|
||||
$idaa_sess.bb.edit__post_obj = false;
|
||||
}
|
||||
// if (log_lvl) {
|
||||
// console.log(`Toggle edit__post_obj: ${$idaa_sess.bb.edit__post_obj}`);
|
||||
// }
|
||||
}}
|
||||
title="View this BB Post"
|
||||
>
|
||||
@@ -178,11 +197,13 @@ onDestroy(() => {
|
||||
class="novi_btn btn btn-warning btn-sm preset-tonal-warning border border-warning-500
|
||||
hover:preset-filled-warning-500 transition"
|
||||
onclick={() => {
|
||||
$idaa_slct.post_obj = $lq__post_obj;
|
||||
$idaa_sess.bb.edit__post_id = $idaa_slct.post_id;
|
||||
if (log_lvl) {
|
||||
console.log(`Toggle edit__post_id: ${$idaa_sess.bb.edit__post_id}`);
|
||||
}
|
||||
// $idaa_slct.post_obj = {
|
||||
// ...$lq__post_obj,
|
||||
// }
|
||||
$idaa_sess.bb.edit__post_obj = $idaa_slct.post_id;
|
||||
// if (log_lvl) {
|
||||
// console.log(`Toggle edit__post_obj: ${$idaa_sess.bb.edit__post_obj}`);
|
||||
// }
|
||||
}}
|
||||
title="Edit this BB Post"
|
||||
>
|
||||
@@ -195,11 +216,12 @@ onDestroy(() => {
|
||||
|
||||
|
||||
|
||||
{#if $idaa_sess.bb.edit__post_id}
|
||||
{#if $idaa_sess.bb.edit__post_obj || $idaa_loc.bb.edit__post_obj}
|
||||
<!-- lq__post_comment_obj_li={lq__post_comment_obj_li} -->
|
||||
<!-- lq__post_comment_obj={lq__post_comment_obj} -->
|
||||
<Comp__post_obj_id_edit
|
||||
lq__post_obj={lq__post_obj}
|
||||
bind:obj_changed={$idaa_sess.bb.obj_changed}
|
||||
/>
|
||||
{:else}
|
||||
<Comp__post_obj_id_view
|
||||
|
||||
Reference in New Issue
Block a user