From 78855d534f1bab2fccbdf33e79bd0e2c77f4cb01 Mon Sep 17 00:00:00 2001 From: bitful-pannul Date: Fri, 20 Sep 2024 00:15:24 +0300 Subject: [PATCH] app_store UI: if publisher mirror offline, default to next online mirror --- .../ui/src/components/MirrorSelector.tsx | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/kinode/packages/app_store/ui/src/components/MirrorSelector.tsx b/kinode/packages/app_store/ui/src/components/MirrorSelector.tsx index 6dad47da..0795ecc8 100644 --- a/kinode/packages/app_store/ui/src/components/MirrorSelector.tsx +++ b/kinode/packages/app_store/ui/src/components/MirrorSelector.tsx @@ -21,16 +21,24 @@ const MirrorSelector: React.FC = ({ packageId, onMirrorSele if (!appData) return; const mirrors = [appData.package_id.publisher_node, ...(appData.metadata?.properties?.mirrors || [])]; setAvailableMirrors(mirrors); - setSelectedMirror(appData.package_id.publisher_node); - mirrors.forEach(mirror => { + // Start with the publisher node + setSelectedMirror(appData.package_id.publisher_node); + setMirrorStatuses(prev => ({ ...prev, [appData.package_id.publisher_node]: null })); + + for (const mirror of mirrors) { if (mirror.startsWith('http')) { setMirrorStatuses(prev => ({ ...prev, [mirror]: 'http' })); + setSelectedMirror(mirror); + break; } else { - setMirrorStatuses(prev => ({ ...prev, [mirror]: null })); - checkMirrorStatus(mirror); + const status = await checkMirrorStatus(mirror); + if (status) { + setSelectedMirror(mirror); + break; + } } - }); + } }, [packageId, fetchListing, checkMirror]); useEffect(() => { @@ -41,8 +49,10 @@ const MirrorSelector: React.FC = ({ packageId, onMirrorSele try { const status = await checkMirror(mirror); setMirrorStatuses(prev => ({ ...prev, [mirror]: status?.is_online ?? false })); + return status?.is_online ?? false; } catch { setMirrorStatuses(prev => ({ ...prev, [mirror]: false })); + return false; } }, [checkMirror]); @@ -62,7 +72,6 @@ const MirrorSelector: React.FC = ({ packageId, onMirrorSele setIsCustomMirrorSelected(false); setCustomMirror(""); if (!value.startsWith('http')) { - // Recheck the status when a non-HTTP mirror is selected setMirrorStatuses(prev => ({ ...prev, [value]: null })); await checkMirrorStatus(value); } @@ -92,7 +101,6 @@ const MirrorSelector: React.FC = ({ packageId, onMirrorSele return (