Listen to notifications and display modal

pull/5370/head
ioedeveloper 3 years ago
parent f7774d72bb
commit 61d3551b4e
  1. 38
      libs/remix-ui/workspace/src/lib/actions/workspace.ts
  2. 6
      libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx

@ -60,7 +60,7 @@ export const displayNotification = (title: string, message: string, labelOk: str
export const hideNotification = () => {
return {
type: 'DISPLAY_NOTIFICATION'
type: 'HIDE_NOTIFICATION'
}
}
@ -128,27 +128,25 @@ const createWorkspaceTemplate = async (workspaceName: string, setDefaults = true
const response: AxiosResponse = await axios.get(`https://api.github.com/gists/${gistId}`)
const data = response.data
console.log('data: ', data)
if (!data.files) {
dispatch(displayNotification('Gist load error', 'No files found', 'OK', null, () => {}, null))
return
return dispatch(displayNotification('Gist load error', 'No files found', 'OK', null, () => {}, null))
}
// const obj = {}
// Object.keys(data.files).forEach((element) => {
// const path = element.replace(/\.\.\./g, '/')
// obj['/' + 'gist-' + gistId + '/' + path] = data.files[element]
// })
// fileManager.setBatchFiles(obj, 'workspace', true, (errorLoadingFile) => {
// if (!errorLoadingFile) {
// const provider = fileManager.getProvider('workspace')
// provider.lastLoadedGistId = gistId
// } else {
// // modalDialogCustom.alert('', errorLoadingFile.message || errorLoadingFile)
// }
// })
const obj = {}
Object.keys(data.files).forEach((element) => {
const path = element.replace(/\.\.\./g, '/')
obj['/' + 'gist-' + gistId + '/' + path] = data.files[element]
})
plugin.fileManager.setBatchFiles(obj, 'workspace', true, (errorLoadingFile) => {
if (!errorLoadingFile) {
const provider = plugin.fileManager.getProvider('workspace')
provider.lastLoadedGistId = gistId
} else {
displayNotification('', errorLoadingFile.message || errorLoadingFile, 'OK', null, () => {}, null)
}
})
} catch (e) {
dispatch(displayNotification('Gist load error', e.message, 'OK', null, () => {}, null))
console.error(e)

@ -56,6 +56,12 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
}
}, [modals])
useEffect(() => {
if (fs.notification.title) {
modal(fs.notification.title, fs.notification.message, fs.notification.labelOk, fs.notification.actionOk, fs.notification.labelCancel, fs.notification.actionCancel)
}
}, [fs.notification])
const handleHideModal = () => {
setFocusModal(modal => {
return { ...modal, hide: true, message: null }

Loading…
Cancel
Save