fix: Adjust height of sidebar to fit on screen when top banner is visible (#8795)

* Adjust height of sidebar to fit on screen when top banner is visible

* Remove empty space on the bottom of the sidebar

* Remove gap at bottom left of sidebar

* fix: use layout effect and resize observer

Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>

---------

Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
Co-authored-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: Keith Williams <keithwillcode@gmail.com>
This commit is contained in:
paridhi7
2023-05-30 15:05:46 +00:00
committed by GitHub
co-authored by Udit Takkar Udit Takkar Peer Richelsen Keith Williams
parent dab0176938
commit 54271283af
+39 -8
View File
@@ -5,7 +5,7 @@ import Link from "next/link";
import type { NextRouter } from "next/router";
import { useRouter } from "next/router";
import type { Dispatch, ReactNode, SetStateAction } from "react";
import React, { Fragment, useEffect, useState } from "react";
import React, { Fragment, useEffect, useState, useRef, useLayoutEffect } from "react";
import { Toaster } from "react-hot-toast";
import dayjs from "@calcom/dayjs";
@@ -140,6 +140,27 @@ function useRedirectToOnboardingIfNeeded() {
const Layout = (props: LayoutProps) => {
const pageTitle = typeof props.heading === "string" && !props.title ? props.heading : props.title;
const bannerRef = useRef<HTMLDivElement | null>(null);
const [bannersHeight, setBannersHeight] = useState<number>(0);
useLayoutEffect(() => {
const resizeObserver = new ResizeObserver((entries) => {
const { offsetHeight } = entries[0].target as HTMLElement;
setBannersHeight(offsetHeight);
});
const currentBannerRef = bannerRef.current;
if (currentBannerRef) {
resizeObserver.observe(currentBannerRef);
}
return () => {
if (currentBannerRef) {
resizeObserver.unobserve(currentBannerRef);
}
};
}, [bannerRef]);
return (
<>
@@ -155,14 +176,14 @@ const Layout = (props: LayoutProps) => {
{/* todo: only run this if timezone is different */}
<TimezoneChangeDialog />
<div className="flex min-h-screen flex-col">
<div className="divide-y divide-black">
<div style={{ paddingTop: `${bannersHeight}px` }} className="flex min-h-screen flex-col">
<div ref={bannerRef} className="fixed top-0 z-10 w-full divide-y divide-black">
<TeamsUpgradeBanner />
<ImpersonatingBanner />
<AdminPasswordBanner />
</div>
<div className="flex flex-1" data-testid="dashboard-shell">
{props.SidebarContainer || <SideBarContainer />}
{props.SidebarContainer || <SideBarContainer bannersHeight={bannersHeight} />}
<div className="flex w-0 flex-1 flex-col">
<MainContainer {...props} />
</div>
@@ -736,7 +757,15 @@ const MobileNavigationMoreItem: React.FC<{
);
};
function SideBarContainer() {
type SideBarContainerProps = {
bannersHeight: number;
};
type SideBarProps = {
bannersHeight: number;
};
function SideBarContainer({ bannersHeight }: SideBarContainerProps) {
const { status } = useSession();
const router = useRouter();
@@ -745,13 +774,15 @@ function SideBarContainer() {
// Though when logged out, app store pages would temporarily show SideBar until session status is confirmed.
if (status !== "loading" && status !== "authenticated") return null;
if (router.route.startsWith("/v2/settings/")) return null;
return <SideBar />;
return <SideBar bannersHeight={bannersHeight} />;
}
function SideBar() {
function SideBar({ bannersHeight }: SideBarProps) {
return (
<div className="relative">
<aside className="desktop-transparent bg-muted border-muted top-0 hidden h-full max-h-screen w-14 flex-col overflow-y-auto overflow-x-hidden border-r dark:bg-gradient-to-tr dark:from-[#2a2a2a] dark:to-[#1c1c1c] md:sticky md:flex lg:w-56 lg:px-4">
<aside
style={{ maxHeight: `calc(100vh - ${bannersHeight}px)`, top: `${bannersHeight}px` }}
className="desktop-transparent bg-muted border-muted fixed left-0 hidden h-full max-h-screen w-14 flex-col overflow-y-auto overflow-x-hidden border-r dark:bg-gradient-to-tr dark:from-[#2a2a2a] dark:to-[#1c1c1c] md:sticky md:flex lg:w-56 lg:px-4">
<div className="flex h-full flex-col justify-between py-3 lg:pt-6 ">
<header className="items-center justify-between md:hidden lg:flex">
<Link href="/event-types" className="px-2">