Modify remove input field command

pull/1575/head
ioedeveloper 3 years ago
parent 55d68f647d
commit 5cf892121d
  1. 16
      libs/remix-ui/workspace/src/lib/actions/index.ts
  2. 4
      libs/remix-ui/workspace/src/lib/actions/payload.ts
  3. 29
      libs/remix-ui/workspace/src/lib/reducers/workspace.ts

@ -73,21 +73,7 @@ export const fetchDirectory = async (path: string) => {
}
export const removeInputField = async (path: string) => {
const provider = plugin.fileManager.currentFileProvider()
const promise = new Promise((resolve) => {
provider.resolveDirectory(path, (error, fileTree) => {
if (error) console.error(error)
resolve(fileTree)
})
})
promise.then((files) => {
dispatch(removeInputFieldSuccess(path, files))
}).catch((error) => {
console.error(error)
})
return promise
dispatch(removeInputFieldSuccess(path))
}
export const deleteWorkspace = async (workspaceName: string) => {

@ -97,10 +97,10 @@ export const addInputFieldSuccess = (path: string, fileTree, type: 'file' | 'fol
}
}
export const removeInputFieldSuccess = (path: string, fileTree) => {
export const removeInputFieldSuccess = (path: string) => {
return {
type: 'REMOVE_INPUT_FIELD',
payload: { path, fileTree }
payload: { path }
}
}

@ -357,11 +357,11 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
...state,
browser: {
...state.browser,
files: state.mode === 'browser' ? fetchDirectoryContent(state, payload, payload.path + '/' + 'blank') : state.browser.files
files: state.mode === 'browser' ? removeInputField(state, payload.path) : state.browser.files
},
localhost: {
...state.localhost,
files: state.mode === 'localhost' ? fetchDirectoryContent(state, payload, payload.path + '/' + 'blank') : state.localhost.files
files: state.mode === 'localhost' ? removeInputField(state, payload.path) : state.localhost.files
},
focusEdit: null
}
@ -597,6 +597,31 @@ const fileRemoved = (state: BrowserState, path: string): { [x: string]: Record<s
return files
}
const removeInputField = (state: BrowserState, path: string): { [x: string]: Record<string, FileType> } => {
let files = state.mode === 'browser' ? state.browser.files : state.localhost.files
const root = state.mode === 'browser' ? state.browser.currentWorkspace : state.mode
if (path === root) {
delete files[root][path + '/' + 'blank']
return files
}
const _path = splitPath(state, path)
const prevFiles = _.get(files, _path)
if (prevFiles) {
prevFiles.child && prevFiles.child[path + '/' + 'blank'] && delete prevFiles.child[path + '/' + 'blank']
files = _.set(files, _path, {
isDirectory: true,
path,
name: extractNameFromKey(path).indexOf('gist-') === 0 ? extractNameFromKey(path).split('-')[1] : extractNameFromKey(path),
type: extractNameFromKey(path).indexOf('gist-') === 0 ? 'gist' : 'folder',
child: prevFiles ? prevFiles.child : {}
})
}
return files
}
// IDEA: Modify function to remove blank input field without fetching content
const fetchDirectoryContent = (state: BrowserState, payload: { fileTree, path: string, type?: 'file' | 'folder' }, deletePath?: string): { [x: string]: Record<string, FileType> } => {
if (!payload.fileTree) return state.mode === 'browser' ? state.browser.files : state[state.mode].files

Loading…
Cancel
Save