diff --git a/src/lib/ae_api/api_post_object.ts b/src/lib/ae_api/api_post_object.ts index 978b935b..a1f1dd9a 100644 --- a/src/lib/ae_api/api_post_object.ts +++ b/src/lib/ae_api/api_post_object.ts @@ -145,20 +145,22 @@ export const post_object = async function post_object({ // Post a message to the window indicating the upload is complete try { - window.postMessage( - { - type: 'api_post_json_form', - status: 'complete', - task_id: task_id, - endpoint: endpoint, - size_total: 0, - size_loaded: 0, - percent_completed: 100, - progress: 100, - rate: 0 - }, - '*' - ); + if (typeof window !== 'undefined') { + window.postMessage( + { + type: 'api_post_json_form', + status: 'complete', + task_id: task_id, + endpoint: endpoint, + size_total: 0, + size_loaded: 0, + percent_completed: 100, + progress: 100, + rate: 0 + }, + '*' + ); + } } catch (error) { console.error('Error posting message to window:', error); } diff --git a/src/lib/ae_core/ae_core__address.editable_fields.ts b/src/lib/ae_core/ae_core__address.editable_fields.ts new file mode 100644 index 00000000..3dd1ca59 --- /dev/null +++ b/src/lib/ae_core/ae_core__address.editable_fields.ts @@ -0,0 +1,11 @@ +export const editable_fields__address = [ + 'city', + 'state_province', + 'country', + 'enable', + 'hide', + 'priority', + 'sort', + 'group', + 'notes' +]; diff --git a/src/lib/ae_core/ae_core__address.ts b/src/lib/ae_core/ae_core__address.ts index f7e06e60..dc383f1a 100644 --- a/src/lib/ae_core/ae_core__address.ts +++ b/src/lib/ae_core/ae_core__address.ts @@ -30,19 +30,72 @@ export interface Address { updated_on?: null | Date; } +// Updated 2026-01-06 +export async function load_ae_obj_id__address({ + api_cfg, + address_id, + view = 'default', + params = {}, + try_cache = true, + log_lvl = 0 +}: { + api_cfg: any; + address_id: string; + view?: string; + params?: key_val; + try_cache?: boolean; + log_lvl?: number; +}) { + ae_promises.load__address_obj = await api.get_ae_obj_v3({ + api_cfg, + obj_type: 'address', + obj_id: address_id, + view, + params, + log_lvl + }).then(async (result) => { + if (result) { + if (try_cache) { + const processed = await process_ae_obj__address_props({ obj_li: [result], log_lvl }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_core, + table_name: 'address', + obj_li: processed, + properties_to_save, + log_lvl + }); + } + return result; + } + return null; + }); + return ae_promises.load__address_obj; +} + +// Updated 2026-01-06 export async function load_ae_obj_li__address({ api_cfg, - for_obj_type, + for_obj_type = 'account', for_obj_id, enabled = 'enabled', hidden = 'not_hidden', + view = 'default', + limit = 99, + offset = 0, + order_by_li = { city: 'ASC' }, + try_cache = true, log_lvl = 0 }: { api_cfg: any; for_obj_type?: string; - for_obj_id?: string; + for_obj_id: string; enabled?: 'all' | 'enabled' | 'not_enabled'; hidden?: 'all' | 'hidden' | 'not_hidden'; + view?: string; + limit?: number; + offset?: number; + order_by_li?: Record; + try_cache?: boolean; log_lvl?: number; }) { ae_promises.load__address_obj_li = await api.get_ae_obj_li_v3({ @@ -52,17 +105,23 @@ export async function load_ae_obj_li__address({ for_obj_id, enabled, hidden, + view, + limit, + offset, + order_by_li, log_lvl }).then(async (result) => { if (result && Array.isArray(result)) { - const processed = await process_ae_obj__address_props({ obj_li: result, log_lvl }); - await db_save_ae_obj_li__ae_obj({ - db_instance: db_core, - table_name: 'address', - obj_li: processed, - properties_to_save: ['id', 'address_id', 'address_id_random', 'city', 'state_province', 'country', 'enable'], - log_lvl - }); + if (try_cache) { + const processed = await process_ae_obj__address_props({ obj_li: result, log_lvl }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_core, + table_name: 'address', + obj_li: processed, + properties_to_save, + log_lvl + }); + } return result; } return []; @@ -70,10 +129,186 @@ export async function load_ae_obj_li__address({ return ae_promises.load__address_obj_li; } -export async function process_ae_obj__address_props({ obj_li, log_lvl = 0 }: { obj_li: any[], log_lvl?: number }) { - return obj_li.map(obj => { - const new_obj = { ...obj }; - new_obj.id = obj.address_id_random; - return new_obj; +// Updated 2026-01-06 +export async function create_ae_obj__address({ + api_cfg, + account_id, + data_kv, + params = {}, + try_cache = true, + log_lvl = 0 +}: { + api_cfg: any; + account_id: string; + data_kv: key_val; + params?: key_val; + try_cache?: boolean; + log_lvl?: number; +}) { + const result = await api.create_ae_obj_v3({ + api_cfg, + obj_type: 'address', + fields: { + account_id_random: account_id, + ...data_kv + }, + params, + log_lvl }); + + if (result && try_cache) { + const processed = await process_ae_obj__address_props({ obj_li: [result], log_lvl }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_core, + table_name: 'address', + obj_li: processed, + properties_to_save, + log_lvl + }); + } + return result; } + +// Updated 2026-01-06 +export async function update_ae_obj__address({ + api_cfg, + address_id, + data_kv, + params = {}, + try_cache = true, + log_lvl = 0 +}: { + api_cfg: any; + address_id: string; + data_kv: key_val; + params?: key_val; + try_cache?: boolean; + log_lvl?: number; +}) { + const result = await api.update_ae_obj_v3({ + api_cfg, + obj_type: 'address', + obj_id: address_id, + fields: data_kv, + params, + log_lvl + }); + + if (result && try_cache) { + const processed = await process_ae_obj__address_props({ obj_li: [result], log_lvl }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_core, + table_name: 'address', + obj_li: processed, + properties_to_save, + log_lvl + }); + } + return result; +} + +// Updated 2026-01-06 +export async function delete_ae_obj_id__address({ + api_cfg, + address_id, + method = 'delete', + params = {}, + try_cache = true, + log_lvl = 0 +}: { + api_cfg: any; + address_id: string; + method?: 'delete' | 'soft_delete' | 'disable' | 'hide'; + params?: key_val; + try_cache?: boolean; + log_lvl?: number; +}) { + const result = await api.delete_ae_obj_v3({ + api_cfg, + obj_type: 'address', + obj_id: address_id, + method, + params, + log_lvl + }); + + if (try_cache) { + await db_core.address.delete(address_id); + } + return result; +} + +export const properties_to_save = [ + 'id', + 'address_id', + 'address_id_random', + 'account_id', + 'account_id_random', + 'for_type', + 'for_id', + 'for_id_random', + 'city', + 'state_province', + 'country', + 'enable', + 'hide', + 'priority', + 'sort', + 'group', + 'notes', + 'created_on', + 'updated_on' +]; + +async function _process_generic_props>({ + obj_li, + obj_type, + log_lvl = 0, + specific_processor +}: { + obj_li: T[]; + obj_type: string; + log_lvl?: number; + specific_processor?: (obj: T) => Promise | T; +}): Promise { + if (!obj_li || obj_li.length === 0) return []; + + const processed_obj_li: T[] = []; + + for (const original_obj of obj_li) { + let processed_obj = { ...original_obj }; + + for (const key in processed_obj) { + if (key.endsWith('_random')) { + const newKey = key.slice(0, -7); + (processed_obj as any)[newKey] = processed_obj[key]; + } + } + const randomIdKey = `${obj_type}_id_random`; + if (processed_obj[randomIdKey]) { + (processed_obj as any).id = processed_obj[randomIdKey]; + } + + if (specific_processor) { + processed_obj = await Promise.resolve(specific_processor(processed_obj)); + } + + processed_obj_li.push(processed_obj as T); + } + + return processed_obj_li; +} + +export async function process_ae_obj__address_props({ + obj_li, + log_lvl = 0 +}: { + obj_li: any[]; + log_lvl?: number; +}) { + return _process_generic_props({ + obj_li, + obj_type: 'address', + log_lvl + }); +} \ No newline at end of file diff --git a/src/lib/ae_core/ae_core__contact.editable_fields.ts b/src/lib/ae_core/ae_core__contact.editable_fields.ts new file mode 100644 index 00000000..b61e0558 --- /dev/null +++ b/src/lib/ae_core/ae_core__contact.editable_fields.ts @@ -0,0 +1,11 @@ +export const editable_fields__contact = [ + 'name', + 'email', + 'phone', + 'enable', + 'hide', + 'priority', + 'sort', + 'group', + 'notes' +]; diff --git a/src/lib/ae_core/ae_core__contact.ts b/src/lib/ae_core/ae_core__contact.ts index b883747b..04be5869 100644 --- a/src/lib/ae_core/ae_core__contact.ts +++ b/src/lib/ae_core/ae_core__contact.ts @@ -30,19 +30,72 @@ export interface Contact { updated_on?: null | Date; } +// Updated 2026-01-06 +export async function load_ae_obj_id__contact({ + api_cfg, + contact_id, + view = 'default', + params = {}, + try_cache = true, + log_lvl = 0 +}: { + api_cfg: any; + contact_id: string; + view?: string; + params?: key_val; + try_cache?: boolean; + log_lvl?: number; +}) { + ae_promises.load__contact_obj = await api.get_ae_obj_v3({ + api_cfg, + obj_type: 'contact', + obj_id: contact_id, + view, + params, + log_lvl + }).then(async (result) => { + if (result) { + if (try_cache) { + const processed = await process_ae_obj__contact_props({ obj_li: [result], log_lvl }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_core, + table_name: 'contact', + obj_li: processed, + properties_to_save, + log_lvl + }); + } + return result; + } + return null; + }); + return ae_promises.load__contact_obj; +} + +// Updated 2026-01-06 export async function load_ae_obj_li__contact({ api_cfg, - for_obj_type, + for_obj_type = 'account', for_obj_id, enabled = 'enabled', hidden = 'not_hidden', + view = 'default', + limit = 99, + offset = 0, + order_by_li = { name: 'ASC' }, + try_cache = true, log_lvl = 0 }: { api_cfg: any; for_obj_type?: string; - for_obj_id?: string; + for_obj_id: string; enabled?: 'all' | 'enabled' | 'not_enabled'; hidden?: 'all' | 'hidden' | 'not_hidden'; + view?: string; + limit?: number; + offset?: number; + order_by_li?: Record; + try_cache?: boolean; log_lvl?: number; }) { ae_promises.load__contact_obj_li = await api.get_ae_obj_li_v3({ @@ -52,17 +105,23 @@ export async function load_ae_obj_li__contact({ for_obj_id, enabled, hidden, + view, + limit, + offset, + order_by_li, log_lvl }).then(async (result) => { if (result && Array.isArray(result)) { - const processed = await process_ae_obj__contact_props({ obj_li: result, log_lvl }); - await db_save_ae_obj_li__ae_obj({ - db_instance: db_core, - table_name: 'contact', - obj_li: processed, - properties_to_save: ['id', 'contact_id', 'contact_id_random', 'name', 'email', 'phone', 'enable'], - log_lvl - }); + if (try_cache) { + const processed = await process_ae_obj__contact_props({ obj_li: result, log_lvl }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_core, + table_name: 'contact', + obj_li: processed, + properties_to_save, + log_lvl + }); + } return result; } return []; @@ -70,10 +129,186 @@ export async function load_ae_obj_li__contact({ return ae_promises.load__contact_obj_li; } -export async function process_ae_obj__contact_props({ obj_li, log_lvl = 0 }: { obj_li: any[], log_lvl?: number }) { - return obj_li.map(obj => { - const new_obj = { ...obj }; - new_obj.id = obj.contact_id_random; - return new_obj; +// Updated 2026-01-06 +export async function create_ae_obj__contact({ + api_cfg, + account_id, + data_kv, + params = {}, + try_cache = true, + log_lvl = 0 +}: { + api_cfg: any; + account_id: string; + data_kv: key_val; + params?: key_val; + try_cache?: boolean; + log_lvl?: number; +}) { + const result = await api.create_ae_obj_v3({ + api_cfg, + obj_type: 'contact', + fields: { + account_id_random: account_id, + ...data_kv + }, + params, + log_lvl }); + + if (result && try_cache) { + const processed = await process_ae_obj__contact_props({ obj_li: [result], log_lvl }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_core, + table_name: 'contact', + obj_li: processed, + properties_to_save, + log_lvl + }); + } + return result; } + +// Updated 2026-01-06 +export async function update_ae_obj__contact({ + api_cfg, + contact_id, + data_kv, + params = {}, + try_cache = true, + log_lvl = 0 +}: { + api_cfg: any; + contact_id: string; + data_kv: key_val; + params?: key_val; + try_cache?: boolean; + log_lvl?: number; +}) { + const result = await api.update_ae_obj_v3({ + api_cfg, + obj_type: 'contact', + obj_id: contact_id, + fields: data_kv, + params, + log_lvl + }); + + if (result && try_cache) { + const processed = await process_ae_obj__contact_props({ obj_li: [result], log_lvl }); + await db_save_ae_obj_li__ae_obj({ + db_instance: db_core, + table_name: 'contact', + obj_li: processed, + properties_to_save, + log_lvl + }); + } + return result; +} + +// Updated 2026-01-06 +export async function delete_ae_obj_id__contact({ + api_cfg, + contact_id, + method = 'delete', + params = {}, + try_cache = true, + log_lvl = 0 +}: { + api_cfg: any; + contact_id: string; + method?: 'delete' | 'soft_delete' | 'disable' | 'hide'; + params?: key_val; + try_cache?: boolean; + log_lvl?: number; +}) { + const result = await api.delete_ae_obj_v3({ + api_cfg, + obj_type: 'contact', + obj_id: contact_id, + method, + params, + log_lvl + }); + + if (try_cache) { + await db_core.contact.delete(contact_id); + } + return result; +} + +export const properties_to_save = [ + 'id', + 'contact_id', + 'contact_id_random', + 'account_id', + 'account_id_random', + 'for_type', + 'for_id', + 'for_id_random', + 'name', + 'email', + 'phone', + 'enable', + 'hide', + 'priority', + 'sort', + 'group', + 'notes', + 'created_on', + 'updated_on' +]; + +async function _process_generic_props>({ + obj_li, + obj_type, + log_lvl = 0, + specific_processor +}: { + obj_li: T[]; + obj_type: string; + log_lvl?: number; + specific_processor?: (obj: T) => Promise | T; +}): Promise { + if (!obj_li || obj_li.length === 0) return []; + + const processed_obj_li: T[] = []; + + for (const original_obj of obj_li) { + let processed_obj = { ...original_obj }; + + for (const key in processed_obj) { + if (key.endsWith('_random')) { + const newKey = key.slice(0, -7); + (processed_obj as any)[newKey] = processed_obj[key]; + } + } + const randomIdKey = `${obj_type}_id_random`; + if (processed_obj[randomIdKey]) { + (processed_obj as any).id = processed_obj[randomIdKey]; + } + + if (specific_processor) { + processed_obj = await Promise.resolve(specific_processor(processed_obj)); + } + + processed_obj_li.push(processed_obj as T); + } + + return processed_obj_li; +} + +export async function process_ae_obj__contact_props({ + obj_li, + log_lvl = 0 +}: { + obj_li: any[]; + log_lvl?: number; +}) { + return _process_generic_props({ + obj_li, + obj_type: 'contact', + log_lvl + }); +} \ No newline at end of file diff --git a/src/lib/ae_core/core__idb_dexie.ts b/src/lib/ae_core/core__idb_dexie.ts index eed7319c..efcda589 100644 --- a/src/lib/ae_core/core__idb_dexie.ts +++ b/src/lib/ae_core/core__idb_dexie.ts @@ -1,4 +1,5 @@ import type { Dexie, Table } from 'dexie'; +import { browser } from '$app/environment'; /** * Extracts the primary key from an object using a prioritized list of possible key names. @@ -61,6 +62,8 @@ export async function db_save_ae_obj_li__ae_obj>({ properties_to_save: (keyof T)[]; log_lvl?: number; }) { + if (!browser) return []; + if (log_lvl > 0) { console.log( `*** db_save_ae_obj_li__ae_obj: Attempting to save ${obj_li.length} objects to table "${table_name}" ***` diff --git a/src/lib/ae_events/ae_events__event.ts b/src/lib/ae_events/ae_events__event.ts index cf9a2ca2..ba2ff0dc 100644 --- a/src/lib/ae_events/ae_events__event.ts +++ b/src/lib/ae_events/ae_events__event.ts @@ -321,6 +321,7 @@ export async function qry_ae_obj_li__event({ for_obj_type = 'account', for_obj_id, qry_str, + qry_person_id = null, enabled = 'enabled', hidden = 'not_hidden', view = 'default', @@ -333,6 +334,7 @@ export async function qry_ae_obj_li__event({ for_obj_type?: string; for_obj_id: string; qry_str?: string; + qry_person_id?: string | null; enabled?: 'enabled' | 'all' | 'not_enabled'; hidden?: 'hidden' | 'all' | 'not_hidden'; view?: string; @@ -344,6 +346,10 @@ export async function qry_ae_obj_li__event({ const search_query: any = { and: [] }; if (qry_str) search_query.q = qry_str; + if (qry_person_id) { + search_query.and.push({ field: 'external_person_id', op: 'eq', value: qry_person_id }); + } + return await api.search_ae_obj_v3({ api_cfg, obj_type: 'event', diff --git a/src/lib/ae_posts/ae_posts__post.ts b/src/lib/ae_posts/ae_posts__post.ts index 5c922e58..3c5aa1f8 100644 --- a/src/lib/ae_posts/ae_posts__post.ts +++ b/src/lib/ae_posts/ae_posts__post.ts @@ -322,6 +322,7 @@ export async function qry__post({ api_cfg, account_id, qry_str, + qry_person_id = null, enabled = 'enabled', hidden = 'not_hidden', view = 'default', @@ -338,6 +339,7 @@ export async function qry__post({ api_cfg: any; account_id: string; qry_str?: string; + qry_person_id?: string | null; enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; view?: string; @@ -356,6 +358,10 @@ export async function qry__post({ search_query.q = qry_str; } + if (qry_person_id) { + search_query.and.push({ field: 'external_person_id', op: 'eq', value: qry_person_id }); + } + ae_promises.load__post_obj_li = await api.search_ae_obj_v3({ api_cfg, obj_type: 'post', diff --git a/src/routes/core/addresses/+page.svelte b/src/routes/core/addresses/+page.svelte index ff45d4f6..8625c230 100644 --- a/src/routes/core/addresses/+page.svelte +++ b/src/routes/core/addresses/+page.svelte @@ -2,8 +2,8 @@ import { onMount } from 'svelte'; import { ae_loc, ae_api, slct } from '$lib/stores/ae_stores'; import { goto } from '$app/navigation'; - import { MapPin, Plus, Search } from 'lucide-svelte'; - import { load_ae_obj_li__address } from '$lib/ae_core/ae_core__address'; + import { MapPin, Plus, Search, ExternalLink } from 'lucide-svelte'; + import { load_ae_obj_li__address, create_ae_obj__address } from '$lib/ae_core/ae_core__address'; let address_li: any[] = $state([]); let loading = $state(true); @@ -20,6 +20,27 @@ loading = false; } + async function handle_add() { + const city = prompt('Enter city:'); + if (!city) return; + const state_province = prompt('Enter state/province:'); + const country = prompt('Enter country:', 'USA'); + + const result = await create_ae_obj__address({ + api_cfg: $ae_api, + account_id: $ae_loc.account_id, + data_kv: { city, state_province, country, enable: true }, + log_lvl: 1 + }); + + if (result) { + load_addresses(); + if (result.address_id_random) { + goto(`/core/addresses/${result.address_id_random}`); + } + } + } + onMount(() => { if (!$ae_loc.manager_access) { goto('/core'); @@ -35,7 +56,7 @@

Address Management

- @@ -70,7 +91,9 @@ - + + Manage + {/each} diff --git a/src/routes/core/addresses/[address_id]/+page.svelte b/src/routes/core/addresses/[address_id]/+page.svelte new file mode 100644 index 00000000..a7575fd0 --- /dev/null +++ b/src/routes/core/addresses/[address_id]/+page.svelte @@ -0,0 +1,159 @@ + + +
+
+
+ + + +
+ +

{address ? `${address.city}, ${address.state_province}` : 'Loading Address...'}

+
+
+
+ + +
+
+ + {#if loading} +
+ {:else if address} +
+
+
+

Address Details

+
+ + + +
+
+ +
+

Internal Metadata

+
+ + + +
+
+
+ +
+
+

Status & Visibility

+
+ + + +
+
+ +
+

ID: {address.address_id_random}

+

Created: {new Date(address.created_on).toLocaleString()}

+ {#if address.updated_on} +

Updated: {new Date(address.updated_on).toLocaleString()}

+ {/if} +
+
+
+ {/if} +
diff --git a/src/routes/core/contacts/+page.svelte b/src/routes/core/contacts/+page.svelte index 8ea1a47c..0031b9e8 100644 --- a/src/routes/core/contacts/+page.svelte +++ b/src/routes/core/contacts/+page.svelte @@ -2,8 +2,8 @@ import { onMount } from 'svelte'; import { ae_loc, ae_api, slct } from '$lib/stores/ae_stores'; import { goto } from '$app/navigation'; - import { Phone, Plus, Search, Mail, User } from 'lucide-svelte'; - import { load_ae_obj_li__contact } from '$lib/ae_core/ae_core__contact'; + import { Phone, Plus, Search, Mail, User, ExternalLink } from 'lucide-svelte'; + import { load_ae_obj_li__contact, create_ae_obj__contact } from '$lib/ae_core/ae_core__contact'; let contact_li: any[] = $state([]); let loading = $state(true); @@ -20,6 +20,27 @@ loading = false; } + async function handle_add() { + const name = prompt('Enter contact name:'); + if (!name) return; + const email = prompt('Enter email address:'); + const phone = prompt('Enter phone number:'); + + const result = await create_ae_obj__contact({ + api_cfg: $ae_api, + account_id: $ae_loc.account_id, + data_kv: { name, email, phone, enable: true }, + log_lvl: 1 + }); + + if (result) { + load_contacts(); + if (result.contact_id_random) { + goto(`/core/contacts/${result.contact_id_random}`); + } + } + } + onMount(() => { if (!$ae_loc.manager_access) { goto('/core'); @@ -35,7 +56,7 @@

Contact Management

- @@ -80,7 +101,9 @@ - + + Manage + {/each} diff --git a/src/routes/core/contacts/[contact_id]/+page.svelte b/src/routes/core/contacts/[contact_id]/+page.svelte new file mode 100644 index 00000000..2c0e710f --- /dev/null +++ b/src/routes/core/contacts/[contact_id]/+page.svelte @@ -0,0 +1,159 @@ + + +
+
+
+ + + +
+ +

{contact?.name ?? 'Loading Contact...'}

+
+
+
+ + +
+
+ + {#if loading} +
+ {:else if contact} +
+
+
+

Contact Information

+
+ + + +
+
+ +
+

Internal Metadata

+
+ + + +
+
+
+ +
+
+

Status & Visibility

+
+ + + +
+
+ +
+

ID: {contact.contact_id_random}

+

Created: {new Date(contact.created_on).toLocaleString()}

+ {#if contact.updated_on} +

Updated: {new Date(contact.updated_on).toLocaleString()}

+ {/if} +
+
+
+ {/if} +
diff --git a/src/routes/core/people/[person_id]/+page.svelte b/src/routes/core/people/[person_id]/+page.svelte index 7a5ab482..d888a12b 100644 --- a/src/routes/core/people/[person_id]/+page.svelte +++ b/src/routes/core/people/[person_id]/+page.svelte @@ -3,6 +3,7 @@ // import { page } from '$app/stores'; // Imports + import { onMount } from 'svelte'; import type { key_val } from '$lib/stores/ae_stores'; import { ae_util } from '$lib/ae_utils/ae_utils'; // import { api } from '$lib/api'; @@ -29,7 +30,7 @@ import { load_ae_obj_li__user } from '$lib/ae_core/ae_core__user'; import { update_ae_obj__person } from '$lib/ae_core/ae_core__person'; import { qry_ae_obj_li__event } from '$lib/ae_events/ae_events__event'; - import { load_ae_obj_li__post } from '$lib/ae_posts/ae_posts__post'; + import { qry__post } from '$lib/ae_posts/ae_posts__post'; import { Users, Link, Unlink, UserPlus, ShieldCheck, User, Calendar, MessageSquare, History } from 'lucide-svelte'; interface Props { @@ -65,18 +66,17 @@ loading_activity = true; // Load related data using search queries - // Assuming person_id_random is the field name in these objects const [events, posts] = await Promise.all([ qry_ae_obj_li__event({ api_cfg: $ae_api, for_obj_id: $ae_loc.account_id, - params: { person_id_random: $slct.person_id }, + qry_person_id: $slct.person_id, log_lvl: 1 }), - load_ae_obj_li__post({ + qry__post({ api_cfg: $ae_api, - for_obj_id: $ae_loc.account_id, - params: { person_id_random: $slct.person_id }, + account_id: $ae_loc.account_id, + qry_person_id: $slct.person_id, log_lvl: 1 }) ]); diff --git a/src/routes/core/people/[person_id]/+page.ts b/src/routes/core/people/[person_id]/+page.ts index f40d0fe9..fa0cfb09 100644 --- a/src/routes/core/people/[person_id]/+page.ts +++ b/src/routes/core/people/[person_id]/+page.ts @@ -13,7 +13,11 @@ export async function load({ params, parent }) { data.log_lvl = log_lvl; const account_id = data.account_id; - const ae_acct = data[account_id]; + // Use spread syntax to create a shallow copy and avoid mutating the shared parent data structure. + // We specifically clone 'slct' because we will be mutating it below. + const ae_acct = { ...data[account_id] }; + ae_acct.slct = { ...ae_acct.slct }; + console.log(`ae_acct = `, ae_acct); const person_id = params.person_id; @@ -37,8 +41,8 @@ export async function load({ params, parent }) { ae_acct.slct.person_obj = load_person_obj; - // WARNING: Precaution against shared data between sites and presentations. - data[account_id] = ae_acct; - - return data; + return { + ...data, + [account_id]: ae_acct + }; }