More work on the BB Posts for IDAA. Can now edit, update, and create now posts.

This commit is contained in:
Scott Idem
2025-07-02 13:52:30 -04:00
parent 50deb79f6b
commit f8461f367e
8 changed files with 226 additions and 71 deletions

View File

@@ -511,7 +511,7 @@ export interface Presentation {
// A key value list of the presenters // A key value list of the presenters
event_presenter_kv?: null|key_val; event_presenter_kv?: null|key_val;
event_presenter_li?: null|list; event_presenter_li?: null|Array<any>;
} }

View File

@@ -65,6 +65,8 @@ let idaa_local_data_struct: key_val = {
qry__limit: 50, qry__limit: 50,
qry__offset: 0, qry__offset: 0,
qry__order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'updated_on': 'DESC', 'created_on': 'DESC', 'title': 'ASC'}, qry__order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'updated_on': 'DESC', 'created_on': 'DESC', 'title': 'ASC'},
edit_kv: {}, // Used to track which post objects are being edited
}, },
recovery_meetings: { recovery_meetings: {
@@ -112,6 +114,8 @@ let idaa_session_data_struct: key_val = {
show__inline_edit__post_obj: null, show__inline_edit__post_obj: null,
show__modal_edit__post_id: null, show__modal_edit__post_id: null,
show__modal_view__post_id: null, show__modal_view__post_id: null,
obj_changed: false, // Used to track if the post object has been changed in the edit view
// edit_kv: {}, // Used to track which post objects are being edited
}, },
recovery_meetings: { recovery_meetings: {

View File

@@ -56,6 +56,11 @@ export interface Post {
// Additional fields for convenience (database views) // Additional fields for convenience (database views)
post_comment_count?: number; post_comment_count?: number;
// Placeholder for generated temp data
hosted_file_id_li?: null|Array<string>;
hosted_file_obj_li?: null|Array<any>;
upload_complete?: boolean;
} }

View File

@@ -39,6 +39,7 @@ export let html_text: string = '';
export let default_minimal: boolean = false; export let default_minimal: boolean = false;
export let show_toolbar: boolean = true; export let show_toolbar: boolean = true;
export let placeholder: string = 'Type your text here...'; export let placeholder: string = 'Type your text here...';
export let changed: boolean = false;
if (default_minimal) { if (default_minimal) {
show_toolbar = false; show_toolbar = false;
@@ -84,6 +85,7 @@ export let show_button_kv: any;
// export let new_json = editor?.getJSON(); // export let new_json = editor?.getJSON();
export let new_html: string = ''; export let new_html: string = '';
let orig_html: string = html_text;
onMount(() => { onMount(() => {
}); });
@@ -91,6 +93,14 @@ onMount(() => {
onDestroy(() => { onDestroy(() => {
}); });
$: if (html_text !== orig_html && html_text !== '<p></p>') {
console.log('html_text changed:', html_text);
console.log('orig_html:', orig_html);
changed = true;
} else {
changed = false;
}
let mouse_entered_timer: any; let mouse_entered_timer: any;
let mouse_enter_wait: number = 500; let mouse_enter_wait: number = 500;
let mouse_leave_wait: number = 2000; let mouse_leave_wait: number = 2000;

View File

@@ -3,7 +3,7 @@ import type { PageData } from './$types';
let { data }: { data: PageData } = $props(); let { data }: { data: PageData } = $props();
let log_lvl: number = 0; let log_lvl: number = 1;
// *** Import Svelte specific // *** Import Svelte specific
import { onDestroy } from "svelte"; import { onDestroy } from "svelte";
@@ -30,7 +30,7 @@ if (log_lvl) {
console.log(`ae_acct = `, ae_acct); 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_id = ae_acct.slct.post_id;
// $idaa_slct.post_obj = ae_acct.slct.post_obj; // $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 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
// 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; return results;
})); }));
@@ -57,6 +69,7 @@ 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
$idaa_slct.post_comment_obj = { ...results };
return results; return results;
})); }));
@@ -155,16 +168,22 @@ onDestroy(() => {
</a> </a>
<!-- View (default)/Edit post_id toggle --> <!-- View (default)/Edit post_id toggle -->
{#if $idaa_sess.bb.edit__post_id} {#if $idaa_sess.bb.edit__post_obj}
<button <button
type="button" type="button"
class="novi_btn btn btn-warning btn-sm preset-tonal-tertiary border border-tertiary-500 class="novi_btn btn btn-warning btn-sm preset-tonal-tertiary border border-tertiary-500
hover:preset-filled-tertiary-500 transition" hover:preset-filled-tertiary-500 transition"
onclick={() => { onclick={() => {
$idaa_sess.bb.edit__post_id = false; if ($idaa_sess.bb.obj_changed) {
if (log_lvl) { if (confirm('You have unsaved changes. Are you sure you want to cancel?')) {
console.log(`Toggle edit__post_id: ${$idaa_sess.bb.edit__post_id}`); $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" 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 class="novi_btn btn btn-warning btn-sm preset-tonal-warning border border-warning-500
hover:preset-filled-warning-500 transition" hover:preset-filled-warning-500 transition"
onclick={() => { onclick={() => {
$idaa_slct.post_obj = $lq__post_obj; // $idaa_slct.post_obj = {
$idaa_sess.bb.edit__post_id = $idaa_slct.post_id; // ...$lq__post_obj,
if (log_lvl) { // }
console.log(`Toggle edit__post_id: ${$idaa_sess.bb.edit__post_id}`); $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" 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_li={lq__post_comment_obj_li} -->
<!-- lq__post_comment_obj={lq__post_comment_obj} --> <!-- lq__post_comment_obj={lq__post_comment_obj} -->
<Comp__post_obj_id_edit <Comp__post_obj_id_edit
lq__post_obj={lq__post_obj} lq__post_obj={lq__post_obj}
bind:obj_changed={$idaa_sess.bb.obj_changed}
/> />
{:else} {:else}
<Comp__post_obj_id_view <Comp__post_obj_id_view

View File

@@ -1,11 +1,23 @@
<script lang="ts"> <script lang="ts">
interface Props {
log_lvl?: number;
lq__post_obj: any;
obj_changed: boolean;
}
// import { run, preventDefault } from 'svelte/legacy'; let {
log_lvl = $bindable(0),
lq__post_obj,
obj_changed = $bindable(false)
}: 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 { browser } from '$app/environment'; import { browser } from '$app/environment';
import { goto } from '$app/navigation';
// *** Import Aether core 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';
@@ -16,22 +28,35 @@ 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';
import Comp_hosted_files_upload from '$lib/ae_core/ae_comp__hosted_files_upload.svelte'; import Comp_hosted_files_upload from '$lib/ae_core/ae_comp__hosted_files_upload.svelte';
interface Props { // let obj_changed = $state(false);
log_lvl?: number; // let orig_post_obj: any = $state(null);
lq__post_obj: any; // let orig_post_obj: any = $state({ ...$idaa_slct.post_obj }); // Create a copy of the post object
let orig_post_obj: any = { ...$idaa_slct.post_obj };
if (browser) {
// console.log(`$lq__post_obj = `, $lq__post_obj);
console.log(`$idaa_slct.post_obj = `, $idaa_slct.post_obj);
// orig_post_obj = { ...$idaa_slct.post_obj }; // Create a copy of the post object
console.log(`orig_post_obj = `, orig_post_obj);
// JSON.stringify($idaa_slct.post_obj) !== JSON.stringify(orig_post_obj)
} }
let { log_lvl = $bindable(0), lq__post_obj }: Props = $props(); if ($idaa_loc.bb.edit__post_obj) {
$idaa_sess.bb.edit__post_obj = $idaa_loc.bb.edit__post_obj;
if (browser) { $idaa_loc.bb.edit__post_obj = false;
console.log(`$lq__post_obj = `, $lq__post_obj);
$idaa_slct.post_obj = $lq__post_obj;
} }
let ae_promises: key_val = $state({}); let ae_promises: key_val = $state({});
let prom_api__post_obj: any = $state(); let prom_api__post_obj: any = $state();
// let prom_api__post_obj__hosted_file: any; // let prom_api__post_obj__hosted_file: any;
let content_new_html = $state('');
let content_changed = $state(false);
let notes_new_html = $state('');
let notes_changed = $state(false);
let hosted_file_id_li = $state<string[]>([]); // Array of hosted file IDs
let hosted_file_obj_li = $state<any[]>([]); // Array of hosted file objects
let upload_complete = $state(false);
let disable_submit_btn = $state(false); let disable_submit_btn = $state(false);
@@ -62,9 +87,9 @@ async function handle_submit_form(event: any) {
post_do['title'] = post_di.title; post_do['title'] = post_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_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_do['content'] = $idaa_slct.post_obj.content_new_html; post_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_do['content'] = event_meeting_fd.content; // post_do['content'] = event_meeting_fd.content;
@@ -107,9 +132,9 @@ async function handle_submit_form(event: any) {
console.log(`post_do.enable = ${post_do.enable}`); console.log(`post_do.enable = ${post_do.enable}`);
// Check if the notes_new_html exists and is a string // Check if the notes_new_html exists and is a string
if (typeof $idaa_slct.post_obj.notes_new_html === 'string') { if (typeof notes_new_html === 'string') {
console.log('New notes is a string'); console.log('New notes is a string');
post_do['notes'] = $idaa_slct.post_obj.notes_new_html; post_do['notes'] = notes_new_html;
} else { } else {
console.log('New notes is not a string. Do nothing.'); console.log('New notes is not a string. Do nothing.');
// post_do['notes'] = event_meeting_fd.notes; // post_do['notes'] = event_meeting_fd.notes;
@@ -147,7 +172,7 @@ async function handle_submit_form(event: any) {
}) })
.finally(() => { .finally(() => {
disable_submit_btn = false; disable_submit_btn = false;
$idaa_sess.bb.show__inline_edit__post_obj = false; $idaa_sess.bb.edit__post_obj = false;
if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_new_email) { if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_new_email) {
send_staff_notification_email(); send_staff_notification_email();
@@ -183,7 +208,7 @@ async function handle_submit_form(event: any) {
// We need to do this since the post has changed and the idaa_slct object does automatically update (yet...???). // We need to do this since the post has changed and the idaa_slct object does automatically update (yet...???).
// $idaa_slct.post_obj = $lq__post_obj; // $idaa_slct.post_obj = $lq__post_obj;
disable_submit_btn = false; disable_submit_btn = false;
$idaa_sess.bb.show__inline_edit__post_obj = false; $idaa_sess.bb.edit__post_obj = false;
if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_update_email) { if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_update_email) {
send_staff_notification_email(); send_staff_notification_email();
@@ -217,9 +242,9 @@ async function handle_delete_post_obj(
log_lvl: log_lvl log_lvl: log_lvl
}) })
.then(function (post_obj_delete_result) { .then(function (post_obj_delete_result) {
$idaa_sess.bb.show__modal_view__post_id = false; // $idaa_sess.bb.show__modal_view__post_id = false;
$idaa_sess.bb.show__inline_edit__post_obj = false; $idaa_sess.bb.edit__post_obj = false;
$idaa_sess.bb.show__inline_edit__post_comment_id = false; // $idaa_sess.bb.show__inline_edit__post_comment_id = false;
}) })
.catch(function (error) { .catch(function (error) {
console.log('The result was null or false when trying to delete.', error); console.log('The result was null or false when trying to delete.', error);
@@ -230,6 +255,7 @@ async function handle_delete_post_obj(
$idaa_slct.post_obj = null; $idaa_slct.post_obj = null;
$idaa_slct.post_comment_id = null; $idaa_slct.post_comment_id = null;
$idaa_slct.post_comment_obj = null; $idaa_slct.post_comment_obj = null;
goto('/idaa/bb'); // Redirect to the BB page
}); });
return prom_api__post_obj; return prom_api__post_obj;
@@ -312,11 +338,36 @@ function send_staff_notification_email() {
}); });
} }
// function preventDefault(
// fn: (event: Event, ...args: Array<unknown>) => void
// ): (event: Event, ...args: unknown[]) => void;
function preventDefault(fn) {
return function (event) {
event.preventDefault();
fn.call(this, event);
};
}
$effect(() => { $effect(() => {
if ($idaa_slct.post_obj?.upload_complete && $idaa_slct.post_obj?.hosted_file_id_li?.length && $idaa_slct.post_obj.hosted_file_obj_li?.length) { if (orig_post_obj === null || orig_post_obj === undefined || orig_post_obj === 'undefined') {
handle_hosted_files_uploaded($idaa_slct.post_obj.hosted_file_id_li, $idaa_slct.post_obj.hosted_file_obj_li); obj_changed = false;
} else if (!obj_changed && orig_post_obj?.id && (JSON.stringify($idaa_slct.post_obj) !== JSON.stringify(orig_post_obj) || content_changed || notes_changed)) {
// console.log('Post object has changed from original.', $inspect(orig_post_obj));
console.log('Post object has changed from original.', orig_post_obj);
console.log('Post object has changed.', $idaa_slct.post_obj);
obj_changed = true;
} else if (obj_changed && orig_post_obj?.id && (JSON.stringify($idaa_slct.post_obj) === JSON.stringify(orig_post_obj) && !content_changed && !notes_changed)) {
obj_changed = false;
} }
}); });
$effect(() => {
if (upload_complete && hosted_file_id_li?.length && hosted_file_obj_li?.length) {
handle_hosted_files_uploaded(hosted_file_id_li, hosted_file_obj_li);
}
});
</script> </script>
@@ -326,7 +377,7 @@ $effect(() => {
bind:clientHeight={$ae_loc.iframe_height_modal_body} bind:clientHeight={$ae_loc.iframe_height_modal_body}
> >
<form onsubmit={handle_submit_form} class="space-y-1"> <form onsubmit={preventDefault(handle_submit_form)} class="space-y-1">
{#await prom_api__post_obj} {#await prom_api__post_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>
@@ -342,7 +393,13 @@ $effect(() => {
<button <button
type="button" type="button"
onclick={() => { onclick={() => {
$idaa_sess.bb.show__inline_edit__post_obj = false; if (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;
}
}} }}
class="novi_btn btn btn-sm preset-tonal-warning border border-warning-500 hover:preset-filled-warning-500 transition" class="novi_btn btn btn-sm preset-tonal-warning border border-warning-500 hover:preset-filled-warning-500 transition"
title="Cancel editing of post for {$idaa_slct.post_obj.full_name} (ID: {$idaa_slct.post_obj.post_id}" title="Cancel editing of post for {$idaa_slct.post_obj.full_name} (ID: {$idaa_slct.post_obj.post_id}"
@@ -362,7 +419,7 @@ $effect(() => {
<span class="text-sm text-gray-600 dark:text-gray-400"> <span class="text-sm text-gray-600 dark:text-gray-400">
Title of BB post: Title of BB post:
</span> </span>
<input type="text" id="title" name="title" required max="200" value={$idaa_slct.post_obj?.title ?? ''} placeholder="Title of Post" autocomplete="off" class="input w-full" /> <input type="text" id="title" name="title" required max="200" bind:value={$idaa_slct.post_obj.title} placeholder="Title of Post" autocomplete="off" class="input w-full" />
</label> </label>
</div> </div>
@@ -376,7 +433,7 @@ $effect(() => {
{#if $ae_loc.administrator_access} {#if $ae_loc.administrator_access}
<Tiptap_editor <Tiptap_editor
default_minimal={true} default_minimal={true}
bind:html_text={$idaa_slct.post_obj.content} html_text={$idaa_slct.post_obj.content}
show_button_kv={{ show_button_kv={{
text: true, text: true,
bullet_list: true, bullet_list: true,
@@ -384,13 +441,14 @@ $effect(() => {
link: true, link: true,
unset_link: true unset_link: true
}} }}
bind:new_html={$idaa_slct.post_obj.content_new_html} bind:new_html={content_new_html}
bind:changed={content_changed}
placeholder="Your post content here..." placeholder="Your post content here..."
/> />
{:else} {:else}
<Tiptap_editor <Tiptap_editor
default_minimal={true} default_minimal={true}
bind:html_text={$idaa_slct.post_obj.content} html_text={$idaa_slct.post_obj.content}
show_button_kv={{ show_button_kv={{
// text: true, // text: true,
// bullet_list: true, // bullet_list: true,
@@ -398,11 +456,13 @@ $effect(() => {
// link: true, // link: true,
// unset_link: true // unset_link: true
}} }}
bind:new_html={$idaa_slct.post_obj.content_new_html} bind:new_html={content_new_html}
bind:changed={content_changed}
placeholder="Your post content here..." placeholder="Your post content here..."
/> />
{/if} {/if}
</label> </label>
</div> </div>
@@ -434,14 +494,14 @@ $effect(() => {
accept="image/*, .docx, .pdf, .pptx, .key" accept="image/*, .docx, .pdf, .pptx, .key"
class_li="border border-gray-300 rounded-md p-2 bg-gray-100 hover:bg-gray-200" class_li="border border-gray-300 rounded-md p-2 bg-gray-100 hover:bg-gray-200"
link_to_type="post" link_to_type="post"
link_to_id={$idaa_slct.post_obj.post_id_random} link_to_id={$idaa_slct.post_obj?.post_id}
bind:hosted_file_id_li={$idaa_slct.post_obj.hosted_file_id_li} bind:hosted_file_id_li={hosted_file_id_li}
bind:hosted_file_obj_li={$idaa_slct.post_obj.hosted_file_obj_li} bind:hosted_file_obj_li={hosted_file_obj_li}
bind:upload_complete={$idaa_slct.post_obj.upload_complete} bind:upload_complete={upload_complete}
log_lvl={log_lvl} log_lvl={log_lvl}
> >
{#snippet label()} {#snippet label()}
<span > <span >
<div> <div>
<span class="fas fa-upload"></span> <span class="fas fa-upload"></span>
<strong class="bg-green-100 p-1">Upload post files</strong> <strong class="bg-green-100 p-1">Upload post files</strong>
@@ -453,7 +513,7 @@ $effect(() => {
<!-- <br> --> <!-- <br> -->
</span> </span>
</span> </span>
{/snippet} {/snippet}
</Comp_hosted_files_upload> </Comp_hosted_files_upload>
{/if} {/if}
</div> </div>
@@ -593,7 +653,7 @@ $effect(() => {
<select <select
name="topic_id" name="topic_id"
class="select w-96" class="select w-96"
value={$idaa_slct.post_obj?.topic_id ?? ''} bind:value={$idaa_slct.post_obj.topic_id}
> >
<option value="">-- None --</option> <option value="">-- None --</option>
<option value={16}>Licensing/ monitoring/ credentialing issues</option> <option value={16}>Licensing/ monitoring/ credentialing issues</option>
@@ -825,9 +885,9 @@ $effect(() => {
</span> </span>
<span class="flex flex-row flex-wrap gap-1 items-center justify-evenly grow"> <span class="flex flex-row flex-wrap gap-1 items-center justify-evenly grow">
<label class="legend text-sm font-semibold">Sort <input type="number" name="sort" value={$idaa_slct.post_obj.sort} class="input w-24" /></label> <label class="legend text-sm font-semibold">Sort <input type="number" name="sort" bind:value={$idaa_slct.post_obj.sort} class="input w-24" /></label>
<label class="legend text-sm font-semibold">Group <input type="text" name="group" value={$idaa_slct.post_obj.group ?? ''} max="100" class="input w-40" /></label> <label class="legend text-sm font-semibold">Group <input type="text" name="group" bind:value={$idaa_slct.post_obj.group} max="100" class="input w-40" /></label>
</span> </span>
{#if $ae_loc.administrator_access} {#if $ae_loc.administrator_access}
@@ -871,9 +931,11 @@ $effect(() => {
<span class="legend text-sm font-semibold">Internal Staff Notes</span> <span class="legend text-sm font-semibold">Internal Staff Notes</span>
<Tiptap_editor <Tiptap_editor
default_minimal={true} default_minimal={true}
bind:html_text={$idaa_slct.post_obj.notes} html_text={$idaa_slct.post_obj.notes}
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_obj.notes_new_html} bind:new_html={notes_new_html}
bind:changed={notes_changed}
placeholder="Internal notes for staff only. Not shown to the public."
/> />
</label> </label>
{/if} {/if}
@@ -888,13 +950,13 @@ $effect(() => {
{#if $idaa_slct.post_id} {#if $idaa_slct.post_id}
<button <button
type="submit" type="submit"
disabled={(disable_submit_btn)} disabled={(disable_submit_btn || !obj_changed)}
class="novi_btn btn_primary btn btn-primary preset-tonal-primary border border-primary-500 hover:preset-filled-primary-500 transition" class="novi_btn btn_primary btn btn-primary preset-tonal-primary border border-primary-500 hover:preset-filled-primary-500 transition"
> >
{#await prom_api__post_obj} {#await prom_api__post_obj}
<span class="fas fa-spinner fa-spin m-1"></span> Saving <span class="fas fa-spinner fa-spin m-1"></span> Saving
{:then} {:then}
<span class="fas fa-save m-1"></span> Save <span class="fas fa-save m-1"></span> Save Changes
{/await} {/await}
</button> </button>
{:else} {:else}
@@ -960,7 +1022,14 @@ $effect(() => {
<button <button
type="button" type="button"
onclick={() => { onclick={() => {
$idaa_sess.bb.show__inline_edit__post_obj = false; if (obj_changed) {
if (confirm('You have unsaved changes. Are you sure you want to cancel?')) {
$idaa_sess.bb.edit__post_obj = false;
}
} else {
// No changes, just close the edit view.
$idaa_sess.bb.edit__post_obj = false;
}
}} }}
class="novi_btn btn btn-sm preset-tonal-warning border border-warning-500 hover:preset-filled-warning-500 transition" class="novi_btn btn btn-sm preset-tonal-warning border border-warning-500 hover:preset-filled-warning-500 transition"
title="Cancel editing of post for {$idaa_slct.post_obj.full_name} (ID: {$idaa_slct.post_obj.post_id}" title="Cancel editing of post for {$idaa_slct.post_obj.full_name} (ID: {$idaa_slct.post_obj.post_id}"

View File

@@ -1,6 +1,13 @@
<script lang="ts"> <script lang="ts">
interface Props {
lq__post_obj: any;
lq__post_comment_obj_li: any;
lq__post_comment_obj: any;
}
import { onDestroy } from 'svelte'; let { lq__post_obj, lq__post_comment_obj_li, lq__post_comment_obj }: Props = $props();
// *** Import Svelte specific
import { browser } from '$app/environment'; import { browser } from '$app/environment';
// *** Import Aether core variables and functions // *** Import Aether core variables and functions
@@ -13,13 +20,6 @@ import { idaa_loc, idaa_sess, idaa_slct, idaa_trig } from '$lib/ae_idaa_stores';
// import Comp__post_obj_id_edit from './ae_idaa_comp__post_obj_id_edit.svelte'; // import Comp__post_obj_id_edit from './ae_idaa_comp__post_obj_id_edit.svelte';
import Comp__post_comment_obj_id_edit from './ae_idaa_comp__post_comment_obj_id_edit.svelte'; import Comp__post_comment_obj_id_edit from './ae_idaa_comp__post_comment_obj_id_edit.svelte';
interface Props {
lq__post_obj: any;
lq__post_comment_obj_li: any;
lq__post_comment_obj: any;
}
let { lq__post_obj, lq__post_comment_obj_li, lq__post_comment_obj }: Props = $props();
let ae_promises: key_val = $state({}); let ae_promises: key_val = $state({});
@@ -275,7 +275,8 @@ $effect(() => {
// $idaa_sess.bb.show_main__options = false; // $idaa_sess.bb.show_main__options = false;
// $idaa_sess.bb.show_list__post_li = false; // $idaa_sess.bb.show_list__post_li = false;
// $idaa_sess.bb.show_view__post_id = false; // $idaa_sess.bb.show_view__post_id = false;
$idaa_sess.bb.show__inline_edit__post_obj = true; // $idaa_sess.bb.show__inline_edit__post_obj = true;
$idaa_sess.bb.edit__post_obj = $idaa_slct.post_id;
}} }}
class="novi_btn btn btn-sm preset-tonal-warning border border-warning-500 hover:preset-filled-warning-500 transition" class="novi_btn btn btn-sm preset-tonal-warning border border-warning-500 hover:preset-filled-warning-500 transition"
title="Edit post for {$lq__post_obj?.full_name} (ID: {$lq__post_obj?.post_id}" title="Edit post for {$lq__post_obj?.full_name} (ID: {$lq__post_obj?.post_id}"
@@ -296,11 +297,11 @@ $effect(() => {
{/if} {/if}
{#if $lq__post_comment_obj_li?.length} {#if $lq__post_comment_obj_li?.length}
<section class="post_comment_obj_li space-y-2 border border p-0 border-y-0"> <section class="post_comment_obj_li space-y-2 border p-0 border-y-0">
{#each $lq__post_comment_obj_li as post_comment_obj, index} {#each $lq__post_comment_obj_li as post_comment_obj, index}
<div <div
class="p-4 space-y-1 border-b border-b-2" class="p-4 space-y-1 border-b-2"
class:dim={post_comment_obj?.hide} class:dim={post_comment_obj?.hide}
class:bg-warning-100={!post_comment_obj?.enable} class:bg-warning-100={!post_comment_obj?.enable}
> >

View File

@@ -1,11 +1,14 @@
<script lang="ts"> <script lang="ts">
// *** Import Svelte specific
import { goto } from '$app/navigation';
// *** Import Aether core variables and functions // *** Import Aether core variables and functions
export let log_lvl: number = 0; export let log_lvl: number = 0;
// import type { key_val } from '$lib/ae_stores'; // import type { key_val } from '$lib/ae_stores';
import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/ae_stores'; import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/ae_stores';
import { idaa_loc, idaa_sess, idaa_slct, idaa_trig, idaa_prom } from '$lib/ae_idaa_stores'; import { idaa_loc, idaa_sess, idaa_slct, idaa_trig, idaa_prom } 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';
// let ae_promises: key_val = {}; // let ae_promises: key_val = {};
// let ae_tmp: key_val = {}; // let ae_tmp: key_val = {};
@@ -109,10 +112,51 @@ if (log_lvl) console.log('** Component Loaded: ** Post Options');
if (!confirm('Create new post?')) { if (!confirm('Create new post?')) {
return false; return false;
} }
let data_kv = {
external_person_id: $idaa_loc.novi_uuid,
title: 'Change Me',
full_name: $idaa_loc.novi_full_name,
email: $idaa_loc.novi_email,
enable: true,
};
if (log_lvl) {
console.log('Creating new post with data_kv:', data_kv);
}
posts_func.create_ae_obj__post({
api_cfg: $ae_api,
account_id: $ae_loc.account_id,
data_kv: data_kv,
log_lvl: log_lvl
}).then((results) => {
if (log_lvl) {
console.log('New post created:', results);
}
$idaa_slct.post_id = results?.post_id_random;
$idaa_sess.bb.edit__post_obj = $idaa_slct.post_id;
$idaa_loc.bb.edit__post_obj = $idaa_slct.post_id;
// if (!$idaa_loc.bb.edit_kv) {
// $idaa_loc.bb.edit_kv = {};
// }
// $idaa_loc.bb.edit_kv[$idaa_slct.post_id] = 'current';
// alert(`Post created successfully! ${$idaa_slct.post_id}`);
}).catch((error) => {
console.error('Error updating post:', error);
alert('Failed to update post.');
}).finally(() => {
if ($idaa_slct.post_id) {
goto(`/idaa/bb/${$idaa_slct.post_id}`);
} else {
alert('Failed to create new post.');
}
});
// $idaa_slct.post_id = ''; // $idaa_slct.post_id = '';
// $idaa_slct.post_id = undefined; // $idaa_slct.post_id = undefined;
$idaa_slct.post_id = null; // $idaa_slct.post_id = null;
$idaa_slct.post_obj = {}; // $idaa_slct.post_obj = {};
// const url = new URL(location); // const url = new URL(location);
// url.searchParams.delete('post_id'); // url.searchParams.delete('post_id');
@@ -123,8 +167,8 @@ if (log_lvl) console.log('** Component Loaded: ** Post Options');
// $idaa_loc.bb.show_view__post_obj = false; // $idaa_loc.bb.show_view__post_obj = false;
// $idaa_loc.bb.show_edit__post_obj = true; // $idaa_loc.bb.show_edit__post_obj = true;
$idaa_sess.bb.show__modal_view__post_id = true; // $idaa_sess.bb.show__modal_view__post_id = true;
$idaa_sess.bb.show__inline_edit__post_obj = true; // $idaa_sess.bb.show__inline_edit__post_obj = true;
}} }}
class="novi_btn btn_new_post btn btn-sm preset-tonal-warning border border-warning-500 hover:preset-filled-warning-500 transition text-xs" class="novi_btn btn_new_post btn btn-sm preset-tonal-warning border border-warning-500 hover:preset-filled-warning-500 transition text-xs"
title="Create new post" title="Create new post"