Commit 7a0ef608 authored by tom's avatar tom

custom header for home page

parent 44ef777d
...@@ -4,16 +4,21 @@ import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; ...@@ -4,16 +4,21 @@ import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import type { AppProps } from 'next/app'; import type { AppProps } from 'next/app';
import React, { useState } from 'react'; import React, { useState } from 'react';
import appConfig from 'configs/app/config';
import { AppContextProvider } from 'lib/appContext'; import { AppContextProvider } from 'lib/appContext';
import { Chakra } from 'lib/Chakra'; import { Chakra } from 'lib/Chakra';
import useConfigSentry from 'lib/hooks/useConfigSentry'; import useConfigSentry from 'lib/hooks/useConfigSentry';
import type { ErrorType } from 'lib/hooks/useFetch'; import type { ErrorType } from 'lib/hooks/useFetch';
import useScrollDirection from 'lib/hooks/useScrollDirection';
import { SocketProvider } from 'lib/socket/context';
import theme from 'theme'; import theme from 'theme';
import ScrollDirectionContext from 'ui/ScrollDirectionContext';
import AppError from 'ui/shared/AppError/AppError'; import AppError from 'ui/shared/AppError/AppError';
import ErrorBoundary from 'ui/shared/ErrorBoundary'; import ErrorBoundary from 'ui/shared/ErrorBoundary';
function MyApp({ Component, pageProps }: AppProps) { function MyApp({ Component, pageProps }: AppProps) {
useConfigSentry(); useConfigSentry();
const directionContext = useScrollDirection();
const [ queryClient ] = useState(() => new QueryClient({ const [ queryClient ] = useState(() => new QueryClient({
defaultOptions: { defaultOptions: {
...@@ -57,7 +62,11 @@ function MyApp({ Component, pageProps }: AppProps) { ...@@ -57,7 +62,11 @@ function MyApp({ Component, pageProps }: AppProps) {
<ErrorBoundary renderErrorScreen={ renderErrorScreen } onError={ handleError }> <ErrorBoundary renderErrorScreen={ renderErrorScreen } onError={ handleError }>
<AppContextProvider pageProps={ pageProps }> <AppContextProvider pageProps={ pageProps }>
<QueryClientProvider client={ queryClient }> <QueryClientProvider client={ queryClient }>
<Component { ...pageProps }/> <ScrollDirectionContext.Provider value={ directionContext }>
<SocketProvider url={ `${ appConfig.api.socket }${ appConfig.api.basePath }/socket/v2` }>
<Component { ...pageProps }/>
</SocketProvider>
</ScrollDirectionContext.Provider>
<ReactQueryDevtools/> <ReactQueryDevtools/>
</QueryClientProvider> </QueryClientProvider>
</AppContextProvider> </AppContextProvider>
......
...@@ -27,7 +27,7 @@ const LatestTransactions = () => { ...@@ -27,7 +27,7 @@ const LatestTransactions = () => {
if (isLoading) { if (isLoading) {
content = ( content = (
<> <>
<Skeleton h="56px" w="100%"/> <Skeleton h="56px" w="100%" borderBottomLeftRadius={ 0 } borderBottomRightRadius={ 0 }/>
{ Array.from(Array(txsCount)).map((item, index) => <LatestTxsItemSkeleton key={ index }/>) } { Array.from(Array(txsCount)).map((item, index) => <LatestTxsItemSkeleton key={ index }/>) }
</> </>
); );
......
...@@ -6,28 +6,42 @@ import LatestBlocks from 'ui/home/LatestBlocks'; ...@@ -6,28 +6,42 @@ import LatestBlocks from 'ui/home/LatestBlocks';
import LatestTxs from 'ui/home/LatestTxs'; import LatestTxs from 'ui/home/LatestTxs';
import Stats from 'ui/home/Stats'; import Stats from 'ui/home/Stats';
import Page from 'ui/shared/Page/Page'; import Page from 'ui/shared/Page/Page';
import ColorModeToggler from 'ui/snippets/header/ColorModeToggler';
import ProfileMenuDesktop from 'ui/snippets/profileMenu/ProfileMenuDesktop';
import SearchBar from 'ui/snippets/searchBar/SearchBar'; import SearchBar from 'ui/snippets/searchBar/SearchBar';
const Home = () => { const Home = () => {
return ( return (
<Page hasSearch={ false }> <Page isHomePage>
<Box <Box
w="100%" w="100%"
backgroundImage="radial-gradient(farthest-corner at 0 0, rgba(183, 148, 244, 0.8) 0%, rgba(0, 163, 196, 0.8) 100%)" backgroundImage="radial-gradient(farthest-corner at 0 0, rgba(183, 148, 244, 0.8) 0%, rgba(0, 163, 196, 0.8) 100%)"
borderRadius="24px" borderRadius="24px"
padding={{ base: '24px 40px', lg: '48px' }} padding={{ base: '24px', lg: '48px' }}
minW={{ base: 'unset', lg: '900px' }} minW={{ base: 'unset', lg: '900px' }}
> >
<Heading <Flex mb={{ base: 6, lg: 8 }} justifyContent="space-between">
as="h1" <Heading
size={{ base: 'lg', ld: 'xl' }} as="h1"
fontWeight={{ base: 600, lg: 500 }} size={{ base: 'md', lg: 'xl' }}
color="white" lineHeight={{ base: '32px', lg: '50px' }}
mb={{ base: 6, lg: 8 }} fontWeight={ 500 }
> color="white"
Welcome to Blockscout explorer >
</Heading> Welcome to Blockscout explorer
<LightMode><SearchBar isHomepage/></LightMode> </Heading>
<Flex
alignItems="center"
display={{ base: 'none', lg: 'flex' }}
columnGap={ 12 }
>
<ColorModeToggler trackBg="whiteAlpha.500"/>
<ProfileMenuDesktop/>
</Flex>
</Flex>
<LightMode>
<SearchBar isHomepage/>
</LightMode>
</Box> </Box>
<Stats/> <Stats/>
<ChainIndicators/> <ChainIndicators/>
......
...@@ -4,12 +4,8 @@ import React from 'react'; ...@@ -4,12 +4,8 @@ import React from 'react';
import { QueryKeys } from 'types/client/queries'; import { QueryKeys } from 'types/client/queries';
import appConfig from 'configs/app/config';
import * as cookies from 'lib/cookies'; import * as cookies from 'lib/cookies';
import useFetch from 'lib/hooks/useFetch'; import useFetch from 'lib/hooks/useFetch';
import useScrollDirection from 'lib/hooks/useScrollDirection';
import { SocketProvider } from 'lib/socket/context';
import ScrollDirectionContext from 'ui/ScrollDirectionContext';
import AppError from 'ui/shared/AppError/AppError'; import AppError from 'ui/shared/AppError/AppError';
import ErrorBoundary from 'ui/shared/ErrorBoundary'; import ErrorBoundary from 'ui/shared/ErrorBoundary';
import PageContent from 'ui/shared/Page/PageContent'; import PageContent from 'ui/shared/Page/PageContent';
...@@ -20,14 +16,14 @@ interface Props { ...@@ -20,14 +16,14 @@ interface Props {
children: React.ReactNode; children: React.ReactNode;
wrapChildren?: boolean; wrapChildren?: boolean;
hideMobileHeaderOnScrollDown?: boolean; hideMobileHeaderOnScrollDown?: boolean;
hasSearch?: boolean; isHomePage?: boolean;
} }
const Page = ({ const Page = ({
children, children,
wrapChildren = true, wrapChildren = true,
hideMobileHeaderOnScrollDown, hideMobileHeaderOnScrollDown,
hasSearch = true, isHomePage,
}: Props) => { }: Props) => {
const fetch = useFetch(); const fetch = useFetch();
...@@ -35,32 +31,26 @@ const Page = ({ ...@@ -35,32 +31,26 @@ const Page = ({
enabled: Boolean(cookies.get(cookies.NAMES.API_TOKEN)), enabled: Boolean(cookies.get(cookies.NAMES.API_TOKEN)),
}); });
const directionContext = useScrollDirection();
const renderErrorScreen = React.useCallback(() => { const renderErrorScreen = React.useCallback(() => {
return wrapChildren ? return wrapChildren ?
<PageContent hasSearch={ hasSearch }><AppError statusCode={ 500 } mt="50px"/></PageContent> : <PageContent isHomePage={ isHomePage }><AppError statusCode={ 500 } mt="50px"/></PageContent> :
<AppError statusCode={ 500 }/>; <AppError statusCode={ 500 }/>;
}, [ wrapChildren, hasSearch ]); }, [ isHomePage, wrapChildren ]);
const renderedChildren = wrapChildren ? ( const renderedChildren = wrapChildren ? (
<PageContent hasSearch={ hasSearch }>{ children }</PageContent> <PageContent isHomePage={ isHomePage }>{ children }</PageContent>
) : children; ) : children;
return ( return (
<SocketProvider url={ `${ appConfig.api.socket }${ appConfig.api.basePath }/socket/v2` }> <Flex w="100%" minH="100vh" alignItems="stretch">
<ScrollDirectionContext.Provider value={ directionContext }> <NavigationDesktop/>
<Flex w="100%" minH="100vh" alignItems="stretch"> <Flex flexDir="column" width="100%">
<NavigationDesktop/> <Header isHomePage={ isHomePage } hideOnScrollDown={ hideMobileHeaderOnScrollDown }/>
<Flex flexDir="column" width="100%"> <ErrorBoundary renderErrorScreen={ renderErrorScreen }>
<Header hasSearch={ hasSearch } hideOnScrollDown={ hideMobileHeaderOnScrollDown }/> { renderedChildren }
<ErrorBoundary renderErrorScreen={ renderErrorScreen }> </ErrorBoundary>
{ renderedChildren } </Flex>
</ErrorBoundary> </Flex>
</Flex>
</Flex>
</ScrollDirectionContext.Provider>
</SocketProvider>
); );
}; };
......
...@@ -3,17 +3,17 @@ import React from 'react'; ...@@ -3,17 +3,17 @@ import React from 'react';
interface Props { interface Props {
children: React.ReactNode; children: React.ReactNode;
hasSearch?: boolean; isHomePage?: boolean;
} }
const PageContent = ({ children, hasSearch }: Props) => { const PageContent = ({ children, isHomePage }: Props) => {
return ( return (
<Box <Box
as="main" as="main"
w="100%" w="100%"
paddingX={{ base: 4, lg: 12 }} paddingX={{ base: 4, lg: 12 }}
paddingBottom={ 10 } paddingBottom={ 10 }
paddingTop={{ base: hasSearch ? '138px' : '88px', lg: 0 }} paddingTop={{ base: isHomePage ? '88px' : '138px', lg: isHomePage ? 9 : 0 }}
> >
{ children } { children }
</Box> </Box>
......
...@@ -21,7 +21,9 @@ import getDefaultTransitionProps from 'theme/utils/getDefaultTransitionProps'; ...@@ -21,7 +21,9 @@ import getDefaultTransitionProps from 'theme/utils/getDefaultTransitionProps';
export interface ColorModeTogglerProps export interface ColorModeTogglerProps
extends Omit<UseCheckboxProps, 'isIndeterminate'>, extends Omit<UseCheckboxProps, 'isIndeterminate'>,
Omit<HTMLChakraProps<'label'>, keyof UseCheckboxProps>, Omit<HTMLChakraProps<'label'>, keyof UseCheckboxProps>,
ThemingProps<'Switch'> {} ThemingProps<'Switch'> {
trackBg?: string;
}
const ColorModeToggler = forwardRef<ColorModeTogglerProps, 'input'>((props, ref) => { const ColorModeToggler = forwardRef<ColorModeTogglerProps, 'input'>((props, ref) => {
const ownProps = omitThemingProps(props); const ownProps = omitThemingProps(props);
...@@ -39,7 +41,7 @@ const ColorModeToggler = forwardRef<ColorModeTogglerProps, 'input'>((props, ref) ...@@ -39,7 +41,7 @@ const ColorModeToggler = forwardRef<ColorModeTogglerProps, 'input'>((props, ref)
const transitionProps = getDefaultTransitionProps(); const transitionProps = getDefaultTransitionProps();
const trackStyles: SystemStyleObject = React.useMemo(() => ({ const trackStyles: SystemStyleObject = React.useMemo(() => ({
bg: trackBg, bgColor: props.trackBg || trackBg,
width: '72px', width: '72px',
height: '32px', height: '32px',
borderRadius: 'full', borderRadius: 'full',
...@@ -50,7 +52,7 @@ const ColorModeToggler = forwardRef<ColorModeTogglerProps, 'input'>((props, ref) ...@@ -50,7 +52,7 @@ const ColorModeToggler = forwardRef<ColorModeTogglerProps, 'input'>((props, ref)
cursor: 'pointer', cursor: 'pointer',
...transitionProps, ...transitionProps,
transitionDuration: 'ultra-slow', transitionDuration: 'ultra-slow',
}), [ trackBg, transitionProps ]); }), [ props.trackBg, trackBg, transitionProps ]);
const thumbStyles: SystemStyleObject = React.useMemo(() => ({ const thumbStyles: SystemStyleObject = React.useMemo(() => ({
bg: thumbBg, bg: thumbBg,
......
...@@ -11,11 +11,11 @@ import Burger from './Burger'; ...@@ -11,11 +11,11 @@ import Burger from './Burger';
import ColorModeToggler from './ColorModeToggler'; import ColorModeToggler from './ColorModeToggler';
type Props = { type Props = {
hasSearch: boolean; isHomePage?: boolean;
hideOnScrollDown?: boolean; hideOnScrollDown?: boolean;
} }
const Header = ({ hideOnScrollDown, hasSearch }: Props) => { const Header = ({ hideOnScrollDown, isHomePage }: Props) => {
const bgColor = useColorModeValue('white', 'black'); const bgColor = useColorModeValue('white', 'black');
return ( return (
...@@ -43,22 +43,27 @@ const Header = ({ hideOnScrollDown, hasSearch }: Props) => { ...@@ -43,22 +43,27 @@ const Header = ({ hideOnScrollDown, hasSearch }: Props) => {
<NetworkLogo/> <NetworkLogo/>
<ProfileMenuMobile/> <ProfileMenuMobile/>
</Flex> </Flex>
{ hasSearch && <SearchBar withShadow={ !hideOnScrollDown }/> } { !isHomePage && <SearchBar withShadow={ !hideOnScrollDown }/> }
</Box><HStack </Box>
as="header" { !isHomePage && (
width="100%" <HStack
alignItems="center" as="header"
justifyContent="center" width="100%"
gap={ 12 } alignItems="center"
display={{ base: 'none', lg: 'flex' }} justifyContent="center"
paddingX={ 12 } gap={ 12 }
paddingTop={ 9 } display={{ base: 'none', lg: 'flex' }}
paddingBottom="52px" paddingX={ 12 }
> paddingTop={ 9 }
<Box width="100%">{ hasSearch && <SearchBar/> }</Box> paddingBottom="52px"
<ColorModeToggler/> >
<ProfileMenuDesktop/> <Box width="100%">
</HStack> <SearchBar/>
</Box>
<ColorModeToggler/>
<ProfileMenuDesktop/>
</HStack>
) }
</> </>
) } ) }
</ScrollDirectionContext.Consumer> </ScrollDirectionContext.Consumer>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment