Working on getting Recovery Meeting edit to show correctly when navigating from list of meetings.

This commit is contained in:
Scott Idem
2025-07-08 20:12:28 -04:00
parent 8672796bac
commit 6bdedecfd8
6 changed files with 111 additions and 50 deletions

View File

@@ -107,6 +107,7 @@ let idaa_session_data_struct: key_val = {
show__modal_view__archive_id: null,
show__modal_edit__archive_content_id: null,
show__modal_view__archive_content_id: null,
obj_changed: false, // Used to track if the archive object has been changed in the edit view
},
bb: {
@@ -127,6 +128,7 @@ let idaa_session_data_struct: key_val = {
show__modal_view: false,
show__modal_edit__event_id: null,
show__modal_view__event_id: null,
obj_changed: false, // Used to track if the event object has been changed in the edit view
},
};

View File

@@ -37,6 +37,9 @@ $idaa_trig.post_id = ae_acct.slct.post_id;
// Functions and Logic
let lq__post_obj = $derived(liveQuery(async () => {
if (log_lvl) {
console.log(`lq__post_obj: post_id = ${$idaa_slct?.post_id}`);
}
let results = await db_posts.post
.get($idaa_slct.post_id ?? ''); // null or undefined does not reset things like '' does

View File

@@ -36,7 +36,7 @@ export const load = (async ({ params, parent }) => { // route
message: 'IDAA BB - Post not found'
});
} else {
// ae_acct.slct.journal_obj = results;
// ae_acct.slct.post_obj = results;
}
});

View File

@@ -33,6 +33,7 @@ if (log_lvl) {
$idaa_sess.recovery_meetings.edit__event_id = null;
$idaa_slct.event_id = ae_acct.slct.event_id;
$idaa_trig.event_id = ae_acct.slct.event_id;
// $idaa_slct.event_obj = ae_acct.slct.event_obj;
@@ -44,6 +45,17 @@ let lq__event_obj = $derived(liveQuery(async () => {
let results = await db_events.events
.get($idaa_slct?.event_id ?? ''); // null or undefined does not reset things like '' does
// Check if results are different than the current $idaa_slct.event_obj
if ($idaa_slct.event_obj && results) {
if (JSON.stringify($idaa_slct.event_obj) !== JSON.stringify(results)) {
$idaa_slct.event_obj = { ...results};
} else {
if (log_lvl) {
console.log(`Event object has not changed for event_id: ${$idaa_slct.event_id}`);
}
}
}
return results;
}));
@@ -196,6 +208,7 @@ onDestroy(() => {
{#if $idaa_sess.recovery_meetings.edit__event_id}
<Event_obj_id_edit
lq__event_obj={lq__event_obj}
bind:obj_changed={$idaa_sess.recovery_meetings.obj_changed}
/>
{:else}
<Event_obj_id_view

View File

@@ -2,6 +2,7 @@ import type { PageLoad } from './$types';
console.log(`ae_p_idaa_events [event_id] +page.ts start`);
import { error } from '@sveltejs/kit';
import { browser } from '$app/environment';
import { events_func } from '$lib/ae_events_functions';
@@ -27,7 +28,17 @@ export const load = (async ({ params, parent }) => { // route
api_cfg: ae_acct.api,
event_id: event_id,
log_lvl: log_lvl
})
.then((results) => {
if (!results) {
error(404, {
message: 'IDAA Recovery Meetings - Event not found'
});
} else {
// ae_acct.slct.event_obj = results;
}
});
if (log_lvl) {
console.log(`load_event_obj = `, load_event_obj);
}

View File

@@ -1,6 +1,19 @@
<script lang="ts">
export let log_lvl: number = 0;
interface Props {
log_lvl?: number;
lq__event_obj: any;
obj_changed: boolean;
}
let {
log_lvl = $bindable(0),
lq__event_obj,
obj_changed = $bindable(false)
}: Props = $props();
// *** Import Svelte core
import { run, preventDefault } from 'svelte/legacy';
// import { onDestroy, onMount } from 'svelte';
import { fade } from 'svelte/transition';
import { browser } from '$app/environment';
@@ -14,12 +27,22 @@ import { idaa_loc, idaa_sess, idaa_slct } from '$lib/ae_idaa_stores';
import { events_func } from '$lib/ae_events_functions';
import Tiptap_editor from '$lib/element_tiptap_editor.svelte';
export let lq__event_obj: any;
// export let container_class_li = [];
let prom_api__event_obj: any;
let prom_api__event_obj: any = $state();
let disable_submit_btn = true;
let description_new_html = $state('');
let description_changed = $state(false);
let location_text_new_html = $state('');
let location_text_changed = $state(false);
let attend_text_new_html = $state('');
let attend_text_changed = $state(false);
let recurring_text_new_html = $state('');
let recurring_text_changed = $state(false);
let notes_new_html = $state('');
let notes_changed = $state(false);
let disable_submit_btn = $state(true);
// $: if (browser) {
// document.body.scrollIntoView();
@@ -146,7 +169,7 @@ if ($ae_loc.lu_time_zone_list && $ae_loc.lu_time_zone_list.length > 0 && Math.ra
// });
}
let lu_country_list = localStorage.getItem('lu_country_list') ? JSON.parse(localStorage.getItem('lu_country_list') ?? '') : [];
let lu_country_list = $state(localStorage.getItem('lu_country_list') ? JSON.parse(localStorage.getItem('lu_country_list') ?? '') : []);
// $ae_loc.lu_country_list = []; // Reset the list
// Refresh the list at least 20% of the time.
if (lu_country_list && lu_country_list.length > 50 && Math.random() < 0.8) {
@@ -175,7 +198,7 @@ if (lu_country_list && lu_country_list.length > 50 && Math.random() < 0.8) {
});
}
let lu_country_subdivision_list = localStorage.getItem('lu_country_subdivision_list') ? JSON.parse(localStorage.getItem('lu_country_subdivision_list') ?? '') : [];
let lu_country_subdivision_list = $state(localStorage.getItem('lu_country_subdivision_list') ? JSON.parse(localStorage.getItem('lu_country_subdivision_list') ?? '') : []);
// $ae_loc.lu_country_subdivision_list = []; // Reset the list
// Refresh the list at least 20% of the time.
if (lu_country_subdivision_list && lu_country_subdivision_list.length > 50 && Math.random() < 0.8) {
@@ -206,17 +229,19 @@ if (lu_country_subdivision_list && lu_country_subdivision_list.length > 50 && Ma
}
$: if ($idaa_slct.event_obj) {
if (log_lvl) {
console.log('Selected Event object changed?', $idaa_slct.event_obj);
}
$effect(() => {
if ($idaa_slct.event_obj) {
if (log_lvl) {
console.log('Selected Event object changed?', $idaa_slct.event_obj);
}
if ($idaa_slct.event_obj == null) {
$idaa_slct.event_obj = {contact_li_json: []};
} else {
disable_submit_btn = false;
if ($idaa_slct.event_obj == null) {
$idaa_slct.event_obj = {contact_li_json: []};
} else {
disable_submit_btn = false;
}
}
}
});
async function handle_submit_form(event: any) {
@@ -246,14 +271,16 @@ async function handle_submit_form(event: any) {
event_do['name'] = event_meeting_fd.name;
// Check if the description_new_html exists and is a string
if (typeof $idaa_slct.event_obj.description_new_html === 'string') {
if (typeof description_new_html === 'string') {
console.log('New description is a string');
event_do['description'] = $idaa_slct.event_obj.description_new_html;
event_do['description'] = description_new_html;
} else {
console.log('New description is not a string. Do nothing.');
// event_do['description'] = event_meeting_fd.description;
}
event_do['type'] = event_meeting_fd.type;
event_do['physical'] = !!event_meeting_fd.physical;
event_do['virtual'] = !!event_meeting_fd.virtual;
@@ -284,8 +311,8 @@ async function handle_submit_form(event: any) {
event_do['location_address_json'] = address;
// Check if the location_text_new_html exists and is a string
if (typeof $idaa_slct.event_obj.location_text_new_html === 'string') {
event_do['location_text'] = $idaa_slct.event_obj.location_text_new_html;
if (typeof location_text_new_html === 'string') {
event_do['location_text'] = location_text_new_html;
} else {
console.log('New location text is not a string. Do nothing.');
}
@@ -296,8 +323,8 @@ async function handle_submit_form(event: any) {
event_do['attend_phone_passcode'] = event_meeting_fd.attend_phone_passcode;
// Check if the attend_text_new_html exists and is a string
if (typeof $idaa_slct.event_obj.attend_text_new_html === 'string') {
event_do['attend_text'] = $idaa_slct.event_obj.attend_text_new_html;
if (typeof attend_text_new_html === 'string') {
event_do['attend_text'] = attend_text_new_html;
} else {
console.log('New attend text is not a string. Do nothing.');
}
@@ -324,11 +351,11 @@ async function handle_submit_form(event: any) {
}
// Check if the recurring_text_new_html exists and is a string
if (typeof $idaa_slct.event_obj.recurring_text_new_html === 'string') {
if (typeof recurring_text_new_html === 'string') {
if (log_lvl) {
console.log(`New recurring text is a string: ${$idaa_slct.event_obj.recurring_text_new_html}`);
console.log(`New recurring text is a string: ${recurring_text_new_html}`);
}
event_do['recurring_text'] = $idaa_slct.event_obj.recurring_text_new_html;
event_do['recurring_text'] = recurring_text_new_html;
} else {
if (log_lvl) {
console.log('New recurring text is not a string. Do nothing.');
@@ -424,8 +451,8 @@ async function handle_submit_form(event: any) {
}
// Check if the notes_new_html exists and is a string
if (typeof $idaa_slct.event_obj.notes_new_html === 'string') {
event_do['notes'] = $idaa_slct.event_obj.notes_new_html;
if (typeof notes_new_html === 'string') {
event_do['notes'] = notes_new_html;
} else {
console.log('New notes is not a string. Do nothing.');
}
@@ -608,7 +635,7 @@ function send_staff_notification_email() {
bind:clientHeight={$ae_loc.iframe_height_modal_body}
>
<form on:submit|preventDefault={handle_submit_form} class="relative space-y-1">
<form onsubmit={preventDefault(handle_submit_form)} class="relative space-y-1">
{#await prom_api__event_obj}
<div class="awaiting alert_msg_pulse" out:fade={{ duration: 2000 }}>Saving...</div>
@@ -670,9 +697,10 @@ function send_staff_notification_email() {
<Tiptap_editor
default_minimal={true}
bind:html_text={$idaa_slct.event_obj.description}
html_text={$idaa_slct.event_obj?.description}
show_button_kv={{'heading__h1': false, 'heading__h2': false, 'heading__h3': false}}
bind:new_html={$idaa_slct.event_obj.description_new_html}
bind:new_html={description_new_html}
bind:changed={description_changed}
classes="preset-tonal-surface hover:preset-filled-surface-100-900"
placeholder="A short description or overview of this recovery meeting"
/>
@@ -845,9 +873,10 @@ function send_staff_notification_email() {
<!-- <textarea class="ae_value event__location_text tinymce_editor editor_less_100 textarea" id="location_text" name="location_text" placeholder="Additional information about the meeting location" rows="2" cols="70" bind:value={$idaa_slct.event_obj.location_text}></textarea> -->
<Tiptap_editor
default_minimal={true}
bind:html_text={$idaa_slct.event_obj.location_text}
html_text={$idaa_slct.event_obj?.location_text}
show_button_kv={{'heading__h1': false, 'heading__h2': false, 'heading__h3': false}}
bind:new_html={$idaa_slct.event_obj.location_text_new_html}
bind:new_html={location_text_new_html}
bind:changed={location_text_changed}
classes="preset-tonal-surface hover:preset-filled-surface-100-900"
placeholder="Additional information about the meeting location"
/>
@@ -896,9 +925,10 @@ function send_staff_notification_email() {
<!-- <textarea class="ae_value event__attend_text tinymce_editor editor_less_100 textarea" id="attend_text" name="attend_text" placeholder="Additional information on how to attend or join the meeting" rows="2" cols="70" value={$lq__event_obj?.attend_text ?? ''}></textarea> -->
<Tiptap_editor
default_minimal={true}
bind:html_text={$idaa_slct.event_obj.attend_text}
html_text={$idaa_slct.event_obj?.attend_text}
show_button_kv={{'heading__h1': false, 'heading__h2': false, 'heading__h3': false}}
bind:new_html={$idaa_slct.event_obj.attend_text_new_html}
bind:new_html={attend_text_new_html}
bind:changed={attend_text_changed}
classes="preset-tonal-surface hover:preset-filled-surface-100-900"
placeholder="Additional information on how to attend or join the meeting"
/>
@@ -1072,7 +1102,7 @@ function send_staff_notification_email() {
<!-- <textarea class="ae_value event__recurring_text tinymce_editor editor_less_100 textarea" id="recurring_text" name="recurring_text" placeholder="Additional information on when and how often" value={$lq__event_obj?.recurring_text ?? ''}></textarea> -->
<Tiptap_editor
default_minimal={true}
bind:html_text={$idaa_slct.event_obj.recurring_text}
html_text={$idaa_slct.event_obj?.recurring_text}
show_button_kv={{
// text: true,
// bullet_list: true,
@@ -1080,7 +1110,8 @@ function send_staff_notification_email() {
// link: true,
// unset_link: true
}}
bind:new_html={$idaa_slct.event_obj.recurring_text_new_html}
bind:new_html={recurring_text_new_html}
bind:changed={recurring_text_changed}
classes="preset-tonal-surface hover:preset-filled-surface-100-900"
placeholder="Additional information on when and how often"
/>
@@ -1110,7 +1141,7 @@ function send_staff_notification_email() {
btn btn-sm
preset-filled-tertiary-200-800
"
on:click={() => {
onclick={() => {
if (confirm('Are you sure you want to remove the text for the additional details?')) {
$idaa_slct.event_obj.recurring_text = '';
$idaa_slct.event_obj.recurring_text_new_html = '';
@@ -1131,13 +1162,13 @@ function send_staff_notification_email() {
btn btn-sm
preset-filled-success-200-800
"
on:click|preventDefault={() => {
onclick={preventDefault(() => {
// Remove *gen* prefix from recurring_text
if ($lq__event_obj.recurring_text && $lq__event_obj.recurring_text.includes('*gen*')) {
$idaa_slct.event_obj.recurring_text = $lq__event_obj.recurring_text.replace('*gen* ', '');
}
$idaa_slct.event_obj.show_recurring_text = true;
}}
})}
>
<span class="fas fa-plus m-1"></span> Add More Details?
</button>
@@ -1207,7 +1238,7 @@ function send_staff_notification_email() {
{#if !($ae_loc.administrator_access || ($idaa_slct.event_obj?.contact_li_json?.length && $idaa_slct.event_obj?.contact_li_json[0]?.unlock))}
<button
type="button"
on:click|preventDefault={() => {
onclick={preventDefault(() => {
if (confirm('Are you sure you want to lock these fields? The primary contact name and email address are required.')) {
if (!$idaa_slct.event_obj?.contact_li_json[0]) {
$idaa_slct.event_obj.contact_li_json[0] = {};
@@ -1217,7 +1248,7 @@ function send_staff_notification_email() {
$idaa_slct.event_obj.contact_li_json[0].unlock = false;
return false;
}
}}
})}
class="
novi_btn novi_smaller ae_btn_info
btn btn-sm
@@ -1229,9 +1260,9 @@ function send_staff_notification_email() {
{:else}
<button
type="button"
on:click|preventDefault={() => {
onclick={preventDefault(() => {
$idaa_slct.event_obj.contact_li_json[0].unlock = false;
}}
})}
class="
novi_btn novi_smaller ae_btn_info
btn btn-sm
@@ -1324,7 +1355,7 @@ function send_staff_notification_email() {
{#if $ae_loc.trusted_access}
<button
type="button"
on:click={() => {
onclick={() => {
$idaa_loc.recovery_meetings.show__admin_options = !$idaa_loc.recovery_meetings.show__admin_options;
}}
class="
@@ -1497,9 +1528,10 @@ function send_staff_notification_email() {
Internal Staff Notes
<Tiptap_editor
default_minimal={true}
bind:html_text={$idaa_slct.event_obj.notes}
html_text={$idaa_slct.event_obj?.notes}
show_button_kv={{'heading__h1': false, 'heading__h2': false, 'heading__h3': false}}
bind:new_html={$idaa_slct.event_obj.notes_new_html}
bind:new_html={notes_new_html}
bind:changed={notes_changed}
classes="preset-tonal-surface hover:preset-filled-surface-100-900"
placeholder="Internal notes for staff only. Not shown to the public."
/>
@@ -1532,7 +1564,7 @@ function send_staff_notification_email() {
<button
type="submit"
disabled={(disable_submit_btn)}
on:click={() => {
onclick={() => {
if (!confirm('Are you sure you want to create this event?')) {return false;}
// handle_save_event_obj({event_id: $idaa_slct.event_id, method: 'create'});
}}
@@ -1555,7 +1587,7 @@ function send_staff_notification_email() {
{#if $ae_loc.administrator_access}
<button
type="button"
on:click={() => {
onclick={() => {
if (!confirm('Are you sure you want to delete this event?')) {return false;}
handle_delete_event_obj({event_id: $idaa_slct.event_id, method: 'delete'});
}}
@@ -1571,7 +1603,7 @@ function send_staff_notification_email() {
{:else if $ae_loc.trusted_access}
<button
type="button"
on:click={() => {
onclick={() => {
if (!confirm('Are you sure you want to disable this event?')) {return false;}
handle_delete_event_obj({event_id: $idaa_slct.event_id, method: 'disable'});
}}
@@ -1588,7 +1620,7 @@ function send_staff_notification_email() {
{:else}
<button
type="button"
on:click={() => {
onclick={() => {
if (!confirm('Are you sure you want to hide this event?')) {return false;}
handle_delete_event_obj({event_id: $idaa_slct.event_id, method: 'hide'});
}}