diff --git a/frontend/src/core/pages/HomePage.tsx b/frontend/src/core/pages/HomePage.tsx index 4aee49272..0de70011a 100644 --- a/frontend/src/core/pages/HomePage.tsx +++ b/frontend/src/core/pages/HomePage.tsx @@ -9,6 +9,9 @@ import { useBaseUrl } from "@app/hooks/useBaseUrl"; import { useIsMobile } from "@app/hooks/useIsMobile"; import { useAppConfig } from "@app/contexts/AppConfigContext"; import { useLogoPath } from "@app/hooks/useLogoPath"; +import { useFileContext } from "@app/contexts/file/fileHooks"; +import { useNavigationActions } from "@app/contexts/NavigationContext"; +import { useViewer } from "@app/contexts/ViewerContext"; import AppsIcon from '@mui/icons-material/AppsRounded'; import ToolPanel from "@app/components/tools/ToolPanel"; @@ -53,6 +56,11 @@ export default function HomePage() { const [configModalOpen, setConfigModalOpen] = useState(false); const [showAnalyticsModal, setShowAnalyticsModal] = useState(false); + const { activeFiles } = useFileContext(); + const { actions } = useNavigationActions(); + const { setActiveFileIndex } = useViewer(); + const prevFileCountRef = useRef(activeFiles.length); + // Show admin analytics choice modal if analytics settings not configured useEffect(() => { if (config && config.enableAnalytics === null) { @@ -60,6 +68,19 @@ export default function HomePage() { } }, [config]); + // Auto-switch to viewer when going from 0 to 1 file + useEffect(() => { + const prevCount = prevFileCountRef.current; + const currentCount = activeFiles.length; + + if (prevCount === 0 && currentCount === 1) { + actions.setWorkbench('viewer'); + setActiveFileIndex(0); + } + + prevFileCountRef.current = currentCount; + }, [activeFiles.length, actions, setActiveFileIndex]); + const brandAltText = t("home.mobile.brandAlt", "Stirling PDF logo"); const brandIconSrc = useLogoPath(); const brandTextSrc = `${BASE_PATH}/branding/StirlingPDFLogo${