diff --git a/src/project/project-actions.tsx b/src/project/project-actions.tsx index e59aefc43..32d93ae91 100644 --- a/src/project/project-actions.tsx +++ b/src/project/project-actions.tsx @@ -843,16 +843,11 @@ export class ProjectActions { await this.handleFirmwareUpdate(e.code, userAction, finalFocusRef); return; case "clear-connect": + return this.handleClearConnectError(finalFocusRef); case "timeout-error": - case "reconnect-microbit": { - return this.dialogs.show((callback) => ( - - )); - } + return this.handleTimeoutError(finalFocusRef); + case "reconnect-microbit": + return this.handleReconnectMicrobitError(finalFocusRef); default: { return this.actionFeedback.unexpectedError(e); } @@ -877,65 +872,81 @@ export class ProjectActions { this.save(finalFocusRef, true); } - private webusbErrorMessage(code: WebUSBErrorCode) { - switch (code) { - case "clear-connect": - return { - title: this.intl.formatMessage({ - id: "webusb-error-clear-connect-title", - }), - description: ( - -

- {this.intl.formatMessage({ - id: "webusb-error-clear-connect-description-1", - })} -

-

- {this.intl.formatMessage({ - id: "webusb-error-clear-connect-description-2", - })} -

-
- ), - }; - case "reconnect-microbit": - return { - title: this.intl.formatMessage({ id: "webusb-error-default-title" }), - description: ( - <> - - {chunks}, - li: (chunks: ReactNode) => ( - - {chunks} - - ), - ul: (chunks: ReactNode) => ( - {chunks} - ), - }} - /> - - - - ), - }; - case "timeout-error": - return { - title: this.intl.formatMessage({ id: "timeout-error-title" }), - description: this.intl.formatMessage({ - id: "timeout-error-description", - }), - }; - default: - throw new Error("Unknown code"); - } + private async handleClearConnectError( + finalFocusRef: React.RefObject + ) { + return this.dialogs.show((callback) => ( + +

+ {this.intl.formatMessage({ + id: "webusb-error-clear-connect-description-1", + })} +

+

+ {this.intl.formatMessage({ + id: "webusb-error-clear-connect-description-2", + })} +

+ + } + /> + )); + } + private async handleReconnectMicrobitError( + finalFocusRef: React.RefObject + ) { + return this.dialogs.show((callback) => ( + + + {chunks}, + li: (chunks: ReactNode) => ( + + {chunks} + + ), + ul: (chunks: ReactNode) => ( + {chunks} + ), + }} + /> + + + + } + /> + )); + } + + private async handleTimeoutError( + finalFocusRef: React.RefObject + ) { + return this.dialogs.show((callback) => ( + + )); } private async handlePostSaveDialog(