mirror of
https://github.com/p-stream/p-stream.git
synced 2026-05-09 15:11:07 +00:00
fix backend selector loading forever
This commit is contained in:
parent
ef1a0893a6
commit
fd79b97bb5
1 changed files with 17 additions and 5 deletions
|
|
@ -140,16 +140,28 @@ export function BackendSelector({
|
||||||
}));
|
}));
|
||||||
setBackendOptions(options);
|
setBackendOptions(options);
|
||||||
|
|
||||||
const promises = options.map(async (option) => {
|
// Fetch each backend's meta independently and update state as each completes
|
||||||
|
// This prevents one slow/down backend from blocking the others
|
||||||
|
options.forEach(async (option) => {
|
||||||
try {
|
try {
|
||||||
const meta = await getBackendMeta(option.url);
|
const meta = await getBackendMeta(option.url);
|
||||||
return { ...option, meta, loading: false, error: false };
|
setBackendOptions((prev) =>
|
||||||
|
prev.map((opt) =>
|
||||||
|
opt.url === option.url
|
||||||
|
? { ...opt, meta, loading: false, error: false }
|
||||||
|
: opt,
|
||||||
|
),
|
||||||
|
);
|
||||||
} catch {
|
} catch {
|
||||||
return { ...option, meta: null, loading: false, error: true };
|
setBackendOptions((prev) =>
|
||||||
|
prev.map((opt) =>
|
||||||
|
opt.url === option.url
|
||||||
|
? { ...opt, meta: null, loading: false, error: true }
|
||||||
|
: opt,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const results = await Promise.all(promises);
|
|
||||||
setBackendOptions(results);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (availableUrls.length > 0) {
|
if (availableUrls.length > 0) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue