From 725e8d6d549fb750db4dbf4caca74bc5a522aec2 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 5 Jan 2022 13:24:47 +0100 Subject: [PATCH] fix modal --- apps/remix-ide/src/lib/cmdInterpreterAPI.js | 2 +- .../remix-core-plugin/src/lib/gist-handler.ts | 39 ++++++++++++------- .../src/lib/remix-ui-modal-dialog.tsx | 6 +-- .../terminal/src/lib/remix-ui-terminal.tsx | 2 +- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/apps/remix-ide/src/lib/cmdInterpreterAPI.js b/apps/remix-ide/src/lib/cmdInterpreterAPI.js index 97d27f3a17..82ae4636fe 100644 --- a/apps/remix-ide/src/lib/cmdInterpreterAPI.js +++ b/apps/remix-ide/src/lib/cmdInterpreterAPI.js @@ -33,7 +33,7 @@ class CmdInterpreterAPI { log () { arguments[0] != null ? this._components.terminal.commands.html(arguments[0]) : this._components.terminal.commands.html(arguments[1]) } loadgist (id, cb) { - this._components.terminal.call('loadFromGistHandler', 'load', id) + this._components.terminal.call('gistHandler', 'load', id) if (cb) cb() } diff --git a/libs/remix-core-plugin/src/lib/gist-handler.ts b/libs/remix-core-plugin/src/lib/gist-handler.ts index 6a5a511098..9a800d2516 100644 --- a/libs/remix-core-plugin/src/lib/gist-handler.ts +++ b/libs/remix-core-plugin/src/lib/gist-handler.ts @@ -1,6 +1,5 @@ 'use strict' import { Plugin } from '@remixproject/engine' -import { AppModal, ModalTypes } from '@remix-ui/app' interface StringByString { [key: string]: string; @@ -25,26 +24,40 @@ export class GistHandler extends Plugin { var loadingFromGist = false if (!gistId) { loadingFromGist = true - let value: string = await this.call('modal', 'prompt-value', 'Load a Gist', 'Enter the ID of the Gist or URL you would like to load.', null) + const value = await (() => { + return new Promise((resolve, reject) => { + const modalContent = { + id: 'gisthandler', + title: 'Load a Gist', + message: 'Enter the ID of the Gist or URL you would like to load.', + modalType: 'prompt', + okFn: (value) => { + resolve(value) + } + } + this.call('modal', 'modal', modalContent) + }) + })() + if (value !== '') { gistId = getGistId(value) if (gistId) { cb(gistId) } else { - const modalContent: AppModal = { + const modalContent = { id: 'gisthandler', title: 'Gist load error', message: 'Error while loading gist. Please provide a valid Gist ID or URL.', - modalType: ModalTypes.alert + modalType: 'alert' } await this.call('modal', 'modal', modalContent) } } else { - const modalContent: AppModal = { + const modalContent = { id: 'gisthandler', title: 'Gist load error', message: 'Error while loading gist. Id cannot be empty.', - modalType: ModalTypes.alert + modalType: 'alert' } await this.call('modal', 'modal', modalContent) } @@ -63,23 +76,23 @@ export class GistHandler extends Plugin { return self.handleLoad(gistId, async (gistId: String | null) => { let data: any try { - data = (await fetch(`https://api.github.com/gists/${gistId}`)).json() as any + data = await (await fetch(`https://api.github.com/gists/${gistId}`)).json() as any if (!data.files) { - const modalContent: AppModal = { + const modalContent = { id: 'gisthandler', title: 'Gist load error', message: data.message, - modalType: ModalTypes.alert + modalType: 'alert' } await this.call('modal', 'modal', modalContent) return } } catch (e: any) { - const modalContent: AppModal = { + const modalContent = { id: 'gisthandler', title: 'Gist load error', message: e.message, - modalType: ModalTypes.alert + modalType: 'alert' } await this.call('modal', 'modal', modalContent) return @@ -94,11 +107,11 @@ export class GistHandler extends Plugin { if (!errorSavingFiles) { const provider = await this.call('fileManager', 'getProviderByName', 'workspace') } else { - const modalContent: AppModal = { + const modalContent = { id: 'gisthandler', title: 'Gist load error', message: errorSavingFiles.message || errorSavingFiles, - modalType: ModalTypes.alert + modalType: 'alert' } this.call('modal', 'modal', modalContent) } diff --git a/libs/remix-ui/modal-dialog/src/lib/remix-ui-modal-dialog.tsx b/libs/remix-ui/modal-dialog/src/lib/remix-ui-modal-dialog.tsx index 524caaad62..f9fca87398 100644 --- a/libs/remix-ui/modal-dialog/src/lib/remix-ui-modal-dialog.tsx +++ b/libs/remix-ui/modal-dialog/src/lib/remix-ui-modal-dialog.tsx @@ -96,8 +96,7 @@ export const ModalDialog = (props: ModalDialogProps) => {
{/* todo add autofocus ^^ */} - { props.okLabel && - { @@ -108,8 +107,7 @@ export const ModalDialog = (props: ModalDialogProps) => { { props.okLabel ? props.okLabel : 'OK' } } - { props.cancelLabel && - { } function loadgist (id, cb) { - gistHandler.loadFromGist({ gist: id }, _deps.fileManager) + props.plugin.call('gistHandler', 'load', id) if (cb) cb() }