mirror of
https://github.com/ikun0014/lx-music-mobile.git
synced 2025-07-03 22:42:09 +08:00
修复使用范围存储时的新建文件夹问题
This commit is contained in:
parent
154ee13953
commit
74554ab088
@ -122,19 +122,21 @@ export default forwardRef<ListType, ListProps>(({
|
|||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const readDir = async(newPath: string, dirOnly: boolean, filter?: string[], isRefresh?: boolean, isOpen?: boolean) => {
|
const readDir = async(newPath: string, dirOnly: boolean, filter?: string[], isRefresh?: boolean, isOpen?: boolean): Promise<PathItem[]> => {
|
||||||
if (isReading) return
|
if (isReading) return []
|
||||||
setIsReading(true)
|
setIsReading(true)
|
||||||
return handleReadDir(newPath, dirOnly, filter, isRefresh).then(list => {
|
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)
|
if (!isOpen && newPath != path && newPath.startsWith(path)) parentDirInfo.set(newPath, path)
|
||||||
setList(list)
|
setList(list)
|
||||||
setPath(newPath)
|
setPath(newPath)
|
||||||
|
return list
|
||||||
}).catch((err: any) => {
|
}).catch((err: any) => {
|
||||||
toast(`Read dir error: ${err.message as string}`, 'long')
|
toast(`Read dir error: ${err.message as string}`, 'long')
|
||||||
// console.log('prevPath', prevPath)
|
// console.log('prevPath', prevPath)
|
||||||
// if (isReadingDir.current) return
|
// if (isReadingDir.current) return
|
||||||
// setPath(prevPath)
|
// setPath(prevPath)
|
||||||
|
return []
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
setIsReading(false)
|
setIsReading(false)
|
||||||
})
|
})
|
||||||
|
@ -9,6 +9,7 @@ import { scaleSizeH } from '@/utils/pixelRatio'
|
|||||||
import { useStatusbarHeight } from '@/store/common/hook'
|
import { useStatusbarHeight } from '@/store/common/hook'
|
||||||
import NewFolderModal, { type NewFolderType } from './NewFolderModal'
|
import NewFolderModal, { type NewFolderType } from './NewFolderModal'
|
||||||
import OpenStorageModal, { type OpenDirModalType } from './OpenStorageModal'
|
import OpenStorageModal, { type OpenDirModalType } from './OpenStorageModal'
|
||||||
|
import type { PathItem } from './ListItem'
|
||||||
|
|
||||||
|
|
||||||
export default memo(({
|
export default memo(({
|
||||||
@ -19,8 +20,8 @@ export default memo(({
|
|||||||
}: {
|
}: {
|
||||||
title: string
|
title: string
|
||||||
path: string
|
path: string
|
||||||
onRefreshDir: (dir: string) => Promise<void>
|
onRefreshDir: (dir: string) => Promise<PathItem[]>
|
||||||
onOpenDir: (dir: string) => Promise<void>
|
onOpenDir: (dir: string) => Promise<PathItem[]>
|
||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme()
|
const theme = useTheme()
|
||||||
const newFolderTypeRef = useRef<NewFolderType>(null)
|
const newFolderTypeRef = useRef<NewFolderType>(null)
|
||||||
|
@ -6,6 +6,7 @@ import ConfirmAlert, { type ConfirmAlertType } from '@/components/common/Confirm
|
|||||||
import { createStyle, toast } from '@/utils/tools'
|
import { createStyle, toast } from '@/utils/tools'
|
||||||
import { mkdir } from '@/utils/fs'
|
import { mkdir } from '@/utils/fs'
|
||||||
import { useTheme } from '@/store/theme/hook'
|
import { useTheme } from '@/store/theme/hook'
|
||||||
|
import type { PathItem } from './ListItem'
|
||||||
const filterFileName = /[\\/:*?#"<>|]/
|
const filterFileName = /[\\/:*?#"<>|]/
|
||||||
|
|
||||||
|
|
||||||
@ -45,7 +46,7 @@ const NameInput = forwardRef<NameInputType, {}>((props, ref) => {
|
|||||||
export interface NewFolderType {
|
export interface NewFolderType {
|
||||||
show: (path: string) => void
|
show: (path: string) => void
|
||||||
}
|
}
|
||||||
export default forwardRef<NewFolderType, { onRefreshDir: (dir: string) => Promise<void> }>(({ onRefreshDir }, ref) => {
|
export default forwardRef<NewFolderType, { onRefreshDir: (dir: string) => Promise<PathItem[]> }>(({ onRefreshDir }, ref) => {
|
||||||
const confirmAlertRef = useRef<ConfirmAlertType>(null)
|
const confirmAlertRef = useRef<ConfirmAlertType>(null)
|
||||||
const nameInputRef = useRef<NameInputType>(null)
|
const nameInputRef = useRef<NameInputType>(null)
|
||||||
const pathRef = useRef<string>('')
|
const pathRef = useRef<string>('')
|
||||||
@ -74,8 +75,9 @@ export default forwardRef<NewFolderType, { onRefreshDir: (dir: string) => Promis
|
|||||||
}
|
}
|
||||||
const newPath = `${pathRef.current}/${text}`
|
const newPath = `${pathRef.current}/${text}`
|
||||||
mkdir(newPath).then(() => {
|
mkdir(newPath).then(() => {
|
||||||
void onRefreshDir(pathRef.current).then(() => {
|
void onRefreshDir(pathRef.current).then((list) => {
|
||||||
void onRefreshDir(newPath)
|
const target = list.find(item => item.name == text)
|
||||||
|
if (target) void onRefreshDir(target.path)
|
||||||
})
|
})
|
||||||
nameInputRef.current?.setName('')
|
nameInputRef.current?.setName('')
|
||||||
}).catch((err: any) => {
|
}).catch((err: any) => {
|
||||||
|
@ -11,6 +11,7 @@ import Button from '@/components/common/Button'
|
|||||||
import ButtonPrimary from '@/components/common/ButtonPrimary'
|
import ButtonPrimary from '@/components/common/ButtonPrimary'
|
||||||
import { useUnmounted } from '@/utils/hooks'
|
import { useUnmounted } from '@/utils/hooks'
|
||||||
import { Icon } from '@/components/common/Icon'
|
import { Icon } from '@/components/common/Icon'
|
||||||
|
import type { PathItem } from './ListItem'
|
||||||
const filterFileName = /[\\:*?#"<>|]/
|
const filterFileName = /[\\:*?#"<>|]/
|
||||||
|
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ const PathInput = forwardRef<PathInputType, {}>((props, ref) => {
|
|||||||
export interface OpenDirModalType {
|
export interface OpenDirModalType {
|
||||||
show: (paths: string[]) => void
|
show: (paths: string[]) => void
|
||||||
}
|
}
|
||||||
export default forwardRef<OpenDirModalType, { onOpenDir: (dir: string) => Promise<void> }>(({
|
export default forwardRef<OpenDirModalType, { onOpenDir: (dir: string) => Promise<PathItem[]> }>(({
|
||||||
onOpenDir,
|
onOpenDir,
|
||||||
}, ref) => {
|
}, ref) => {
|
||||||
const confirmAlertRef = useRef<ConfirmAlertType>(null)
|
const confirmAlertRef = useRef<ConfirmAlertType>(null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user