(null);
let spaceOptionSection;
if (existingSubspaces.length > 0) {
const options = [space, ...existingSubspaces].map((space) => {
const classes = classNames("mx_AddExistingToSpaceDialog_dropdownOption", {
mx_AddExistingToSpaceDialog_dropdownOptionActive: space === selectedSpace,
});
return
{ space.name || getDisplayAliasForRoom(space) || space.roomId }
;
});
spaceOptionSection = (
{
setSelectedSpace(existingSubspaces.find(space => space.roomId === key) || space);
}}
value={selectedSpace.roomId}
label={_t("Space selection")}
>
{ options }
);
} else {
spaceOptionSection =
{ space.name || getDisplayAliasForRoom(space) || space.roomId }
;
}
const title =
{ _t("Add existing rooms") }
{ spaceOptionSection }
;
const addRooms = async () => {
setError(null);
setProgress(0);
let error;
for (const room of selectedToAdd) {
const via = calculateRoomVia(room);
try {
await SpaceStore.instance.addRoomToSpace(space, room.roomId, via).catch(async e => {
if (e.errcode === "M_LIMIT_EXCEEDED") {
await sleep(e.data.retry_after_ms);
return SpaceStore.instance.addRoomToSpace(space, room.roomId, via); // retry
}
throw e;
});
setProgress(i => i + 1);
} catch (e) {
console.error("Failed to add rooms to space", e);
setError(error = e);
break;
}
}
if (!error) {
onFinished(true);
}
};
const busy = progress !== null;
let footer;
if (error) {
footer = <>
{ _t("Not all selected were added") }
{ _t("Try again") }
{ _t("Retry") }
>;
} else if (busy) {
footer =
{ _t("Adding rooms... (%(progress)s out of %(count)s)", {
count: selectedToAdd.size,
progress,
}) }
;
} else {
footer = <>
{ _t("Want to add a new room instead?") }
onCreateRoomClick(cli, space)} kind="link">
{ _t("Create a new room") }
{ _t("Add") }
>;
}
return
{
if (checked) {
selectedToAdd.add(room);
} else {
selectedToAdd.delete(room);
}
setSelectedToAdd(new Set(selectedToAdd));
} : null}
/>
{ footer }
onFinished(false)} />
;
};
export default AddExistingToSpaceDialog;