Fix micronutrient dropdown toggle and resilient All-tab search (allSettled)

This commit is contained in:
James Clifford Spratt 2026-06-28 12:46:32 +01:00
parent c93c488451
commit 4f414251d6
3 changed files with 9 additions and 4 deletions

View file

@ -332,8 +332,13 @@ export async function searchAllSources(
);
}
// Execute searches in parallel
const results = await Promise.all(searchPromises);
// Execute searches in parallel. Use allSettled so that one failing source
// (e.g. a network error or outage from a single API) doesn't wipe out the
// results from the others.
const settled = await Promise.allSettled(searchPromises);
const results = settled
.filter((r): r is PromiseFulfilledResult<UnifiedFoodResult[]> => r.status === 'fulfilled')
.map((r) => r.value);
// Merge and deduplicate with enhanced prioritization
const merged = mergeAndDedupeResults(...results);

View file

@ -939,7 +939,7 @@ export class LiveFoodSearchModal extends Modal {
}
escapeRegExp(string: string): string {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\');
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
/**

View file

@ -331,7 +331,7 @@ export class ManualFoodEntryModal extends Modal {
let expanded = false;
const toggle = () => {
expanded = !expanded;
body.style.display = expanded ? 'block' : 'none';
body.toggleClass('macros-u-hidden', !expanded);
toggleIcon.textContent = expanded ? '▼' : '▶';
};
this.component.registerDomEvent(header, 'click', toggle);