Skip to content

Commit

Permalink
Refactor mobile graph components
Browse files Browse the repository at this point in the history
  • Loading branch information
lubej committed Feb 22, 2023
1 parent 54a7564 commit 4e042e0
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 37 deletions.
1 change: 0 additions & 1 deletion src/app/pages/HomePage/GraphTooltip/CipherGraphTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export const CipherGraphTooltip: FC<GraphTooltipExtendedProps> = ({
offsetWidth,
offsetHeight,
}) => {
const { t } = useTranslation()
const theme = useTheme()
const isMobile = useMediaQuery(theme.breakpoints.down('sm'))

Expand Down
25 changes: 24 additions & 1 deletion src/app/pages/HomePage/GraphTooltip/GraphTooltipMobile.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
import { FC, PropsWithChildren } from 'react'
import { MobileBackdrop, MobileGraphTooltip } from './index'
import Fade from '@mui/material/Fade'
import CloseIcon from '@mui/icons-material/Close'
import { COLORS } from '../../../../styles/theme/colors'
import { useTranslation } from 'react-i18next'
import { styled } from '@mui/material/styles'
import Box from '@mui/material/Box'

export const MobileBackdrop = styled(Box)(() => ({
position: 'fixed',
inset: 0,
backgroundColor: COLORS.black,
opacity: 0.3,
zIndex: 4,
}))

export const MobileGraphTooltip = styled(Box)(() => ({
position: 'fixed',
bottom: 0,
left: 0,
right: 0,
height: 120,
zIndex: 4,
'> svg': {
position: 'fixed',
right: 10,
bottom: 125,
},
}))

export interface GraphTooltipMobileProps {
onClose: () => void
Expand Down
26 changes: 2 additions & 24 deletions src/app/pages/HomePage/GraphTooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,6 @@ export interface GraphTooltipStyledProps {
disabled?: boolean
}

export const MobileBackdrop = styled(Box)(() => ({
position: 'fixed',
inset: 0,
backgroundColor: COLORS.black,
opacity: 0.3,
zIndex: 4,
}))

export const MobileGraphTooltip = styled(Box)(() => ({
position: 'fixed',
bottom: 0,
left: 0,
right: 0,
height: 120,
zIndex: 4,
'> svg': {
position: 'fixed',
right: 10,
bottom: 125,
},
}))

export const GraphTooltipStyled = styled(Box, {
shouldForwardProp: (prop: PropertyKey) =>
!(['isMobile', 'disabled'] as (keyof GraphTooltipStyledProps)[]).includes(
Expand Down Expand Up @@ -60,7 +38,7 @@ export const GraphTooltipIcon = styled(Box, {
flex: '0 0 120px',
height: '100%',
borderRight: `2px solid ${COLORS.aqua}`,
backgroundColor: COLORS.brandExtraDark,
backgroundColor: COLORS.brandExtraDark + (isMobile ? '80' : ''),
borderRadius: isMobile ? '12px 0 0 12px' : '0 0 0 0',
}))

Expand All @@ -80,7 +58,7 @@ export const GraphTooltipText = styled(Box, {
justifyContent: 'space-between',
flex: '0 1 100%',
padding: theme.spacing(4),
backgroundColor: disabled ? COLORS.shadowBlue : COLORS.brandExtraDark,
backgroundColor: (disabled ? COLORS.shadowBlue : COLORS.brandExtraDark) + (isMobile ? '80' : ''),
borderRadius: isMobile ? '0 12px 0 0' : '0 12px 12px 0',
}))

Expand Down
9 changes: 6 additions & 3 deletions src/app/pages/HomePage/ParaTimeSelector/Graph/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const GraphCmp: ForwardRefRenderFunction<SVGSVGElement, GraphProps> = (
const emeraldRef = useRef<SVGGElement>(null)
const sapphireRef = useRef<SVGGElement>(null)
const cipherRef = useRef<SVGGElement>(null)
const { setShowTooltip } = useMobileTooltip()
const { setShowMobileTooltip } = useMobileTooltip()

const [showEmeraldTooltip, setShowEmeraldTooltip] = useState(false)

Expand All @@ -105,7 +105,10 @@ const GraphCmp: ForwardRefRenderFunction<SVGSVGElement, GraphProps> = (

useEffect(() => {
setShowEmeraldTooltip(false)
setShowTooltip(ParaTime.Sapphire, false)
setShowMobileTooltip(GraphEndpoint.Consensus, false)
setShowMobileTooltip(GraphEndpoint.Emerald, false)
setShowMobileTooltip(GraphEndpoint.Cipher, false)
setShowMobileTooltip(GraphEndpoint.Sapphire, false)
}, [isMobile])

const isGraphEndpointDisabled = (graphEndpoint: GraphEndpoint) => {
Expand All @@ -126,7 +129,7 @@ const GraphCmp: ForwardRefRenderFunction<SVGSVGElement, GraphProps> = (
isMobile &&
(disabledMap[graphEndpoint] || (!disabledMap[graphEndpoint] && selectedGraphEndpoint === graphEndpoint))
) {
setShowTooltip(graphEndpoint, true)
setShowMobileTooltip(graphEndpoint, true)

return
}
Expand Down
10 changes: 5 additions & 5 deletions src/app/pages/HomePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const HomePageCmp: FC = () => {
const apiStatusQuery = useGetStatus()
const {
state: { showMobileTooltip },
setShowTooltip,
setShowMobileTooltip,
} = useMobileTooltip()
const isApiOffline = apiStatusQuery.isFetched && !apiStatusQuery.isSuccess

Expand Down Expand Up @@ -152,16 +152,16 @@ const HomePageCmp: FC = () => {
</FooterStyled>
</HomepageLayout>
{showMobileTooltip.consensus && (
<ConsensusGraphMobileTooltip onClose={() => setShowTooltip(GraphEndpoint.Consensus, false)} />
<ConsensusGraphMobileTooltip onClose={() => setShowMobileTooltip(GraphEndpoint.Consensus, false)} />
)}
{showMobileTooltip.emerald && (
<EmeraldGraphMobileTooltip onClose={() => setShowTooltip(GraphEndpoint.Emerald, false)} />
<EmeraldGraphMobileTooltip onClose={() => setShowMobileTooltip(GraphEndpoint.Emerald, false)} />
)}
{showMobileTooltip.sapphire && (
<SapphireGraphMobileTooltip onClose={() => setShowTooltip(GraphEndpoint.Sapphire, false)} />
<SapphireGraphMobileTooltip onClose={() => setShowMobileTooltip(GraphEndpoint.Sapphire, false)} />
)}
{showMobileTooltip.cipher && (
<CipherGraphMobileTooltip onClose={() => setShowTooltip(GraphEndpoint.Cipher, false)} />
<CipherGraphMobileTooltip onClose={() => setShowMobileTooltip(GraphEndpoint.Cipher, false)} />
)}
</>
)
Expand Down
6 changes: 3 additions & 3 deletions src/app/pages/HomePage/providers/MobileTooltipProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface MobileTooltipProviderState {

interface MobileTooltipProviderContext {
readonly state: MobileTooltipProviderState
setShowTooltip: (graphEndpoint: GraphEndpoint, show: boolean) => void
setShowMobileTooltip: (graphEndpoint: GraphEndpoint, show: boolean) => void
}

const mobileTooltipProviderInitialState: MobileTooltipProviderState = {
Expand All @@ -28,7 +28,7 @@ export const MobileTooltipProvider: FC<PropsWithChildren> = ({ children }) => {
...mobileTooltipProviderInitialState,
})

const setShowTooltip = (graphEndpoint: GraphEndpoint, show: boolean) => {
const setShowMobileTooltip = (graphEndpoint: GraphEndpoint, show: boolean) => {
setState(prevState => ({
...prevState,
showMobileTooltip: {
Expand All @@ -40,7 +40,7 @@ export const MobileTooltipProvider: FC<PropsWithChildren> = ({ children }) => {

const providerState: MobileTooltipProviderContext = {
state,
setShowTooltip,
setShowMobileTooltip,
}

return <MobileTooltipContext.Provider value={providerState}>{children}</MobileTooltipContext.Provider>
Expand Down

0 comments on commit 4e042e0

Please sign in to comment.