Skip to content

Commit

Permalink
sort root level files and folders by name
Browse files Browse the repository at this point in the history
  • Loading branch information
joeizang committed Sep 1, 2023
1 parent d0b0263 commit e085b47
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion libs/remix-ui/workspace/src/lib/reducers/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -933,12 +933,29 @@ const removeInputField = (
return files
}

const sortDirectoriesFetched = (folderStructure: any) => {
if(!folderStructure) return

}

const sortFilesFetched = (folderStructure: any) => {
// eslint-disable-next-line prefer-const
let newResult = _.fromPairs(_.sortBy(_.toPairs(folderStructure[ROOT_PATH]), (x: any) => x[1].name))
let target = {}
Object.assign(target, newResult)
const result = { '/': target }
target = null
newResult = null
return result
}

// 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
Expand Down Expand Up @@ -986,13 +1003,15 @@ const fetchDirectoryContent = (
)
}
}
files = sortFilesFetched(files)
return files
}
} else {
if (payload.path === ROOT_PATH) {
let files = normalize(payload.fileTree, ROOT_PATH, payload.type)
files = _.merge(files, state.localhost.files[ROOT_PATH])
if (deletePath) delete files[deletePath]

return {[ROOT_PATH]: files}
} else {
let files = state.localhost.files
Expand All @@ -1012,6 +1031,8 @@ const fetchDirectoryContent = (
}
}
files = _.setWith(files, _path, prevFiles, Object)
const newFiles = sortFilesFetched(files)
console.log({ newFiles })
} else {
files = {
[payload.path]: normalize(
Expand All @@ -1021,7 +1042,8 @@ const fetchDirectoryContent = (
)
}
}
return files
const newFiles = sortFilesFetched(files)
return newFiles
}
}
}
Expand Down

0 comments on commit e085b47

Please sign in to comment.