diff --git a/src/components/common/ChoosePath/List.tsx b/src/components/common/ChoosePath/List.tsx index 8fba289..c7df503 100644 --- a/src/components/common/ChoosePath/List.tsx +++ b/src/components/common/ChoosePath/List.tsx @@ -122,19 +122,21 @@ export default forwardRef(({ } }, []) - const readDir = async(newPath: string, dirOnly: boolean, filter?: string[], isRefresh?: boolean, isOpen?: boolean) => { - if (isReading) return + const readDir = async(newPath: string, dirOnly: boolean, filter?: string[], isRefresh?: boolean, isOpen?: boolean): Promise => { + if (isReading) return [] setIsReading(true) return handleReadDir(newPath, dirOnly, filter, isRefresh).then(list => { - if (isUnmountedRef.current) return + if (isUnmountedRef.current) return [] if (!isOpen && newPath != path && newPath.startsWith(path)) parentDirInfo.set(newPath, path) setList(list) setPath(newPath) + return list }).catch((err: any) => { toast(`Read dir error: ${err.message as string}`, 'long') // console.log('prevPath', prevPath) // if (isReadingDir.current) return // setPath(prevPath) + return [] }).finally(() => { setIsReading(false) }) diff --git a/src/components/common/ChoosePath/components/Header.tsx b/src/components/common/ChoosePath/components/Header.tsx index 4413326..bcd3df4 100644 --- a/src/components/common/ChoosePath/components/Header.tsx +++ b/src/components/common/ChoosePath/components/Header.tsx @@ -9,6 +9,7 @@ import { scaleSizeH } from '@/utils/pixelRatio' import { useStatusbarHeight } from '@/store/common/hook' import NewFolderModal, { type NewFolderType } from './NewFolderModal' import OpenStorageModal, { type OpenDirModalType } from './OpenStorageModal' +import type { PathItem } from './ListItem' export default memo(({ @@ -19,8 +20,8 @@ export default memo(({ }: { title: string path: string - onRefreshDir: (dir: string) => Promise - onOpenDir: (dir: string) => Promise + onRefreshDir: (dir: string) => Promise + onOpenDir: (dir: string) => Promise }) => { const theme = useTheme() const newFolderTypeRef = useRef(null) diff --git a/src/components/common/ChoosePath/components/NewFolderModal.tsx b/src/components/common/ChoosePath/components/NewFolderModal.tsx index d9d5a56..c040c35 100644 --- a/src/components/common/ChoosePath/components/NewFolderModal.tsx +++ b/src/components/common/ChoosePath/components/NewFolderModal.tsx @@ -6,6 +6,7 @@ import ConfirmAlert, { type ConfirmAlertType } from '@/components/common/Confirm import { createStyle, toast } from '@/utils/tools' import { mkdir } from '@/utils/fs' import { useTheme } from '@/store/theme/hook' +import type { PathItem } from './ListItem' const filterFileName = /[\\/:*?#"<>|]/ @@ -45,7 +46,7 @@ const NameInput = forwardRef((props, ref) => { export interface NewFolderType { show: (path: string) => void } -export default forwardRef Promise }>(({ onRefreshDir }, ref) => { +export default forwardRef Promise }>(({ onRefreshDir }, ref) => { const confirmAlertRef = useRef(null) const nameInputRef = useRef(null) const pathRef = useRef('') @@ -74,8 +75,9 @@ export default forwardRef Promis } const newPath = `${pathRef.current}/${text}` mkdir(newPath).then(() => { - void onRefreshDir(pathRef.current).then(() => { - void onRefreshDir(newPath) + void onRefreshDir(pathRef.current).then((list) => { + const target = list.find(item => item.name == text) + if (target) void onRefreshDir(target.path) }) nameInputRef.current?.setName('') }).catch((err: any) => { diff --git a/src/components/common/ChoosePath/components/OpenStorageModal.tsx b/src/components/common/ChoosePath/components/OpenStorageModal.tsx index 1ac0f89..726570b 100644 --- a/src/components/common/ChoosePath/components/OpenStorageModal.tsx +++ b/src/components/common/ChoosePath/components/OpenStorageModal.tsx @@ -11,6 +11,7 @@ import Button from '@/components/common/Button' import ButtonPrimary from '@/components/common/ButtonPrimary' import { useUnmounted } from '@/utils/hooks' import { Icon } from '@/components/common/Icon' +import type { PathItem } from './ListItem' const filterFileName = /[\\:*?#"<>|]/ @@ -53,7 +54,7 @@ const PathInput = forwardRef((props, ref) => { export interface OpenDirModalType { show: (paths: string[]) => void } -export default forwardRef Promise }>(({ +export default forwardRef Promise }>(({ onOpenDir, }, ref) => { const confirmAlertRef = useRef(null)