Skip to content

Commit

Permalink
fix: prevent creating multiple devices
Browse files Browse the repository at this point in the history
  • Loading branch information
maciekstosio committed Jan 14, 2025
1 parent 3613b0d commit 00de04e
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function findNewestIosRuntime(runtimes: IOSRuntimeInfo[]) {

function DevicesNotFoundView() {
const { openModal, closeModal } = useModal();
const [isCreating, setIsCreating] = useState(false);
const { iOSRuntimes, androidImages, deviceManager } = useDevices();
const [isIOSCreating, withIosCreating] = useLoadingState();
const [isAndroidCreating, withAndroidCreating] = useLoadingState();
Expand All @@ -78,6 +79,7 @@ function DevicesNotFoundView() {
}

async function createAndroidDevice() {
setIsCreating(true);
if (errors?.emulator) {
utils.showDismissableError(errors?.emulator.message);
return;
Expand All @@ -97,9 +99,11 @@ function DevicesNotFoundView() {
const { modelId, modelName } = firstAndroidDevice;
await deviceManager.createAndroidDevice(modelId, modelName, newestImage);
});
setIsCreating(false);
}

async function createIOSDevice() {
setIsCreating(true);
if (errors?.simulator) {
utils.showDismissableError(errors.simulator.message);
return;
Expand All @@ -114,6 +118,7 @@ function DevicesNotFoundView() {
const iOSDeviceType = firstRuntimeSupportedDevice(newestRuntime.supportedDeviceTypes);
await deviceManager.createIOSDevice(iOSDeviceType!, iOSDeviceType!.name, newestRuntime);
});
setIsCreating(false);
}
return (
<div className="devices-not-found-container">
Expand All @@ -127,6 +132,7 @@ function DevicesNotFoundView() {
<div className="devices-not-found-button-group">
{Platform.OS === "macos" && (
<Button
disabled={isCreating}
type="ternary"
className="devices-not-found-quick-action"
onClick={createIOSDevice}>
Expand All @@ -136,6 +142,7 @@ function DevicesNotFoundView() {
)}

<Button
disabled={isCreating}
type="ternary"
className="devices-not-found-quick-action"
onClick={createAndroidDevice}>
Expand Down

0 comments on commit 00de04e

Please sign in to comment.