refactor and fix

pull/5370/head
yann300 7 months ago committed by Joseph Izang
parent 9c48c6e563
commit b31285cf39
  1. 1
      apps/remix-ide/src/app/files/fileManager.ts
  2. 50
      libs/remix-ui/workspace/src/lib/components/file-explorer.tsx
  3. 8
      libs/remix-ui/workspace/src/lib/components/flat-tree-drop.tsx
  4. 6
      libs/remix-ui/workspace/src/lib/components/flat-tree.tsx
  5. 2
      libs/remix-ui/workspace/src/lib/types/index.ts

@ -83,7 +83,6 @@ class FileManager extends Plugin {
* @param {string} message message to display if path doesn't exist.
*/
async _handleExists(path: string, message?: string) {
console.log('_handleExists is called ', { path, message })
const exists = await this.exists(path)
if (!exists) {

@ -303,7 +303,6 @@ export const FileExplorer = (props: FileExplorerProps) => {
const moveFileSilently = async (dest: string, src: string) => {
if (dest.length === 0 || src.length === 0) return
if (await moveFileIsAllowed(src, dest) === false) return
console.log({ src, dest })
try {
props.dispatchMoveFile(src, dest)
} catch (error) {
@ -326,7 +325,6 @@ export const FileExplorer = (props: FileExplorerProps) => {
const moveFolderSilently = async (dest: string, src: string) => {
if (dest.length === 0 || src.length === 0) return
if (await moveFolderIsAllowed(src, dest) === false) return
console.log({ src, dest })
try {
props.dispatchMoveFolder(src, dest)
} catch (error) {
@ -352,52 +350,6 @@ export const FileExplorer = (props: FileExplorerProps) => {
})
}
const handleFileMove = async (dest: string, sourcesrc: string[]) => {
if (await moveFilesIsAllowed(sourcesrc, dest) === false) return
const files = filesSelected && filesSelected.length > 0 && filesSelected.join(' ')
const src = files.length > 0 ? files : sourcesrc.length === 1 ? sourcesrc[0] : sourcesrc.join(' ')
try {
props.modal(
intl.formatMessage({ id: 'filePanel.moveFile' }),
intl.formatMessage({ id: 'filePanel.moveFileMsg1' }, { src, dest }),
intl.formatMessage({ id: 'filePanel.yes' }),
() => props.dispatchMoveFile(copySrc, dest),
intl.formatMessage({ id: 'filePanel.cancel' }),
() => { }
)
} catch (error) {
props.modal(
intl.formatMessage({ id: 'filePanel.movingFileFailed' }),
intl.formatMessage({ id: 'filePanel.movingFileFailedMsg' }, { src }),
intl.formatMessage({ id: 'filePanel.close' }),
async () => { }
)
}
}
const handleFolderMove = async (dest: string, copySrc: string) => {
if (await moveFolderIsAllowed(copySrc, dest) === false) return
const src = filesSelected && filesSelected.length > 0 ? filesSelected.join(' ') : ''
try {
props.modal(
intl.formatMessage({ id: 'filePanel.moveFile' }),
intl.formatMessage({ id: 'filePanel.moveFileMsg1' }, { src, dest }),
intl.formatMessage({ id: 'filePanel.yes' }),
() => props.dispatchMoveFolder(copySrc, dest),
intl.formatMessage({ id: 'filePanel.cancel' }),
() => { }
)
} catch (error) {
props.modal(
intl.formatMessage({ id: 'filePanel.movingFolderFailed' }),
intl.formatMessage({ id: 'filePanel.movingFolderFailedMsg' }, { src }),
intl.formatMessage({ id: 'filePanel.close' }),
async () => { }
)
}
}
const handleTreeClick = (event: SyntheticEvent) => {
let target = event.target as HTMLElement
while (target && target.getAttribute && !target.getAttribute('data-path')) {
@ -466,8 +418,6 @@ export const FileExplorer = (props: FileExplorerProps) => {
expandPath={props.expandPath}
handleContextMenu={handleContextMenu}
warnMovingItems={warnMovingItems}
moveFile={handleFileMove}
moveFolder={handleFolderMove}
moveFolderSilently={moveFolderSilently}
moveFileSilently={moveFileSilently}
setFilesSelected={setFilesSelected}

@ -68,20 +68,20 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => {
if (dragDestination.isDirectory) {
if (dragSource.isDirectory) {
await props.warnMovingItems(filePaths, dragDestination.path)
await moveFoldersSilently(filePaths, dragDestination.path)
await moveFoldersSilently(props.selectedItems, dragDestination.path)
} else {
await props.warnMovingItems(filePaths, dragDestination.path)
await moveFilesSilently(filePaths, dragDestination.path)
await moveFilesSilently(props.selectedItems, dragDestination.path)
}
} else {
const path = extractParentFromKey(dragDestination.path) || '/'
if (dragSource.isDirectory) {
await props.warnMovingItems(filePaths, path)
await moveFoldersSilently(filePaths, path)
await moveFoldersSilently(props.selectedItems, path)
} else {
await props.warnMovingItems(filePaths, path)
await moveFilesSilently(filePaths, path)
await moveFilesSilently(props.selectedItems, path)
}
}
}

@ -36,8 +36,6 @@ interface FlatTreeProps {
handleContextMenu: (pageX: number, pageY: number, path: string, content: string, type: string) => void
handleTreeClick: (e: SyntheticEvent) => void
handleClickFolder: (path: string, type: string) => void
moveFile: (dest: string, src: string) => void
moveFolder: (dest: string, src: string) => void
moveFolderSilently: (dest: string, src: string) => Promise<void>
moveFileSilently: (dest: string, src: string) => Promise<void>
setFilesSelected: Dispatch<React.SetStateAction<string[]>>
@ -55,7 +53,7 @@ let mouseTimer: any = {
}
export const FlatTree = (props: FlatTreeProps) => {
const { files, flatTree, expandPath, focusEdit, editModeOff, handleTreeClick, moveFile, moveFolder, warnMovingItems, fileState, focusElement, handleClickFolder, deletePath, moveFileSilently, moveFolderSilently, setFilesSelected } = props
const { files, flatTree, expandPath, focusEdit, editModeOff, handleTreeClick, warnMovingItems, fileState, focusElement, handleClickFolder, deletePath, moveFileSilently, moveFolderSilently, setFilesSelected } = props
const [hover, setHover] = useState<string>('')
const [mouseOverTarget, setMouseOverTarget] = useState<{
path: string,
@ -263,8 +261,6 @@ export const FlatTree = (props: FlatTreeProps) => {
<FlatTreeDrop
dragSource={dragSource}
getFlatTreeItem={getFlatTreeItem}
moveFile={moveFile}
moveFolder={moveFolder}
warnMovingItems={warnMovingItems}
moveFolderSilently={moveFolderSilently}
moveFileSilently={moveFileSilently}

@ -346,8 +346,6 @@ export type Actions = {[A in keyof ActionPayloadTypes]: Action<A>}[keyof ActionP
export type WorkspaceElement = 'folder' | 'file' | 'workspace'
export interface FlatTreeDropProps {
moveFile: (dest: string, src: string) => void
moveFolder: (dest: string, src: string) => void
moveFolderSilently: (dest: string, src: string) => Promise<void>
moveFileSilently: (dest: string, src: string) => Promise<void>
setFilesSelected: Dispatch<React.SetStateAction<string[]>>

Loading…
Cancel
Save