Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

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

Reece Browne4f4d93d028db
diff --git a/frontend/src/core/utils/homePageNavigation.test.ts b/frontend/src/core/utils/homePageNavigation.test.ts
index e6cadf79ed..14b107aa3a 100644
--- a/frontend/src/core/utils/homePageNavigation.test.ts
+++ b/frontend/src/core/utils/homePageNavigation.test.ts
@@ -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();
- expect(getStartupNavigationAction(1, 2, null, 'fileEditor' 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,
+ });
+ });
- // User has 3 files, adds more -> no navigation
+ it('does not navigate when adding files in non-viewer workbenches', () => {
+ expect(getStartupNavigationAction(1, 2, null, 'fileEditor' as WorkbenchType)).toBeNull();
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', () => {
diff --git a/frontend/src/core/utils/homePageNavigation.ts b/frontend/src/core/utils/homePageNavigation.ts
index 02f1616431..cb3461e076 100644
--- a/frontend/src/core/utils/homePageNavigation.ts
+++ b/frontend/src/core/utils/homePageNavigation.ts
@@ -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;
}
- // 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 };
+ // 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→N (N>1): Go to fileEditor to manage multiple files
- if (currentFileCount > 1) {
- console.log('[homePageNavigation] 0→N transition, returning fileEditor');
- return { workbench: 'fileEditor' };
+ // From landing page (no prior files)
+ if (previousFileCount === 0) {
+ if (currentFileCount === 1) {
+ return { workbench: 'viewer', activeFileIndex: 0 };
+ }
+ if (currentFileCount > 1) {
+ return { workbench: 'fileEditor' };
+ }
}
- console.log('[homePageNavigation] Still at 0 files, returning null');
return null;
}