From 6442c8017e12810d03088b27786ceafb4ee4ab98 Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Tue, 8 Jun 2021 11:19:49 -0500 Subject: [PATCH] Make sure to only refresh navbar and modals when required --- components/common/Layout/Layout.tsx | 70 ++++++++++++++++++----------- components/ui/context.tsx | 70 ++++++++++++++++++++--------- 2 files changed, 92 insertions(+), 48 deletions(-) diff --git a/components/common/Layout/Layout.tsx b/components/common/Layout/Layout.tsx index 75d995c23..ff6d72aaf 100644 --- a/components/common/Layout/Layout.tsx +++ b/components/common/Layout/Layout.tsx @@ -49,21 +49,53 @@ interface Props { } } +const ModalView: FC<{ modalView: string; closeModal(): any }> = ({ + modalView, + closeModal, +}) => { + return ( + + {modalView === 'LOGIN_VIEW' && } + {modalView === 'SIGNUP_VIEW' && } + {modalView === 'FORGOT_VIEW' && } + + ) +} + +const ModalUI: FC = () => { + const { displayModal, closeModal, modalView } = useUI() + return displayModal ? ( + + ) : null +} + +const SidebarView: FC<{ sidebarView: string; closeSidebar(): any }> = ({ + sidebarView, + closeSidebar, +}) => { + return ( + + {sidebarView === 'CART_VIEW' && } + {sidebarView === 'CHECKOUT_VIEW' && } + {sidebarView === 'PAYMENT_VIEW' && } + {sidebarView === 'SHIPPING_VIEW' && } + + ) +} + +const SidebarUI: FC = () => { + const { displaySidebar, closeSidebar, sidebarView } = useUI() + return displaySidebar ? ( + + ) : null +} + const Layout: FC = ({ children, pageProps: { categories = [], ...pageProps }, }) => { - const { - displaySidebar, - displayModal, - closeSidebar, - closeModal, - modalView, - sidebarView, - } = useUI() const { acceptedCookies, onAcceptCookies } = useAcceptCookies() const { locale = 'en-US' } = useRouter() - const navBarlinks = categories.slice(0, 2).map((c) => ({ label: c.name, href: `/search/${c.slug}`, @@ -75,24 +107,8 @@ const Layout: FC = ({
{children}