refactor: standardize 'prevent_default' helpers and batch format modules
- Renamed internal 'preventDefault' helpers to 'prevent_default' for project-wide snake_case consistency. - Corrected native event method calls from 'prevent_default()' to 'preventDefault()' to resolve runtime TypeErrors. - Applied batch formatting (printWidth: 80) to Journals and IDAA Recovery Meetings modules. - Removed deprecated 'preventDefault' imports from svelte/legacy. - Fixed Journal Entry 404 by migrating loader to V3 API helper.
This commit is contained in:
@@ -20,10 +20,7 @@
|
||||
idaa_slct,
|
||||
idaa_trig
|
||||
} from '$lib/stores/ae_idaa_stores';
|
||||
import {
|
||||
ae_loc,
|
||||
ae_api
|
||||
} from '$lib/stores/ae_stores';
|
||||
import { ae_loc, ae_api } from '$lib/stores/ae_stores';
|
||||
import { events_func } from '$lib/ae_events_functions';
|
||||
|
||||
import Element_data_store from '$lib/elements/element_data_store_v3.svelte';
|
||||
@@ -80,7 +77,7 @@
|
||||
|
||||
/**
|
||||
* SWR (Stale-While-Revalidate) Search Orchestrator
|
||||
*
|
||||
*
|
||||
* GOAL: Render matching meetings in < 50ms, then update with perfect server data.
|
||||
*/
|
||||
async function handle_search_refresh() {
|
||||
@@ -90,7 +87,10 @@
|
||||
|
||||
if (!account_id) return;
|
||||
|
||||
if (log_lvl) console.log(`[Search #${current_search_id}] Refreshing recovery meetings (remote_first=${remote_first}) for account: ${account_id}...`);
|
||||
if (log_lvl)
|
||||
console.log(
|
||||
`[Search #${current_search_id}] Refreshing recovery meetings (remote_first=${remote_first}) for account: ${account_id}...`
|
||||
);
|
||||
|
||||
$idaa_sess.recovery_meetings.qry__status = 'loading';
|
||||
|
||||
@@ -100,7 +100,9 @@
|
||||
}
|
||||
|
||||
// Snapshot parameters to ensure the Fast Path and Revalidation are using the same criteria.
|
||||
const qry_str = ($idaa_loc.recovery_meetings.qry__fulltext_str ?? '').toLowerCase().trim();
|
||||
const qry_str = ($idaa_loc.recovery_meetings.qry__fulltext_str ?? '')
|
||||
.toLowerCase()
|
||||
.trim();
|
||||
const qry_physical = $idaa_loc.recovery_meetings.qry__physical;
|
||||
const qry_virtual = $idaa_loc.recovery_meetings.qry__virtual;
|
||||
const qry_type = $idaa_loc.recovery_meetings.qry__type;
|
||||
@@ -112,16 +114,19 @@
|
||||
if (!remote_first) {
|
||||
try {
|
||||
let local_results = await db_events.event
|
||||
.filter(ev => {
|
||||
.filter((ev) => {
|
||||
// Resilient account check
|
||||
const acct_match = ev.account_id === account_id || ev.account_id_random === account_id;
|
||||
const acct_match =
|
||||
ev.account_id === account_id ||
|
||||
ev.account_id_random === account_id;
|
||||
if (!acct_match) return false;
|
||||
|
||||
if (qry_type && ev.type !== qry_type) return false;
|
||||
if (qry_physical || qry_virtual) {
|
||||
let match = false;
|
||||
// Loose equality to handle 1, '1', true from DB
|
||||
if (qry_physical && ev.physical == true) match = true;
|
||||
if (qry_physical && ev.physical == true)
|
||||
match = true;
|
||||
if (qry_virtual && ev.virtual == true) match = true;
|
||||
if (!match) return false;
|
||||
}
|
||||
@@ -129,7 +134,11 @@
|
||||
const name = (ev.name ?? '').toLowerCase();
|
||||
const desc = (ev.description ?? '').toLowerCase();
|
||||
const loc = (ev.location_text ?? '').toLowerCase();
|
||||
return name.includes(qry_str) || desc.includes(qry_str) || loc.includes(qry_str);
|
||||
return (
|
||||
name.includes(qry_str) ||
|
||||
desc.includes(qry_str) ||
|
||||
loc.includes(qry_str)
|
||||
);
|
||||
}
|
||||
return true;
|
||||
})
|
||||
@@ -137,27 +146,39 @@
|
||||
|
||||
// Sort local results matching UI selection
|
||||
if ($idaa_loc.recovery_meetings.qry__order_by === 'name') {
|
||||
local_results.sort((a, b) => (a.name ?? '').localeCompare(b.name ?? ''));
|
||||
local_results.sort((a, b) =>
|
||||
(a.name ?? '').localeCompare(b.name ?? '')
|
||||
);
|
||||
} else {
|
||||
local_results.sort((a, b) => {
|
||||
const dateA = a.updated_on ? new Date(a.updated_on).getTime() : 0;
|
||||
const dateB = b.updated_on ? new Date(b.updated_on).getTime() : 0;
|
||||
const dateA = a.updated_on
|
||||
? new Date(a.updated_on).getTime()
|
||||
: 0;
|
||||
const dateB = b.updated_on
|
||||
? new Date(b.updated_on).getTime()
|
||||
: 0;
|
||||
return dateB - dateA;
|
||||
});
|
||||
}
|
||||
|
||||
local_ids = local_results.map(e => String(e.id || e.event_id_random)).filter(Boolean);
|
||||
local_ids = local_results
|
||||
.map((e) => String(e.id || e.event_id_random))
|
||||
.filter(Boolean);
|
||||
|
||||
// Update UI immediately. This eliminates the "white page" during searching.
|
||||
if (current_search_id === last_search_id) {
|
||||
if (log_lvl) console.log(`[Search #${current_search_id}] Fast Path complete. Found ${local_ids.length} items locally.`);
|
||||
if (log_lvl)
|
||||
console.log(
|
||||
`[Search #${current_search_id}] Fast Path complete. Found ${local_ids.length} items locally.`
|
||||
);
|
||||
event_id_random_li = local_ids;
|
||||
if (local_ids.length > 0) {
|
||||
$idaa_sess.recovery_meetings.qry__status = 'done';
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (log_lvl) console.warn('Fast Path failed, waiting for API...', e);
|
||||
if (log_lvl)
|
||||
console.warn('Fast Path failed, waiting for API...', e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,46 +217,71 @@
|
||||
const name = (ev.name ?? '').toLowerCase();
|
||||
const desc = (ev.description ?? '').toLowerCase();
|
||||
const loc = (ev.location_text ?? '').toLowerCase();
|
||||
if (!name.includes(qry_str) && !desc.includes(qry_str) && !loc.includes(qry_str)) return false;
|
||||
if (
|
||||
!name.includes(qry_str) &&
|
||||
!desc.includes(qry_str) &&
|
||||
!loc.includes(qry_str)
|
||||
)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
const api_ids = api_results.map((e: any) => String(e.id || e.event_id_random)).filter(Boolean);
|
||||
const api_ids = api_results
|
||||
.map((e: any) => String(e.id || e.event_id_random))
|
||||
.filter(Boolean);
|
||||
|
||||
// UI PROTECTION: Preserve results if API returns nothing (0 results)
|
||||
// BUT only if it was a successful empty response, not a failure.
|
||||
// ALSO: Only protect if qry_str was the primary change.
|
||||
// ALSO: Only protect if qry_str was the primary change.
|
||||
// If Type or Location changed, we want to see the 0.
|
||||
const filter_changed = qry_type !== $idaa_sess.recovery_meetings.status_qry__last_type ||
|
||||
qry_physical !== $idaa_sess.recovery_meetings.status_qry__last_phys ||
|
||||
qry_virtual !== $idaa_sess.recovery_meetings.status_qry__last_virt;
|
||||
const filter_changed =
|
||||
qry_type !==
|
||||
$idaa_sess.recovery_meetings.status_qry__last_type ||
|
||||
qry_physical !==
|
||||
$idaa_sess.recovery_meetings.status_qry__last_phys ||
|
||||
qry_virtual !==
|
||||
$idaa_sess.recovery_meetings.status_qry__last_virt;
|
||||
|
||||
if (api_ids.length === 0 && local_ids.length > 0 && !remote_first && !filter_changed) {
|
||||
if (log_lvl) console.warn(`[Search #${current_search_id}] API returned 0 matching results. Preserving local cache view.`);
|
||||
if (
|
||||
api_ids.length === 0 &&
|
||||
local_ids.length > 0 &&
|
||||
!remote_first &&
|
||||
!filter_changed
|
||||
) {
|
||||
if (log_lvl)
|
||||
console.warn(
|
||||
`[Search #${current_search_id}] API returned 0 matching results. Preserving local cache view.`
|
||||
);
|
||||
$idaa_sess.recovery_meetings.qry__status = 'done';
|
||||
return;
|
||||
}
|
||||
|
||||
$idaa_slct.event_obj_li = api_results;
|
||||
event_id_random_li = api_ids;
|
||||
|
||||
|
||||
// Snapshot last used filters for future protection checks
|
||||
$idaa_sess.recovery_meetings.status_qry__last_request_str = qry_str;
|
||||
$idaa_sess.recovery_meetings.status_qry__last_request_str =
|
||||
qry_str;
|
||||
$idaa_sess.recovery_meetings.status_qry__last_type = qry_type;
|
||||
$idaa_sess.recovery_meetings.status_qry__last_phys = qry_physical;
|
||||
$idaa_sess.recovery_meetings.status_qry__last_virt = qry_virtual;
|
||||
|
||||
$idaa_sess.recovery_meetings.status_qry__last_phys =
|
||||
qry_physical;
|
||||
$idaa_sess.recovery_meetings.status_qry__last_virt =
|
||||
qry_virtual;
|
||||
|
||||
$idaa_sess.recovery_meetings.qry__status = 'done';
|
||||
if (log_lvl) console.log(`[Search #${current_search_id}] Revalidation Complete. Found ${api_ids.length} items.`);
|
||||
if (log_lvl)
|
||||
console.log(
|
||||
`[Search #${current_search_id}] Revalidation Complete. Found ${api_ids.length} items.`
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
if (current_search_id === last_search_id) {
|
||||
console.error('Revalidation failed:', error);
|
||||
$idaa_sess.recovery_meetings.qry__status = 'error';
|
||||
|
||||
// If the API failed (e.g. 400/500), we should NOT preserve results from a
|
||||
// previous successful search as it's misleading.
|
||||
|
||||
// If the API failed (e.g. 400/500), we should NOT preserve results from a
|
||||
// previous successful search as it's misleading.
|
||||
// We clear the list so the 'No recovery meetings found' / Error message shows.
|
||||
event_id_random_li = [];
|
||||
}
|
||||
@@ -244,7 +290,10 @@
|
||||
|
||||
if (browser) {
|
||||
console.log('Browser environment ready.');
|
||||
window.parent.postMessage({ event_id: $idaa_slct?.event_id ?? null }, '*');
|
||||
window.parent.postMessage(
|
||||
{ event_id: $idaa_slct?.event_id ?? null },
|
||||
'*'
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -274,12 +323,16 @@
|
||||
{:else}
|
||||
<div class="space-y-2">
|
||||
{#if $idaa_sess.recovery_meetings.qry__status === 'loading'}
|
||||
<div class="ae_highlight ae_padding_md ae_row ae_flex_justify_center">
|
||||
<div
|
||||
class="ae_highlight ae_padding_md ae_row ae_flex_justify_center"
|
||||
>
|
||||
<span class="fas fa-spinner fa-spin m-1"></span>
|
||||
Searching...
|
||||
</div>
|
||||
{:else}
|
||||
<div class="ae_highlight ae_padding_md ae_row ae_flex_justify_center">
|
||||
<div
|
||||
class="ae_highlight ae_padding_md ae_row ae_flex_justify_center"
|
||||
>
|
||||
No recovery meetings found matching your criteria.
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user