diff --git a/packages/insomnia-app/app/ui/components/modals/ask-modal.tsx b/packages/insomnia-app/app/ui/components/modals/ask-modal.tsx index 60ec29b5f7..4970a86a74 100644 --- a/packages/insomnia-app/app/ui/components/modals/ask-modal.tsx +++ b/packages/insomnia-app/app/ui/components/modals/ask-modal.tsx @@ -14,6 +14,14 @@ interface State { loading: boolean; } +interface AskModalOptions { + title?: string; + message?: string; + onDone?: (success: boolean) => Promise; + yesText?: string; + noText?: string; +} + @autoBindMethodsForReact(AUTOBIND_CFG) class AskModal extends PureComponent<{}, State> { state: State = { @@ -26,8 +34,9 @@ class AskModal extends PureComponent<{}, State> { modal: Modal | null = null; yesButton: HTMLButtonElement | null = null; - _doneCallback: Function = () => {}; - _promiseCallback: Function = () => {}; + + _doneCallback: AskModalOptions['onDone']; + _promiseCallback: (value: boolean | PromiseLike) => void = () => {}; _setModalRef(m: Modal) { this.modal = m; @@ -42,19 +51,17 @@ class AskModal extends PureComponent<{}, State> { loading: true, }); - if (this._doneCallback) { - // Wait for the callback to finish before closing - await this._doneCallback(true); - } + // Wait for the callback to finish before closing + await this._doneCallback?.(true); this._promiseCallback(true); this.hide(); } - _handleNo() { + async _handleNo() { this.hide(); - this?._doneCallback(false); + await this._doneCallback?.(false); this._promiseCallback(false); } @@ -63,8 +70,7 @@ class AskModal extends PureComponent<{}, State> { this.modal?.hide(); } - show(options: any = {}) { - const { title, message, onDone, yesText, noText } = options; + show({ title, message, onDone, yesText, noText }: AskModalOptions = {}) { this._doneCallback = onDone; this.setState({ title: title || 'Confirm', @@ -74,10 +80,12 @@ class AskModal extends PureComponent<{}, State> { loading: false, }); this.modal?.show(); + setTimeout(() => { this.yesButton && this.yesButton.focus(); }, 100); - return new Promise(resolve => { + + return new Promise(resolve => { this._promiseCallback = resolve; }); } diff --git a/packages/insomnia-app/app/ui/redux/modules/global.tsx b/packages/insomnia-app/app/ui/redux/modules/global.tsx index 0235804e84..61765dd17c 100644 --- a/packages/insomnia-app/app/ui/redux/modules/global.tsx +++ b/packages/insomnia-app/app/ui/redux/modules/global.tsx @@ -538,24 +538,28 @@ const showSelectExportTypeModal = ({ onCancel, onDone }: { onCancel: () => void; onDone: (selectedFormat: SelectedFormat) => Promise; }) => { + const options = [ + { + name: 'Insomnia v4 (JSON)', + value: VALUE_JSON, + }, + { + name: 'Insomnia v4 (YAML)', + value: VALUE_YAML, + }, + { + name: 'HAR – HTTP Archive Format', + value: VALUE_HAR, + }, + ]; + const lastFormat = window.localStorage.getItem('insomnia.lastExportFormat'); + const defaultValue = options.find(({ value }) => value === lastFormat) ? lastFormat : VALUE_JSON; + showModal(SelectModal, { title: 'Select Export Type', - value: lastFormat, - options: [ - { - name: 'Insomnia v4 (JSON)', - value: VALUE_JSON, - }, - { - name: 'Insomnia v4 (YAML)', - value: VALUE_YAML, - }, - { - name: 'HAR – HTTP Archive Format', - value: VALUE_HAR, - }, - ], + value: defaultValue, + options, message: 'Which format would you like to export as?', onCancel, onDone: async (selectedFormat: SelectedFormat) => { diff --git a/packages/insomnia-app/config/config.json b/packages/insomnia-app/config/config.json index f2074e4a84..5084e9625d 100644 --- a/packages/insomnia-app/config/config.json +++ b/packages/insomnia-app/config/config.json @@ -1,5 +1,5 @@ { - "version": "2021.4.0", + "version": "2021.4.1", "name": "insomnia", "executableName": "insomnia", "appId": "com.insomnia.app",