mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 19:33:11 +02:00
Automatically switch to Viewer when going to exactly 1 file (#4973)
# Description of Changes Automatically switch to Viewer when going to exactly 1 file
This commit is contained in:
@@ -9,6 +9,9 @@ import { useBaseUrl } from "@app/hooks/useBaseUrl";
|
|||||||
import { useIsMobile } from "@app/hooks/useIsMobile";
|
import { useIsMobile } from "@app/hooks/useIsMobile";
|
||||||
import { useAppConfig } from "@app/contexts/AppConfigContext";
|
import { useAppConfig } from "@app/contexts/AppConfigContext";
|
||||||
import { useLogoPath } from "@app/hooks/useLogoPath";
|
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 AppsIcon from '@mui/icons-material/AppsRounded';
|
||||||
|
|
||||||
import ToolPanel from "@app/components/tools/ToolPanel";
|
import ToolPanel from "@app/components/tools/ToolPanel";
|
||||||
@@ -53,6 +56,11 @@ export default function HomePage() {
|
|||||||
const [configModalOpen, setConfigModalOpen] = useState(false);
|
const [configModalOpen, setConfigModalOpen] = useState(false);
|
||||||
const [showAnalyticsModal, setShowAnalyticsModal] = 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
|
// Show admin analytics choice modal if analytics settings not configured
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (config && config.enableAnalytics === null) {
|
if (config && config.enableAnalytics === null) {
|
||||||
@@ -60,6 +68,19 @@ export default function HomePage() {
|
|||||||
}
|
}
|
||||||
}, [config]);
|
}, [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 brandAltText = t("home.mobile.brandAlt", "Stirling PDF logo");
|
||||||
const brandIconSrc = useLogoPath();
|
const brandIconSrc = useLogoPath();
|
||||||
const brandTextSrc = `${BASE_PATH}/branding/StirlingPDFLogo${
|
const brandTextSrc = `${BASE_PATH}/branding/StirlingPDFLogo${
|
||||||
|
|||||||
Reference in New Issue
Block a user