mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-09-18 09:29:24 +00:00
Fix error with expansion
This commit is contained in:
parent
4e5789e8f4
commit
65e3141760
@ -32,7 +32,7 @@ interface FileManagerContextValue {
|
|||||||
onDeleteSelected: () => void;
|
onDeleteSelected: () => void;
|
||||||
onDownloadSelected: () => void;
|
onDownloadSelected: () => void;
|
||||||
onDownloadSingle: (file: StirlingFileStub) => void;
|
onDownloadSingle: (file: StirlingFileStub) => void;
|
||||||
onToggleExpansion: (fileId: string) => void;
|
onToggleExpansion: (fileId: FileId) => void;
|
||||||
onAddToRecents: (file: StirlingFileStub) => void;
|
onAddToRecents: (file: StirlingFileStub) => void;
|
||||||
onNewFilesSelect: (files: File[]) => void;
|
onNewFilesSelect: (files: File[]) => void;
|
||||||
|
|
||||||
@ -412,7 +412,7 @@ export const FileManagerProvider: React.FC<FileManagerProviderProps> = ({
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleToggleExpansion = useCallback(async (fileId: string) => {
|
const handleToggleExpansion = useCallback(async (fileId: FileId) => {
|
||||||
const isCurrentlyExpanded = expandedFileIds.has(fileId);
|
const isCurrentlyExpanded = expandedFileIds.has(fileId);
|
||||||
|
|
||||||
// Update expansion state
|
// Update expansion state
|
||||||
@ -446,12 +446,26 @@ export const FileManagerProvider: React.FC<FileManagerProviderProps> = ({
|
|||||||
const historyFiles: StirlingFileStub[] = [];
|
const historyFiles: StirlingFileStub[] = [];
|
||||||
|
|
||||||
// Find the original file
|
// Find the original file
|
||||||
const originalFileId = currentStoredStub.originalFileId || currentStoredStub.id;
|
|
||||||
|
|
||||||
// Collect all files in this history chain
|
// Collect only files in this specific branch (ancestors of current file)
|
||||||
const chainFiles = Array.from(fileMap.values()).filter(file =>
|
const chainFiles: StirlingFileStub[] = [];
|
||||||
(file.originalFileId || file.id) === originalFileId && file.id !== fileId
|
const allFiles = Array.from(fileMap.values());
|
||||||
);
|
|
||||||
|
// Build a map for fast parent lookups
|
||||||
|
const fileIdMap = new Map<FileId, StirlingFileStub>();
|
||||||
|
allFiles.forEach(f => fileIdMap.set(f.id, f));
|
||||||
|
|
||||||
|
// Trace back from current file through parent chain
|
||||||
|
let currentFile = fileIdMap.get(fileId);
|
||||||
|
while (currentFile?.parentFileId) {
|
||||||
|
const parentFile = fileIdMap.get(currentFile.parentFileId);
|
||||||
|
if (parentFile) {
|
||||||
|
chainFiles.push(parentFile);
|
||||||
|
currentFile = parentFile;
|
||||||
|
} else {
|
||||||
|
break; // Parent not found, stop tracing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Sort by version number (oldest first for history display)
|
// Sort by version number (oldest first for history display)
|
||||||
chainFiles.sort((a, b) => (a.versionNumber || 1) - (b.versionNumber || 1));
|
chainFiles.sort((a, b) => (a.versionNumber || 1) - (b.versionNumber || 1));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user