Commit 5cf89212 authored by ioedeveloper's avatar ioedeveloper

Modify remove input field command

parent 55d68f64
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment