From df3459eb81c5512141aa756802aa75be76021a0e Mon Sep 17 00:00:00 2001 From: Sanjeev Lakhwani Date: Wed, 25 Sep 2024 14:49:30 -0400 Subject: [PATCH] rebased onto main --- src/js/components/ResponsiveContext.tsx | 35 ++++++++++++++++++++++ src/js/components/SiteHeader.tsx | 39 ++++++++++++++++--------- src/js/components/SiteSider.tsx | 1 + src/js/index.tsx | 35 ++++++++++++---------- src/styles.css | 11 +++++++ 5 files changed, 91 insertions(+), 30 deletions(-) create mode 100644 src/js/components/ResponsiveContext.tsx diff --git a/src/js/components/ResponsiveContext.tsx b/src/js/components/ResponsiveContext.tsx new file mode 100644 index 00000000..69054776 --- /dev/null +++ b/src/js/components/ResponsiveContext.tsx @@ -0,0 +1,35 @@ +import type { ReactNode } from 'react'; +import React, { createContext, useState, useContext, useEffect } from 'react'; + +interface ResponsiveContextType { + isMobile: boolean; +} + +const ResponsiveContext = createContext(undefined); + +interface ResponsiveProviderProps { + children: ReactNode; +} + +export const ResponsiveProvider = ({ children }: ResponsiveProviderProps) => { + const [isMobile, setIsMobile] = useState(false); + + useEffect(() => { + const handleResize = () => { + setIsMobile(window.innerWidth <= 768); // Adjust this breakpoint as needed + }; + handleResize(); + window.addEventListener('resize', handleResize); + return () => window.removeEventListener('resize', handleResize); + }, []); + + return {children}; +}; + +export const useResponsive = (): ResponsiveContextType => { + const context = useContext(ResponsiveContext); + if (context === undefined) { + throw new Error('useResponsive must be used within a ResponsiveProvider'); + } + return context; +}; diff --git a/src/js/components/SiteHeader.tsx b/src/js/components/SiteHeader.tsx index c3dc2b8f..81aefc67 100644 --- a/src/js/components/SiteHeader.tsx +++ b/src/js/components/SiteHeader.tsx @@ -15,6 +15,7 @@ import { DEFAULT_TRANSLATION, LNG_CHANGE, LNGS_FULL_NAMES } from '@/constants/co import { CLIENT_NAME, PORTAL_URL, TRANSLATED } from '@/config'; import ScopePickerModal from './Scope/ScopePickerModal'; +import { useResponsive } from '@/components/ResponsiveContext'; const { Header } = Layout; @@ -24,6 +25,7 @@ const SiteHeader = () => { const { t, i18n } = useTranslation(DEFAULT_TRANSLATION); const navigate = useNavigate(); const location = useLocation(); + const { isMobile } = useResponsive(); const { isFetching: openIdConfigFetching } = useOpenIdConfig(); const { isHandingOffCodeForToken } = useAuthState(); @@ -65,16 +67,25 @@ const SiteHeader = () => { return (
- - logo navigate(`/${i18n.language}${scopeToUrl(scopeObj)}`)} - /> + + {isMobile ? ( + logo navigate(`/${i18n.language}${scopeToUrl(scopeObj)}`)} + /> + ) : ( + logo navigate(`/${i18n.language}${scopeToUrl(scopeObj)}`)} + /> + )} {CLIENT_NAME} @@ -95,7 +106,7 @@ const SiteHeader = () => { - + {TRANSLATED && ( )} {isAuthenticated ? ( ) : ( )} diff --git a/src/js/components/SiteSider.tsx b/src/js/components/SiteSider.tsx index aac2a4a3..bf941e1b 100644 --- a/src/js/components/SiteSider.tsx +++ b/src/js/components/SiteSider.tsx @@ -75,6 +75,7 @@ const SiteSider: React.FC<{ return ( { return ( @@ -51,22 +52,24 @@ const RootApp = () => { return ( - - - - - - - + + + + + + + + + ); diff --git a/src/styles.css b/src/styles.css index a7fc01ab..53916297 100644 --- a/src/styles.css +++ b/src/styles.css @@ -27,6 +27,10 @@ body { border-right: 1px solid #f0f0f0; } +.ant-layout-header { + padding: 0 !important; +} + .select-project-title { transition: all 0.2s; } @@ -108,3 +112,10 @@ body { } /* END search results pane */ + +@media (max-width: 768px) { + .ant-layout-content { + padding: 10px !important; + } +} +