If in viewer load latest file in viewer (#5784)

This commit is contained in:
Reece Browne
2026-02-23 22:33:43 +00:00
committed by GitHub
parent d3494e3287
commit 4f4d93d028
2 changed files with 26 additions and 33 deletions

View File

@@ -25,21 +25,26 @@ describe('getStartupNavigationAction', () => {
expect(getStartupNavigationAction(0, 3, 'pdfTextEditor', 'viewer' as WorkbenchType)).toBeNull();
});
it('does not navigate on non-startup transitions', () => {
expect(getStartupNavigationAction(1, 2, null, 'viewer' as WorkbenchType)).toBeNull();
it('does not navigate when file count decreases', () => {
expect(getStartupNavigationAction(2, 1, null, 'viewer' as WorkbenchType)).toBeNull();
expect(getStartupNavigationAction(3, 1, null, 'fileEditor' as WorkbenchType)).toBeNull();
});
it('does not navigate when user already has files (N→M transitions)', () => {
// User has 1 file, adds another -> no navigation (stay in current workbench)
expect(getStartupNavigationAction(1, 2, null, 'viewer' as WorkbenchType)).toBeNull();
it('navigates to last file when already in viewer and files are added', () => {
expect(getStartupNavigationAction(1, 2, null, 'viewer' as WorkbenchType)).toEqual({
workbench: 'viewer',
activeFileIndex: 1,
});
expect(getStartupNavigationAction(3, 5, null, 'viewer' as WorkbenchType)).toEqual({
workbench: 'viewer',
activeFileIndex: 4,
});
});
it('does not navigate when adding files in non-viewer workbenches', () => {
expect(getStartupNavigationAction(1, 2, null, 'fileEditor' as WorkbenchType)).toBeNull();
// User has 3 files, adds more -> no navigation
expect(getStartupNavigationAction(3, 4, null, 'fileEditor' as WorkbenchType)).toBeNull();
// User has 2 files, deletes 1 -> no navigation
expect(getStartupNavigationAction(2, 1, null, 'viewer' as WorkbenchType)).toBeNull();
expect(getStartupNavigationAction(1, 3, null, 'pageEditor' as WorkbenchType)).toBeNull();
});
it('handles all workbench types consistently for 0→N transitions', () => {

View File

@@ -13,37 +13,25 @@ export function getStartupNavigationAction(
selectedToolKey: string | null,
currentWorkbench: WorkbenchType
): StartupNavigationAction | null {
console.log('[homePageNavigation] Called with:', {
previousFileCount,
currentFileCount,
selectedToolKey,
currentWorkbench,
});
// pdfTextEditor handles its own empty state
if (selectedToolKey === 'pdfTextEditor') {
console.log('[homePageNavigation] pdfTextEditor detected, returning null');
return null;
}
// Only handle transitions from empty (0 files) to some files
if (previousFileCount !== 0) {
console.log('[homePageNavigation] Not a 0→N transition, returning null');
return null;
// Already actively viewing in the viewer → update to the latest file
if (previousFileCount > 0 && currentWorkbench === 'viewer' && currentFileCount > previousFileCount) {
return { workbench: 'viewer', activeFileIndex: currentFileCount - 1 };
}
// 0→1: Go to viewer to view the single file
if (currentFileCount === 1) {
console.log('[homePageNavigation] 0→1 transition, returning viewer');
return { workbench: 'viewer', activeFileIndex: 0 };
// From landing page (no prior files)
if (previousFileCount === 0) {
if (currentFileCount === 1) {
return { workbench: 'viewer', activeFileIndex: 0 };
}
if (currentFileCount > 1) {
return { workbench: 'fileEditor' };
}
}
// 0→N (N>1): Go to fileEditor to manage multiple files
if (currentFileCount > 1) {
console.log('[homePageNavigation] 0→N transition, returning fileEditor');
return { workbench: 'fileEditor' };
}
console.log('[homePageNavigation] Still at 0 files, returning null');
return null;
}