From 5afd2d09f88c750e96692f6e50ad32699e382607 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Mon, 11 Sep 2023 22:59:16 +0100 Subject: [PATCH] add types for sort function --- libs/remix-ui/workspace/src/lib/actions/index.ts | 4 +++- .../workspace/src/lib/components/file-explorer.tsx | 3 +++ libs/remix-ui/workspace/src/lib/contexts/index.ts | 5 +++-- .../workspace/src/lib/providers/FileSystemProvider.tsx | 6 ++++++ libs/remix-ui/workspace/src/lib/reducers/workspace.ts | 7 ++----- libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx | 2 ++ libs/remix-ui/workspace/src/lib/types/index.ts | 3 ++- 7 files changed, 21 insertions(+), 9 deletions(-) diff --git a/libs/remix-ui/workspace/src/lib/actions/index.ts b/libs/remix-ui/workspace/src/lib/actions/index.ts index e34b9db4177..f7c5098426b 100644 --- a/libs/remix-ui/workspace/src/lib/actions/index.ts +++ b/libs/remix-ui/workspace/src/lib/actions/index.ts @@ -126,7 +126,7 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React. }else{ _paq.push(['trackEvent', 'Storage', 'error', `Workspace in localstorage not found: ${localStorage.getItem("currentWorkspace")}`]) await basicWorkspaceInit(workspaces, workspaceProvider) - } + } } else { await basicWorkspaceInit(workspaces, workspaceProvider) } @@ -142,9 +142,11 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React. } export const fetchDirectory = async (path: string) => { + console.trace() const provider = plugin.fileManager.currentFileProvider() const promise = new Promise((resolve) => { provider.resolveDirectory(path, (error, fileTree) => { + console.log({ fileTree }) if (error) console.error(error) resolve(fileTree) diff --git a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx index 1cd08e52715..d65d88fa75e 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx @@ -34,6 +34,7 @@ export const FileExplorer = (props: FileExplorerProps) => { const [state, setState] = useState(workspaceState) const [sortIcon, setSortIcon] = useState(sortIconDesc) const treeRef = useRef(null) + console.log({ props }) useEffect(() => { if (contextMenuItems) { @@ -155,6 +156,7 @@ export const FileExplorer = (props: FileExplorerProps) => { } const handleClickFolder = async (path: string, type: 'folder' | 'file' | 'gist') => { + console.log({ state, props }) if (state.ctrlKey) { if (props.focusElement.findIndex((item) => item.key === path) !== -1) { const focusElement = props.focusElement.filter((item) => item.key !== path) @@ -307,6 +309,7 @@ export const FileExplorer = (props: FileExplorerProps) => { { console.log('sorting clicked') sortIcon === sortIconDesc ? setSortIcon(sortIconAsc) : setSortIcon(sortIconDesc) + props.dispatchDirectoriesSort(files[ROOT_PATH]) }}> diff --git a/libs/remix-ui/workspace/src/lib/contexts/index.ts b/libs/remix-ui/workspace/src/lib/contexts/index.ts index d0b578d85e8..5eb61aa8a1f 100644 --- a/libs/remix-ui/workspace/src/lib/contexts/index.ts +++ b/libs/remix-ui/workspace/src/lib/contexts/index.ts @@ -1,6 +1,7 @@ import { customAction } from '@remixproject/plugin-api' import { createContext, SyntheticEvent } from 'react' import { BrowserState } from '../reducers/workspace' +import { FileType } from '../types' export const FileSystemContext = createContext<{ fs: BrowserState, @@ -13,6 +14,7 @@ export const FileSystemContext = createContext<{ dispatchCreateWorkspace: (workspaceName: string, workspaceTemplateName: string, opts?, initGitRepo?: boolean) => Promise, toast: (toasterMsg: string) => void, dispatchFetchWorkspaceDirectory: (path: string) => Promise, + dispatchDirectoriesSort: (files: { [x: string]: Record } | any, direction?: 'asc' | 'desc') => Promise, dispatchSwitchToWorkspace: (name: string) => Promise, dispatchRenameWorkspace: (oldName: string, workspaceName: string) => Promise, dispatchDeleteWorkspace: (workspaceName: string) => Promise, @@ -47,5 +49,4 @@ export const FileSystemContext = createContext<{ dispatchCreateSlitherGithubAction: () => Promise dispatchCreateHelperScripts: (script: string) => Promise }>(null) - - \ No newline at end of file + diff --git a/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx b/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx index 13adb71235f..1a534a0e81f 100644 --- a/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx +++ b/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx @@ -76,6 +76,11 @@ export const FileSystemProvider = (props: WorkspaceProps) => { await fetchDirectory(path) } + const dispatchDirectoriesSort = async (files: any, path?: string, direction?: 'asc' | 'desc') => { + const result = await fetchDirectory(files.path ?? path) + console.log(result) + } + const dispatchAddInputField = async (path: string, type: 'file' | 'folder') => { await addInputField(type, path) } @@ -305,6 +310,7 @@ export const FileSystemProvider = (props: WorkspaceProps) => { toast, dispatchInitWorkspace, dispatchFetchDirectory, + dispatchDirectoriesSort, dispatchAddInputField, dispatchRemoveInputField, dispatchCreateWorkspace, diff --git a/libs/remix-ui/workspace/src/lib/reducers/workspace.ts b/libs/remix-ui/workspace/src/lib/reducers/workspace.ts index 50c1fd508f1..9cec5c880c8 100644 --- a/libs/remix-ui/workspace/src/lib/reducers/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/reducers/workspace.ts @@ -951,7 +951,7 @@ const fetchDirectoryContent = ( payload: {fileTree; path: string; type?: 'file' | 'folder'}, deletePath?: string ): {[x: string]: Record} => { - console.trace() + // console.trace() if (!payload.fileTree) return state.mode === 'browser' ? state.browser.files @@ -1026,8 +1026,6 @@ const fetchDirectoryContent = ( } } files = _.setWith(files, _path, prevFiles, Object) - const newFiles = sortFilesFetched(files) - console.log({ newFiles }) } else { files = { [payload.path]: normalize( @@ -1037,8 +1035,7 @@ const fetchDirectoryContent = ( ) } } - const newFiles = sortFilesFetched(files) - return newFiles + return files } } } diff --git a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx index f73d7df6c50..821e39220c3 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -989,6 +989,7 @@ export function Workspace() { dispatchHandleClickFile={global.dispatchHandleClickFile} dispatchSetFocusElement={global.dispatchSetFocusElement} dispatchFetchDirectory={global.dispatchFetchDirectory} + dispatchDirectoriesSort={global.dispatchDirectoriesSort} dispatchRemoveInputField={global.dispatchRemoveInputField} dispatchAddInputField={global.dispatchAddInputField} dispatchHandleExpandPath={global.dispatchHandleExpandPath} @@ -1047,6 +1048,7 @@ export function Workspace() { dispatchHandleClickFile={global.dispatchHandleClickFile} dispatchSetFocusElement={global.dispatchSetFocusElement} dispatchFetchDirectory={global.dispatchFetchDirectory} + dispatchDirectoriesSort={global.dispatchDirectoriesSort} dispatchRemoveInputField={global.dispatchRemoveInputField} dispatchAddInputField={global.dispatchAddInputField} dispatchHandleExpandPath={global.dispatchHandleExpandPath} diff --git a/libs/remix-ui/workspace/src/lib/types/index.ts b/libs/remix-ui/workspace/src/lib/types/index.ts index 5ded4df7d48..7776ec86d11 100644 --- a/libs/remix-ui/workspace/src/lib/types/index.ts +++ b/libs/remix-ui/workspace/src/lib/types/index.ts @@ -108,6 +108,7 @@ export interface FileExplorerProps { dispatchHandleClickFile: (path: string, type: 'file' | 'folder' | 'gist') => Promise, dispatchSetFocusElement: (elements: { key: string, type: 'file' | 'folder' | 'gist' }[]) => Promise, dispatchFetchDirectory:(path: string) => Promise, + dispatchDirectoriesSort: (files: { [x: string]: Record } | any, direction?: 'asc' | 'desc') => Promise, dispatchRemoveInputField:(path: string) => Promise, dispatchAddInputField:(path: string, type: 'file' | 'folder') => Promise, dispatchHandleExpandPath: (paths: string[]) => Promise, @@ -202,4 +203,4 @@ export type FileFocusContextType = { export type CopyElementType = { key: string type: 'folder' | 'gist' | 'file' | 'workspace' -} \ No newline at end of file +}