import React, { useCallback } from 'react'; import cn from 'classnames'; import { Flex } from 'indigo-react'; import Footer from './Footer'; import useBreakpoints from 'lib/useBreakpoints'; import MiniBackButton from './MiniBackButton'; import { useHistory } from 'store/history'; import NavHeader from './NavHeader'; const EXPECT_LOGOUT_WHEN_POPPING_AT_DEPTH = 2; // View is a top-level component that all Views must render to inherit styling function View({ className, children, inset = false, full = false, pop, ...rest }) { const { size } = useHistory(); const isMobile = useBreakpoints([true, false, false]); const shouldInset = inset && !isMobile; const insetPadding = cn({ pt7: shouldInset, pt5: !shouldInset, }); const goBack = useCallback(() => pop(), [pop]); const goLogout = useCallback(() => pop(size - 1), [pop, size]); const showBackButton = size > 1 && !!pop; const backIsLogout = size === EXPECT_LOGOUT_WHEN_POPPING_AT_DEPTH; const Header = useCallback( ({ logout }) => { return showBackButton ? ( Logout ) : ( ); }, [goLogout, insetPadding, showBackButton] ); return ( {showBackButton && !backIsLogout && ( )}
{children} ); } // View.Full is sugar for to help with readability View.Full = function FullView(props) { return ; }; export default View;