#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
import { useEffect, type ReactNode } from "react";
import { useTranslation } from "react-i18next";
import { useLocation } from "react-router-dom";
import { ActionIcon } from "@editor/ui";
import { Sidebar } from "@processor/components/Sidebar";
import { PortalSearchBar } from "@processor/components/PortalSearchBar";
import { useUI } from "@processor/contexts/UIContext";
import { Icon } from "@editor/ui/Icon";
import { Logo } from "@editor/ui/Logo";
import "@editor/components/layout/WorkspaceFrame.css";
import { QuickNavHostBridge } from "@editor/components/shared/quickNav/QuickNavHostBridge";
import "@processor/components/AppShell.css";
import { NotificationBell } from "@editor/components/notifications/NotificationBell";
import { useIsPhone } from "@editor/hooks/useIsMobile";
import { ConnectAccountRail } from "@processor/components/ConnectAccountRail";
import { FeedbackTag } from "@editor/components/feedback/FeedbackTag";
/**
* Compact header shown only under the mobile breakpoint (CSS-hidden on
* desktop): hamburger opens the sidebar drawer, search focuses the global
* search bar below (there's no ⌘K on a phone).
*/
function MobileTopbar() {
const { t } = useTranslation();
const { mobileNavOpen, toggleMobileNav, closeMobileNav } = useUI();
return (
<header className="portal-shell__topbar">
<ActionIcon
variant="tertiary"
size="lg"
aria-label={t("portal.shell.topbar.openNav")}
aria-expanded={mobileNavOpen}
onClick={toggleMobileNav}
>
<Icon name="menu" size={20} />
</ActionIcon>
<Logo
variant="iconAndText"
iconHeight="1.6rem"
textHeight="1.3rem"
className="portal-shell__topbar-wordmark"
/>
<ActionIcon
variant="tertiary"
size="lg"
aria-label={t("portal.shell.topbar.search")}
onClick={() => {
closeMobileNav();
document.getElementById("portal-search-input")?.focus();
}}
>
<Icon name="search" size={19} />
</ActionIcon>
</header>
);
}
/**
* Two-column layout: fixed-width sidebar on the left, a scrolling main column on
* the right (topped by the global search bar). Under the mobile breakpoint the
* sidebar becomes an off-canvas drawer behind a scrim, opened from the topbar
* hamburger. The Sidebar reads its state from context, so this shell stays
* prop-free.
*/
export function AppShell({ children }: { children: ReactNode }) {
const { mobileNavOpen, closeMobileNav } = useUI();
const { pathname } = useLocation();
// Below this width the rail, and the bell it carries, is gone.
const isPhone = useIsPhone();
// Navigating (tap on a nav row, back button, deep link) always dismisses the
// drawer. Depends on pathname only: the close fn's identity changes with any
// UI state, and re-running on that would instantly close a just-opened drawer.
useEffect(() => {
closeMobileNav();
}, [pathname]);
useEffect(() => {
if (!mobileNavOpen) return;
function onKey(e: KeyboardEvent) {
if (e.key === "Escape") closeMobileNav();
}
document.addEventListener("keydown", onKey);
return () => document.removeEventListener("keydown", onKey);
}, [mobileNavOpen, closeMobileNav]);
return (
<div className="portal-shell">
<QuickNavHostBridge />
<div className="workspace-frame">
<Sidebar />
</div>
{mobileNavOpen && (
<div
className="portal-shell__scrim"
onClick={closeMobileNav}
aria-hidden
/>
)}
<div className="portal-shell__main">
<MobileTopbar />
<PortalSearchBar />
{/* Phone only: above that the rail carries it, and this would be a second. */}
{isPhone && (
<div className="portal-shell__notifications">
<NotificationBell />
</div>
)}
<main className="portal-shell__view">
<ConnectAccountRail />
{children}
</main>
<FeedbackTag />
</div>
</div>
);
}