Skip to content

Commit

Permalink
add types for sort function
Browse files Browse the repository at this point in the history
  • Loading branch information
joeizang committed Sep 11, 2023
1 parent 59072e5 commit 5afd2d0
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 9 deletions.
4 changes: 3 additions & 1 deletion libs/remix-ui/workspace/src/lib/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions libs/remix-ui/workspace/src/lib/components/file-explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
const [state, setState] = useState<WorkSpaceState>(workspaceState)
const [sortIcon, setSortIcon] = useState(sortIconDesc)
const treeRef = useRef<HTMLDivElement>(null)
console.log({ props })

useEffect(() => {
if (contextMenuItems) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -307,6 +309,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
<span className={sortIcon} onClick={() => {
console.log('sorting clicked')
sortIcon === sortIconDesc ? setSortIcon(sortIconAsc) : setSortIcon(sortIconDesc)
props.dispatchDirectoriesSort(files[ROOT_PATH])
}}></span>
</CustomTooltip>
</span>
Expand Down
5 changes: 3 additions & 2 deletions libs/remix-ui/workspace/src/lib/contexts/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -13,6 +14,7 @@ export const FileSystemContext = createContext<{
dispatchCreateWorkspace: (workspaceName: string, workspaceTemplateName: string, opts?, initGitRepo?: boolean) => Promise<void>,
toast: (toasterMsg: string) => void,
dispatchFetchWorkspaceDirectory: (path: string) => Promise<void>,
dispatchDirectoriesSort: (files: { [x: string]: Record<string, FileType> } | any, direction?: 'asc' | 'desc') => Promise<any>,
dispatchSwitchToWorkspace: (name: string) => Promise<void>,
dispatchRenameWorkspace: (oldName: string, workspaceName: string) => Promise<void>,
dispatchDeleteWorkspace: (workspaceName: string) => Promise<void>,
Expand Down Expand Up @@ -47,5 +49,4 @@ export const FileSystemContext = createContext<{
dispatchCreateSlitherGithubAction: () => Promise<void>
dispatchCreateHelperScripts: (script: string) => Promise<void>
}>(null)



Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -305,6 +310,7 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
toast,
dispatchInitWorkspace,
dispatchFetchDirectory,
dispatchDirectoriesSort,
dispatchAddInputField,
dispatchRemoveInputField,
dispatchCreateWorkspace,
Expand Down
7 changes: 2 additions & 5 deletions libs/remix-ui/workspace/src/lib/reducers/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ const fetchDirectoryContent = (
payload: {fileTree; path: string; type?: 'file' | 'folder'},
deletePath?: string
): {[x: string]: Record<string, FileType>} => {
console.trace()
// console.trace()
if (!payload.fileTree)
return state.mode === 'browser'
? state.browser.files
Expand Down Expand Up @@ -1026,8 +1026,6 @@ const fetchDirectoryContent = (
}
}
files = _.setWith(files, _path, prevFiles, Object)
const newFiles = sortFilesFetched(files)
console.log({ newFiles })
} else {
files = {
[payload.path]: normalize(
Expand All @@ -1037,8 +1035,7 @@ const fetchDirectoryContent = (
)
}
}
const newFiles = sortFilesFetched(files)
return newFiles
return files
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down
3 changes: 2 additions & 1 deletion libs/remix-ui/workspace/src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export interface FileExplorerProps {
dispatchHandleClickFile: (path: string, type: 'file' | 'folder' | 'gist') => Promise<void>,
dispatchSetFocusElement: (elements: { key: string, type: 'file' | 'folder' | 'gist' }[]) => Promise<void>,
dispatchFetchDirectory:(path: string) => Promise<void>,
dispatchDirectoriesSort: (files: { [x: string]: Record<string, FileType> } | any, direction?: 'asc' | 'desc') => Promise<any>,
dispatchRemoveInputField:(path: string) => Promise<void>,
dispatchAddInputField:(path: string, type: 'file' | 'folder') => Promise<void>,
dispatchHandleExpandPath: (paths: string[]) => Promise<void>,
Expand Down Expand Up @@ -202,4 +203,4 @@ export type FileFocusContextType = {
export type CopyElementType = {
key: string
type: 'folder' | 'gist' | 'file' | 'workspace'
}
}

0 comments on commit 5afd2d0

Please sign in to comment.