2023-03-23 11:41:58 +00:00
|
|
|
import React, { useEffect, useRef, useState } from "react";
|
|
|
|
|
import { useLocation } from "react-router-dom";
|
|
|
|
|
import { ThemeProvider } from "styled-components";
|
|
|
|
|
import type { ApplicationPayload } from "@appsmith/constants/ReduxActionConstants";
|
|
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
|
|
import type { AppState } from "@appsmith/reducers";
|
|
|
|
|
import {
|
2024-07-31 02:54:51 +00:00
|
|
|
getCurrentBasePageId,
|
2023-03-23 11:41:58 +00:00
|
|
|
getViewModePageList,
|
|
|
|
|
} from "selectors/editorSelectors";
|
2024-01-25 13:41:48 +00:00
|
|
|
import { getCurrentWorkspaceId } from "@appsmith/selectors/selectedWorkspaceSelectors";
|
2023-03-23 11:41:58 +00:00
|
|
|
import { getCurrentUser } from "selectors/usersSelectors";
|
|
|
|
|
import type { User } from "constants/userConstants";
|
|
|
|
|
import type { Theme } from "constants/DefaultTheme";
|
|
|
|
|
import { getThemeDetails, ThemeMode } from "selectors/themeSelectors";
|
|
|
|
|
import HtmlTitle from "../AppViewerHtmlTitle";
|
|
|
|
|
import { NAVIGATION_SETTINGS } from "constants/AppConstants";
|
|
|
|
|
import PageMenu from "pages/AppViewer/PageMenu";
|
|
|
|
|
import { useHref } from "pages/Editor/utils";
|
2023-10-12 05:31:22 +00:00
|
|
|
import { builderURL } from "@appsmith/RouteBuilder";
|
2023-03-23 11:41:58 +00:00
|
|
|
import TopHeader from "./components/TopHeader";
|
|
|
|
|
import Sidebar from "./Sidebar";
|
2023-03-29 17:07:06 +00:00
|
|
|
import { getCurrentApplication } from "@appsmith/selectors/applicationSelectors";
|
2023-03-23 11:41:58 +00:00
|
|
|
import { useIsMobileDevice } from "utils/hooks/useDeviceDetect";
|
|
|
|
|
import { setAppViewHeaderHeight } from "actions/appViewActions";
|
2024-04-19 09:36:50 +00:00
|
|
|
import AnalyticsUtil from "@appsmith/utils/AnalyticsUtil";
|
2023-03-23 11:41:58 +00:00
|
|
|
|
|
|
|
|
export function Navigation() {
|
|
|
|
|
const { search } = useLocation();
|
|
|
|
|
const queryParams = new URLSearchParams(search);
|
2023-06-05 14:07:39 +00:00
|
|
|
const isEmbed = queryParams.get("embed") === "true";
|
2023-06-22 05:00:24 +00:00
|
|
|
const showNavBar = queryParams.get("navbar") === "true";
|
|
|
|
|
const hideHeader = isEmbed && !showNavBar;
|
2023-03-23 11:41:58 +00:00
|
|
|
const [isMenuOpen, setMenuOpen] = useState(false);
|
|
|
|
|
const headerRef = useRef<HTMLDivElement>(null);
|
2024-07-31 02:54:51 +00:00
|
|
|
const basePageId = useSelector(getCurrentBasePageId);
|
|
|
|
|
const editorURL = useHref(builderURL, { basePageId });
|
2023-03-23 11:41:58 +00:00
|
|
|
const currentWorkspaceId: string = useSelector(getCurrentWorkspaceId);
|
|
|
|
|
const currentUser: User | undefined = useSelector(getCurrentUser);
|
|
|
|
|
const lightTheme: Theme = useSelector((state: AppState) =>
|
|
|
|
|
getThemeDetails(state, ThemeMode.LIGHT),
|
|
|
|
|
);
|
|
|
|
|
const currentApplicationDetails: ApplicationPayload | undefined = useSelector(
|
|
|
|
|
getCurrentApplication,
|
|
|
|
|
);
|
|
|
|
|
const pages = useSelector(getViewModePageList);
|
|
|
|
|
const isMobile = useIsMobileDevice();
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const header = document.querySelector(".js-appviewer-header");
|
|
|
|
|
|
|
|
|
|
dispatch(setAppViewHeaderHeight(header?.clientHeight || 0));
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
dispatch(setAppViewHeaderHeight(0));
|
|
|
|
|
};
|
|
|
|
|
}, [
|
|
|
|
|
currentApplicationDetails?.applicationDetail?.navigationSetting?.navStyle,
|
|
|
|
|
currentApplicationDetails?.applicationDetail?.navigationSetting
|
|
|
|
|
?.orientation,
|
|
|
|
|
]);
|
2023-06-22 05:00:24 +00:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (showNavBar && currentApplicationDetails) {
|
|
|
|
|
AnalyticsUtil.logEvent("APP_VIEWED_WITH_NAVBAR", {
|
|
|
|
|
id: currentApplicationDetails.id,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, [showNavBar, currentApplicationDetails]);
|
2023-03-23 11:41:58 +00:00
|
|
|
|
|
|
|
|
const renderNavigation = () => {
|
|
|
|
|
if (
|
|
|
|
|
currentApplicationDetails?.applicationDetail?.navigationSetting
|
|
|
|
|
?.orientation === NAVIGATION_SETTINGS.ORIENTATION.SIDE
|
|
|
|
|
) {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{/*
|
|
|
|
|
* We need to add top header since we want the current mobile
|
|
|
|
|
* navigation experience until we create the new sidebar for mobile.
|
|
|
|
|
*/}
|
|
|
|
|
{isMobile ? (
|
|
|
|
|
<TopHeader
|
|
|
|
|
currentApplicationDetails={currentApplicationDetails}
|
|
|
|
|
currentUser={currentUser}
|
|
|
|
|
currentWorkspaceId={currentWorkspaceId}
|
|
|
|
|
isMenuOpen={isMenuOpen}
|
|
|
|
|
pages={pages}
|
|
|
|
|
setMenuOpen={setMenuOpen}
|
2023-06-05 14:07:39 +00:00
|
|
|
showUserSettings={!isEmbed}
|
2023-03-23 11:41:58 +00:00
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<Sidebar
|
|
|
|
|
currentApplicationDetails={currentApplicationDetails}
|
|
|
|
|
currentUser={currentUser}
|
|
|
|
|
currentWorkspaceId={currentWorkspaceId}
|
|
|
|
|
pages={pages}
|
2023-06-05 14:07:39 +00:00
|
|
|
showUserSettings={!isEmbed}
|
2023-03-23 11:41:58 +00:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<TopHeader
|
|
|
|
|
currentApplicationDetails={currentApplicationDetails}
|
|
|
|
|
currentUser={currentUser}
|
|
|
|
|
currentWorkspaceId={currentWorkspaceId}
|
|
|
|
|
isMenuOpen={isMenuOpen}
|
|
|
|
|
pages={pages}
|
|
|
|
|
setMenuOpen={setMenuOpen}
|
2023-06-05 14:07:39 +00:00
|
|
|
showUserSettings={!isEmbed}
|
2023-03-23 11:41:58 +00:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (hideHeader) return <HtmlTitle />;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ThemeProvider theme={lightTheme}>
|
|
|
|
|
<div ref={headerRef}>
|
|
|
|
|
{/* Since the Backend doesn't have navigationSetting field by default
|
|
|
|
|
and we are creating the default values only when any nav settings via the
|
|
|
|
|
settings pane has changed, we need to hide the navbar ONLY when the showNavbar
|
|
|
|
|
setting is explicitly set to false by the user via the settings pane. */}
|
|
|
|
|
{currentApplicationDetails?.applicationDetail?.navigationSetting
|
|
|
|
|
?.showNavbar !== false && renderNavigation()}
|
|
|
|
|
|
|
|
|
|
{/* Mobile Sidebar */}
|
|
|
|
|
<PageMenu
|
|
|
|
|
application={currentApplicationDetails}
|
|
|
|
|
headerRef={headerRef}
|
|
|
|
|
isOpen={isMenuOpen}
|
|
|
|
|
pages={pages}
|
|
|
|
|
setMenuOpen={setMenuOpen}
|
|
|
|
|
url={editorURL}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</ThemeProvider>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default Navigation;
|