fix(idaa/bb): fire-and-forget page load + UX fixes for post/comment editing
- [post_id]/+page.ts: remove await on post load (same pattern as archives); liveQuery renders immediately, replace error(404) with console.warn. - ae_idaa_comp__post_options: add in-flight creating guard + spinner on Create New Post button to prevent double-submit; remove ~15 lines of dead commented code left over from previous refactors. - ae_idaa_comp__post_obj_id_view: remove confirm() dialog before opening the Add Comment form — no need to confirm an intent to type a comment. - ae_idaa_comp__post_comment_obj_id_edit: remove redundant block that manually injected post_id into the payload for new comments; post_id is already handled correctly by the form payload builder.
This commit is contained in:
@@ -2,7 +2,6 @@ import type { PageLoad } from './$types';
|
||||
|
||||
console.log(`ae_idaa_bulletin_board [post_id] +page.ts start`);
|
||||
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { browser } from '$app/environment';
|
||||
import { posts_func } from '$lib/ae_posts/ae_posts_functions';
|
||||
|
||||
@@ -24,8 +23,11 @@ export const load = (async ({ params, parent }) => {
|
||||
if (log_lvl) {
|
||||
console.log(`ae_idaa_posts posts [post_id] +page.ts: post_id = `, post_id);
|
||||
}
|
||||
// Load post object
|
||||
const load_post_obj = await posts_func
|
||||
// NOTE: Fire in background — do NOT await. Newly created posts are already in Dexie
|
||||
// (saved by create_ae_obj__post), so the liveQuery renders immediately. For direct
|
||||
// links or refreshes, the post loads from the API and Dexie updates reactively.
|
||||
// Awaiting here blocked the SvelteKit navigation, causing a visible "refresh" delay.
|
||||
posts_func
|
||||
.load_ae_obj_id__post({
|
||||
api_cfg: ae_acct.api,
|
||||
post_id: post_id,
|
||||
@@ -34,18 +36,9 @@ export const load = (async ({ params, parent }) => {
|
||||
})
|
||||
.then((results) => {
|
||||
if (!results) {
|
||||
error(404, {
|
||||
message: 'IDAA BB - Post not found'
|
||||
});
|
||||
} else {
|
||||
// ae_acct.slct.post_obj = results;
|
||||
console.warn(`ae IDAA BB [post_id] +page.ts: Post ${post_id} not found via API or Cache.`);
|
||||
}
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log(`load_post_obj = `, load_post_obj);
|
||||
}
|
||||
ae_acct.slct.post_obj = load_post_obj;
|
||||
}
|
||||
|
||||
// WARNING: Precaution against shared data between sites.
|
||||
|
||||
@@ -105,13 +105,6 @@
|
||||
post_comment_do['group'] = post_comment_form.group ?? null;
|
||||
post_comment_do['enable'] = post_comment_form.enable ?? true;
|
||||
|
||||
if (!$idaa_slct.post_comment_id) {
|
||||
// NEW COMMENT: Ensure post_id is included
|
||||
const parent_post_id = $idaa_slct.post_id;
|
||||
post_comment_do['post_id'] = parent_post_id;
|
||||
// post_comment_do['post_id'] = parent_post_id;
|
||||
}
|
||||
|
||||
log_lvl = 1;
|
||||
if (log_lvl) {
|
||||
console.log('Final Payload (post_comment_do):', post_comment_do);
|
||||
@@ -819,7 +812,7 @@ Copy and paste link: <a href="${link_base_url}?post_id=${$idaa_slct.post_id}">${
|
||||
type="submit"
|
||||
disabled={disable_submit_btn}
|
||||
onclick={() => {
|
||||
if (!confirm('Are you sure you want to create this post?')) {
|
||||
if (!confirm('Are you sure you want to add this comment?')) {
|
||||
return false;
|
||||
}
|
||||
// handle_save_post_comment_obj({post_id: $idaa_slct.post_id, method: 'create'});
|
||||
|
||||
@@ -161,13 +161,8 @@
|
||||
{#if ($ae_loc.trusted_access && $ae_loc.edit_mode) || $idaa_loc.novi_uuid}
|
||||
<button type="button"
|
||||
onclick={() => {
|
||||
if (!confirm('Are you sure you want to add a new comment?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$idaa_slct.post_comment_id = null;
|
||||
$idaa_slct.post_comment_obj = {};
|
||||
|
||||
$idaa_sess.bb.show__inline_edit__post_comment_id = true;
|
||||
}}
|
||||
class="
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
import { posts_func } from '$lib/ae_posts/ae_posts_functions';
|
||||
import Help_tech from '$lib/app_components/e_app_help_tech.svelte';
|
||||
|
||||
let creating = $state(false); // true while create API call is in-flight
|
||||
|
||||
// let ae_promises: key_val = {};
|
||||
// let ae_tmp: key_val = {};
|
||||
// let ae_trigger: any = null;
|
||||
@@ -170,12 +172,13 @@
|
||||
|
||||
{#if ($ae_loc.trusted_access && $ae_loc.edit_mode) || $idaa_loc.novi_uuid}
|
||||
<button type="button"
|
||||
disabled={!$ae_loc.authenticated_access}
|
||||
disabled={creating || !$ae_loc.authenticated_access}
|
||||
onclick={() => {
|
||||
if (!confirm('Create new post?')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
creating = true;
|
||||
$idaa_slct.post_obj = {};
|
||||
|
||||
let data_kv = {
|
||||
@@ -211,6 +214,7 @@
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error creating post:', error);
|
||||
creating = false; // Re-enable so user can retry
|
||||
alert('Failed to create post.');
|
||||
})
|
||||
.finally(() => {
|
||||
@@ -219,26 +223,10 @@
|
||||
if (log_lvl) console.log(`Redirecting to new post: ${final_id}`);
|
||||
goto(`/idaa/bb/${final_id}`);
|
||||
} else {
|
||||
creating = false;
|
||||
alert('Failed to create new post.');
|
||||
}
|
||||
});
|
||||
|
||||
// $idaa_slct.post_id = '';
|
||||
// $idaa_slct.post_id = undefined;
|
||||
// $idaa_slct.post_id = null;
|
||||
// $idaa_slct.post_obj = {};
|
||||
|
||||
// const url = new URL(location);
|
||||
// url.searchParams.delete('post_id');
|
||||
// history.pushState({}, '', url);
|
||||
|
||||
// $idaa_loc.bb.show_main__options = false;
|
||||
// $idaa_loc.bb.show_list__post_obj_li = false;
|
||||
// $idaa_loc.bb.show_view__post_obj = false;
|
||||
// $idaa_loc.bb.show_edit__post_obj = true;
|
||||
|
||||
// $idaa_sess.bb.show__modal_view__post_id = true;
|
||||
// $idaa_sess.bb.show__inline_edit__post_obj = true;
|
||||
}}
|
||||
class="
|
||||
novi_btn novi_white btn-tertiary
|
||||
@@ -249,7 +237,11 @@
|
||||
"
|
||||
title="Create new post"
|
||||
>
|
||||
<span class="fas fa-plus m-1"></span> Create New Post
|
||||
{#if creating}
|
||||
<span class="fas fa-spinner fa-spin m-1"></span> Creating...
|
||||
{:else}
|
||||
<span class="fas fa-plus m-1"></span> Create New Post
|
||||
{/if}
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user