fix(file-manager): don't show items from other folder

This commit is contained in:
Simon Chan 2021-07-13 16:47:44 +08:00
parent aa212685e4
commit 37e82267bc

View file

@ -130,6 +130,10 @@ export const FileManager = withDisplayName('FileManager')((): JSX.Element | null
const items: ListItem[] = []; const items: ListItem[] = [];
const linkItems: AdbSyncEntryResponse[] = []; const linkItems: AdbSyncEntryResponse[] = [];
const intervalId = setInterval(() => { const intervalId = setInterval(() => {
if (currentPath !== currentPathRef.current) {
return;
}
setItems(items.slice()); setItems(items.slice());
}, 1000); }, 1000);
@ -138,7 +142,7 @@ export const FileManager = withDisplayName('FileManager')((): JSX.Element | null
for await (const entry of sync.opendir(currentPath)) { for await (const entry of sync.opendir(currentPath)) {
if (currentPath !== currentPathRef.current) { if (currentPath !== currentPathRef.current) {
break; return;
} }
if (entry.name === '.' || entry.name === '..') { if (entry.name === '.' || entry.name === '..') {
@ -159,6 +163,10 @@ export const FileManager = withDisplayName('FileManager')((): JSX.Element | null
} }
for (const entry of linkItems) { for (const entry of linkItems) {
if (currentPath !== currentPathRef.current) {
return;
}
if (!await sync.isDirectory(path.resolve(currentPath, entry.name!))) { if (!await sync.isDirectory(path.resolve(currentPath, entry.name!))) {
entry.mode = (LinuxFileType.File << 12) | entry.permission; entry.mode = (LinuxFileType.File << 12) | entry.permission;
entry.size = 0; entry.size = 0;
@ -167,6 +175,9 @@ export const FileManager = withDisplayName('FileManager')((): JSX.Element | null
items.push(toListItem(entry)); items.push(toListItem(entry));
} }
if (currentPath !== currentPathRef.current) {
return;
}
setItems(items); setItems(items);
listRef.current?.scrollToIndex(0); listRef.current?.scrollToIndex(0);
} finally { } finally {