import React, { useEffect, useState } from "react"; import { CommonLayout } from "./common-layout"; import { CommonHeader } from "./common-header"; import { BlogFooter } from "./blog-footer"; import clsx from "clsx"; import { BannerSidebar } from "../components/banner/banner-sidebar"; import { BannerModal } from "../components/banner/banner-modal"; import useScrollTracker from "../hooks/use-scroll-tracker"; type Props = { showSidebarBanner?: boolean; } & Record; export const RefineBlogLayout = (props: Props) => { const [shouldShowBanner, setShouldShowBanner] = useState(false); const { children, toc, showSidebarBanner = true, ...layoutProps } = props; const tracker = useScrollTracker(); useEffect(() => { if (!showSidebarBanner) return; if (tracker.scrollY > 20) { setShouldShowBanner(true); } if (tracker.scrollY < 20) { setShouldShowBanner(false); } }, [tracker.scrollY, showSidebarBanner]); return ( {/* If there's TOC, then we can say that this is a blog post page. */} {/* Then we can pass `trackProgress` prop to the header. */}
{showSidebarBanner && (
)}
{children}
{toc && (
{toc}
)}
); };