flattentree
bunsenstraat 11 months ago
parent e25db2149f
commit 0fbb26093e
  1. 10
      libs/remix-ui/workspace/src/lib/reducers/workspace.ts
  2. 9
      libs/remix-ui/workspace/src/lib/utils/index.ts

@ -184,7 +184,7 @@ export const browserReducer = (state = browserInitialState, action: Actions) =>
case 'FETCH_DIRECTORY_SUCCESS': {
const payload = action.payload
console.log('make a flat tree', payload)
console.log('FETCH_DIRECTORY_SUCCESS', payload)
const startTime = new Date().getTime()
const fd = fetchDirectoryContent(state, payload)
const endTime = new Date().getTime()
@ -255,16 +255,11 @@ export const browserReducer = (state = browserInitialState, action: Actions) =>
case 'FETCH_WORKSPACE_DIRECTORY_SUCCESS': {
const payload = action.payload
if(state.mode === 'browser'){
console.log('make a flat tree', payload)
console.log('FETCH_WORKSPACE_DIRECTORY_SUCCESS', payload)
}
const startTime = new Date().getTime()
const fd = fetchWorkspaceDirectoryContent(state, payload)
const endTime = new Date().getTime()
console.log(fd[payload.path])
const sortedKeys = fileKeySort(fd[payload.path])
console.log('sortedKeys', sortedKeys)
console.log('fetchDirectoryContent tree', endTime - startTime, fd)
return {
@ -957,6 +952,7 @@ const fetchDirectoryContent = (
return state.mode === 'browser'
? state.browser.files
: state[state.mode].files
fileKeySort(payload.fileTree)
if (state.mode === 'browser') {
if (payload.path === ROOT_PATH) {
let files = normalize(payload.fileTree, ROOT_PATH, payload.type)

@ -125,18 +125,19 @@ export const contextMenuActions: MenuItems = [{
}]
export const fileKeySort = (children: any): string[] => {
const directories = Object.keys(children).filter((key: string) => children[key].isDirectory && children[key].name !== '')
const directories = Object.keys(children).filter((key: string) => children[key].isDirectory)
// sort case insensitive
directories.sort((a: string, b: string) => a.toLowerCase().localeCompare(b.toLowerCase()))
const fileKeys = Object.keys(children).filter((key: string) => !children[key].isDirectory && children[key].name !== '')
const fileKeys = Object.keys(children).filter((key: string) => !children[key].isDirectory)
// sort case insensitive
fileKeys.sort((a: string, b: string) => a.toLowerCase().localeCompare(b.toLowerCase()))
// find the children with a blank name
const blankChildren = Object.keys(children).filter((key: string) => children[key].name === '')
//const blankChildren = Object.keys(children).filter((key: string) => children[key].name === '')
const keys = [...directories, ...fileKeys, ...blankChildren]
const keys = [...directories, ...fileKeys]
console.log('sorted keys', keys)
return keys
}

Loading…
Cancel
Save