33import { useQueryClient } from "@tanstack/react-query" ;
44import { useAtom } from "jotai" ;
55import { useParams , usePathname } from "next/navigation" ;
6+ import { useLayoutEffect , useRef , useState } from "react" ;
67import { toast } from "sonner" ;
78import NotFound from "@/app/not-found" ;
89import { useTrackingSetup } from "@/hooks/use-tracking-setup" ;
910import { isAnalyticsRefreshingAtom } from "@/stores/jotai/filterAtoms" ;
1011import { AnalyticsToolbar } from "./_components/analytics-toolbar" ;
1112import { FiltersSection } from "./_components/filters-section" ;
1213
13- interface WebsiteLayoutProps {
14+ type WebsiteLayoutProps = {
1415 children : React . ReactNode ;
15- }
16+ } ;
1617
1718export default function WebsiteLayout ( { children } : WebsiteLayoutProps ) {
1819 const { id } = useParams ( ) ;
1920 const pathname = usePathname ( ) ;
2021 const queryClient = useQueryClient ( ) ;
2122 const { isTrackingSetup } = useTrackingSetup ( id as string ) ;
2223 const [ isRefreshing , setIsRefreshing ] = useAtom ( isAnalyticsRefreshingAtom ) ;
23-
24- if ( ! id ) {
25- return < NotFound /> ;
26- }
27-
28- const websiteId = id as string ;
24+ const toolbarRef = useRef < HTMLDivElement > ( null ) ;
25+ const [ toolbarHeight , setToolbarHeight ] = useState ( 88 ) ;
2926
3027 const isAssistantPage =
3128 pathname . includes ( "/assistant" ) ||
@@ -35,6 +32,34 @@ export default function WebsiteLayout({ children }: WebsiteLayoutProps) {
3532 pathname . includes ( "/settings" ) ||
3633 pathname . includes ( "/users" ) ;
3734
35+ useLayoutEffect ( ( ) => {
36+ const element = toolbarRef . current ;
37+ if ( ! element || isAssistantPage || ! isTrackingSetup ) {
38+ setToolbarHeight ( 0 ) ;
39+ return ;
40+ }
41+
42+ const updateHeight = ( ) => {
43+ const height = element . getBoundingClientRect ( ) . height ;
44+ setToolbarHeight ( height ) ;
45+ } ;
46+
47+ updateHeight ( ) ;
48+
49+ const resizeObserver = new ResizeObserver ( updateHeight ) ;
50+ resizeObserver . observe ( element ) ;
51+
52+ return ( ) => {
53+ resizeObserver . disconnect ( ) ;
54+ } ;
55+ } , [ isTrackingSetup , isAssistantPage ] ) ;
56+
57+ if ( ! id ) {
58+ return < NotFound /> ;
59+ }
60+
61+ const websiteId = id as string ;
62+
3863 const handleRefresh = async ( ) => {
3964 setIsRefreshing ( true ) ;
4065 try {
@@ -59,7 +84,10 @@ export default function WebsiteLayout({ children }: WebsiteLayoutProps) {
5984 return (
6085 < div className = "flex h-full flex-col overflow-hidden" >
6186 { isTrackingSetup && ! isAssistantPage && (
62- < div className = "fixed top-12 right-0 left-0 z-50 flex-shrink-0 space-y-0 bg-background md:top-0 md:left-84" >
87+ < div
88+ className = "fixed top-12 right-0 left-0 z-50 shrink-0 space-y-0 bg-background md:top-0 md:left-84"
89+ ref = { toolbarRef }
90+ >
6391 < AnalyticsToolbar
6492 isRefreshing = { isRefreshing }
6593 onRefresh = { handleRefresh }
@@ -70,7 +98,12 @@ export default function WebsiteLayout({ children }: WebsiteLayoutProps) {
7098 ) }
7199
72100 < div
73- className = { `${ isAssistantPage ? "min-h-0 flex-1" : isTrackingSetup && ! isAssistantPage ? "min-h-0 flex-1 overflow-y-auto pt-[88px] md:pt-[88px]" : "min-h-0 flex-1 overflow-y-auto" } ` }
101+ className = { `${ isAssistantPage ? "min-h-0 flex-1" : isTrackingSetup && ! isAssistantPage ? "min-h-0 flex-1 overflow-y-auto" : "min-h-0 flex-1 overflow-y-auto" } ` }
102+ style = {
103+ isTrackingSetup && ! isAssistantPage
104+ ? { paddingTop : `${ toolbarHeight } px` }
105+ : undefined
106+ }
74107 >
75108 { children }
76109 </ div >
0 commit comments