From 84e0bf3795f59f3602d689775f2fba254da72675 Mon Sep 17 00:00:00 2001 From: glicht Date: Thu, 17 Jun 2021 19:56:42 +0300 Subject: [PATCH] try to fix mp sidebar error --- src/theme/MarketplaceSidebar/index.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/theme/MarketplaceSidebar/index.js b/src/theme/MarketplaceSidebar/index.js index 6ccf2c9e9..791c8cfe8 100644 --- a/src/theme/MarketplaceSidebar/index.js +++ b/src/theme/MarketplaceSidebar/index.js @@ -317,6 +317,19 @@ function DocSidebarItem(props) { } } +function useShowAnnouncementBar() { + const {isAnnouncementBarClosed} = useUserPreferencesContext(); + const [showAnnouncementBar, setShowAnnouncementBar] = useState( + !isAnnouncementBarClosed, + ); + useScrollPosition(({scrollY}) => { + if (!isAnnouncementBarClosed) { + setShowAnnouncementBar(scrollY === 0); + } + }); + return showAnnouncementBar; +} + function MarketplaceSidebar({ path, sidebar, @@ -327,6 +340,7 @@ function MarketplaceSidebar({ totalPacks, totalFilteredPacks, }) { + const showAnnouncementBar = useShowAnnouncementBar(); const [showResponsiveSidebar, setShowResponsiveSidebar] = useState(false); const { navbar: { hideOnScroll }, @@ -357,8 +371,7 @@ function MarketplaceSidebar({ styles.menu, { "menu--show": showResponsiveSidebar, - [styles.menuWithAnnouncementBar]: - !isAnnouncementBarClosed && scrollY === 0, + [styles.menuWithAnnouncementBar]: showAnnouncementBar } )} >