Fix modal conflict

pull/668/head
ioedeveloper 4 years ago
parent d23cb5a1f2
commit 84b776599d
  1. 12
      apps/remix-ide/src/app/ui/modaldialog.js
  2. 55
      libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
  3. 7
      libs/remix-ui/modal-dialog/src/lib/remix-ui-modal-dialog.tsx

@ -6,10 +6,10 @@ module.exports = (title, content, ok, cancel, focusSelector, opts) => {
let agreed = true let agreed = true
let footerIsActive = false let footerIsActive = false
opts = opts || {} opts = opts || {}
var container = document.querySelector('.modal') var container = document.getElementById('modal-dialog')
if (!container) { if (!container) {
document.querySelector('body').appendChild(html(opts)) document.querySelector('body').appendChild(html(opts))
container = document.querySelector('.modal') container = document.getElementById('modal-dialog')
incomingModal = false incomingModal = false
} else incomingModal = true } else incomingModal = true
@ -24,8 +24,8 @@ module.exports = (title, content, ok, cancel, focusSelector, opts) => {
cancelDiv.innerHTML = (cancel && cancel.label !== undefined) ? cancel.label : 'Cancel' cancelDiv.innerHTML = (cancel && cancel.label !== undefined) ? cancel.label : 'Cancel'
cancelDiv.style.display = cancelDiv.innerHTML === '' ? 'none' : 'inline-block' cancelDiv.style.display = cancelDiv.innerHTML === '' ? 'none' : 'inline-block'
var modal = document.querySelector('.modal-body') var modal = document.getElementById('modal-body-id')
var modalTitle = document.querySelector('.modal-header h6') var modalTitle = document.getElementById('modal-title-h6')
modalTitle.innerHTML = '' modalTitle.innerHTML = ''
if (title) modalTitle.innerText = title if (title) modalTitle.innerText = title
@ -134,12 +134,12 @@ function html (opts) {
<div id="modal-background" class="modal-dialog" role="document"> <div id="modal-background" class="modal-dialog" role="document">
<div class="modal-content ${css.modalContent} ${opts.class}"> <div class="modal-content ${css.modalContent} ${opts.class}">
<div class="modal-header"> <div class="modal-header">
<h6 class="modal-title" data-id="modalDialogModalTitle"></h6> <h6 id="modal-title-h6" class="modal-title" data-id="modalDialogModalTitle"></h6>
<span class="modal-close"> <span class="modal-close">
<i id="modal-close" title="Close" class="fas fa-times" aria-hidden="true"></i> <i id="modal-close" title="Close" class="fas fa-times" aria-hidden="true"></i>
</span> </span>
</div> </div>
<div class="modal-body ${css.modalBody}" data-id="modalDialogModalBody"> - </div> <div id="modal-body-id" class="modal-body ${css.modalBody}" data-id="modalDialogModalBody"> - </div>
<div class="modal-footer" data-id="modalDialogModalFooter" autofocus> <div class="modal-footer" data-id="modalDialogModalFooter" autofocus>
<span id="modal-footer-ok" class="${css.modalFooterOk} modal-ok btn btn-sm btn-light" tabindex='5'>OK</span> <span id="modal-footer-ok" class="${css.modalFooterOk} modal-ok btn btn-sm btn-light" tabindex='5'>OK</span>
<span id="modal-footer-cancel" class="${css.modalFooterCancel} modal-cancel btn btn-sm btn-light" tabindex='10' data-dismiss="modal">Cancel</span> <span id="modal-footer-cancel" class="${css.modalFooterCancel} modal-cancel btn btn-sm btn-light" tabindex='10' data-dismiss="modal">Cancel</span>

@ -85,12 +85,14 @@ export const FileExplorer = (props: FileExplorerProps) => {
setState(prevState => { setState(prevState => {
return { ...prevState, fileManager, accessToken, files, actions } return { ...prevState, fileManager, accessToken, files, actions }
}) })
})()
}, [])
if (props.filesProvider) { useEffect(() => {
if (state.fileManager) {
props.filesProvider.event.register('fileAdded', fileAdded) props.filesProvider.event.register('fileAdded', fileAdded)
} }
})() }, [state.fileManager])
}, [])
const resolveDirectory = async (folderPath, dir: File[]): Promise<File[]> => { const resolveDirectory = async (folderPath, dir: File[]): Promise<File[]> => {
dir = await Promise.all(dir.map(async (file) => { dir = await Promise.all(dir.map(async (file) => {
@ -267,7 +269,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
} }
} }
const addFile = async (parentFolder: string, newFilePath: string, files?: File[]) => { const addFile = async (parentFolder: string, newFilePath: string) => {
if (parentFolder === name) { if (parentFolder === name) {
setState(prevState => { setState(prevState => {
return { return {
@ -281,7 +283,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
} }
}) })
} else { } else {
const updatedFiles = await resolveDirectory(parentFolder, files || state.files) const updatedFiles = await resolveDirectory(parentFolder, state.files)
setState(prevState => { setState(prevState => {
return { ...prevState, files: updatedFiles, focusElement: [{ key: newFilePath, type: 'file' }] } return { ...prevState, files: updatedFiles, focusElement: [{ key: newFilePath, type: 'file' }] }
@ -290,6 +292,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
if (newFilePath.includes('_test.sol')) { if (newFilePath.includes('_test.sol')) {
plugin.events.trigger('newTestFileCreated', [newFilePath]) plugin.events.trigger('newTestFileCreated', [newFilePath])
} }
state.fileManager.open(newFilePath)
} }
const addEmptyFile = (parentFolder: string, files: File[]): File[] => { const addEmptyFile = (parentFolder: string, files: File[]): File[] => {
@ -432,10 +435,46 @@ export const FileExplorer = (props: FileExplorerProps) => {
// }) // })
const fileAdded = async (filePath: string) => { const fileAdded = async (filePath: string) => {
const pathArr = filePath.split('/')
const hasChild = pathArr.length > 2
if (hasChild) {
const expandPath = pathArr.map((path, index) => {
return [...pathArr.slice(0, index)].join('/')
}).filter(path => path && (path !== name))
if (state.files.findIndex(item => item.path === expandPath[0]) === -1) {
const dir = buildTree(expandPath)
let files = [dir, ...state.files]
await Promise.all(expandPath.map(async path => {
files = await resolveDirectory(path, files)
}))
setState(prevState => {
return { ...prevState, files, expandPath: [...state.expandPath, ...expandPath] }
})
} else {
if (state.expandPath.findIndex(path => path === expandPath[expandPath.length - 1]) !== -1) return
const dir = state.files.find(item => item.path === expandPath[0])
let files = [{
...dir,
child: [...(await fetchDirectoryContent(dir.path))]
}, ...state.files.filter(item => item.path !== expandPath[0])]
await Promise.all(expandPath.map(async path => {
files = await resolveDirectory(path, files)
}))
const updatedPath = [state.expandPath.filter(key => key && (typeof key === 'string') && !key.startsWith(expandPath[0]))]
setState(prevState => {
return { ...prevState, files, expandPath: [...updatedPath, ...expandPath] }
})
}
} else {
const parentFolder = extractParentFromKey(filePath) const parentFolder = extractParentFromKey(filePath)
addFile(parentFolder, filePath) addFile(parentFolder, filePath)
await state.fileManager.open(filePath) }
} }
// props.filesProvider.event.register('folderAdded', async (folderpath: string) => { // props.filesProvider.event.register('folderAdded', async (folderpath: string) => {
@ -681,8 +720,8 @@ export const FileExplorer = (props: FileExplorerProps) => {
<div key={index}> <div key={index}>
<TreeViewItem <TreeViewItem
id={`treeViewItem${file.path}`} id={`treeViewItem${file.path}`}
iconX='pr-3 fa fa-folder text-info' iconX='pr-3 far fa-folder'
iconY='pr-3 fa fa-folder-open text-info' iconY='pr-3 far fa-folder-open'
key={`${file.path + index}`} key={`${file.path + index}`}
label={label(file)} label={label(file)}
onClick={(e) => { onClick={(e) => {

@ -42,7 +42,6 @@ export const ModalDialog = (props: ModalDialogProps) => {
return ( return (
<div <div
id="modal-dialog"
data-id="modalDialogContainer" data-id="modalDialogContainer"
data-backdrop="static" data-backdrop="static"
data-keyboard="false" data-keyboard="false"
@ -50,7 +49,7 @@ export const ModalDialog = (props: ModalDialogProps) => {
style={{ display: props.hide ? 'none' : 'block' }} style={{ display: props.hide ? 'none' : 'block' }}
role="dialog" role="dialog"
> >
<div id="modal-background" className="modal-dialog" role="document"> <div className="modal-dialog" role="document">
<div <div
onBlur={(e) => { onBlur={(e) => {
e.stopPropagation() e.stopPropagation()
@ -67,7 +66,7 @@ export const ModalDialog = (props: ModalDialogProps) => {
</h6> </h6>
{!props.showCancelIcon && {!props.showCancelIcon &&
<span className="modal-close" onClick={() => handleHide()}> <span className="modal-close" onClick={() => handleHide()}>
<i id="modal-close" title="Close" className="fas fa-times" aria-hidden="true"></i> <i title="Close" className="fas fa-times" aria-hidden="true"></i>
</span> </span>
} }
</div> </div>
@ -78,7 +77,6 @@ export const ModalDialog = (props: ModalDialogProps) => {
{/* todo add autofocus ^^ */} {/* todo add autofocus ^^ */}
{ props.ok && { props.ok &&
<span <span
id="modal-footer-ok"
className={'modal-ok btn btn-sm ' + (state.toggleBtn ? 'btn-dark' : 'btn-light')} className={'modal-ok btn btn-sm ' + (state.toggleBtn ? 'btn-dark' : 'btn-light')}
onClick={() => { onClick={() => {
if (props.ok.fn) props.ok.fn() if (props.ok.fn) props.ok.fn()
@ -90,7 +88,6 @@ export const ModalDialog = (props: ModalDialogProps) => {
} }
{ props.cancel && { props.cancel &&
<span <span
id="modal-footer-cancel"
className={'modal-cancel btn btn-sm ' + (state.toggleBtn ? 'btn-light' : 'btn-dark')} className={'modal-cancel btn btn-sm ' + (state.toggleBtn ? 'btn-light' : 'btn-dark')}
data-dismiss="modal" data-dismiss="modal"
onClick={() => { onClick={() => {

Loading…
Cancel
Save