Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
isstuev committed Oct 5, 2024
1 parent 7593807 commit 361ccad
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 121 deletions.
54 changes: 8 additions & 46 deletions nextjs/PageNextJs.tsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,19 @@
import Head from 'next/head';
/* eslint-disable @typescript-eslint/no-explicit-any */
import React from 'react';

import type { Route } from 'nextjs-routes';
import type { Props as PageProps } from 'nextjs/getServerSideProps';

import config from 'configs/app';
import useAdblockDetect from 'lib/hooks/useAdblockDetect';
import useGetCsrfToken from 'lib/hooks/useGetCsrfToken';
import * as metadata from 'lib/metadata';
import * as mixpanel from 'lib/mixpanel';
import { init as initSentry } from 'lib/sentry/config';

interface Props<Pathname extends Route['pathname']> {
pathname: Pathname;
interface Props {
children: React.ReactNode;
query?: PageProps<Pathname>['query'];
apiData?: PageProps<Pathname>['apiData'];
pathname?: any;
query?: any;
apiData?: any;
}

initSentry();

const PageNextJs = <Pathname extends Route['pathname']>(props: Props<Pathname>) => {
const { title, description, opengraph, canonical } = metadata.generate(props, props.apiData);

useGetCsrfToken();
useAdblockDetect();

const isMixpanelInited = mixpanel.useInit();
mixpanel.useLogPageView(isMixpanelInited);

return (
<>
<Head>
<title>{ title }</title>
<meta name="description" content={ description }/>
{ canonical && <link rel="canonical" href={ canonical }/> }

{ /* OG TAGS */ }
<meta property="og:title" content={ opengraph.title }/>
{ opengraph.description && <meta property="og:description" content={ opengraph.description }/> }
<meta property="og:image" content={ opengraph.imageUrl }/>
<meta property="og:type" content="website"/>

{ /* Twitter Meta Tags */ }
<meta name="twitter:card" content="summary_large_image"/>
<meta property="twitter:domain" content={ config.app.host }/>
<meta name="twitter:title" content={ opengraph.title }/>
{ opengraph.description && <meta name="twitter:description" content={ opengraph.description }/> }
<meta property="twitter:image" content={ opengraph.imageUrl }/>
</Head>
{ props.children }
</>
);
};
const PageNextJs = (props: Props) => (
<div>{ props.children }</div>
);

export default React.memo(PageNextJs);
71 changes: 1 addition & 70 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,87 +1,18 @@
import { type ChakraProps } from '@chakra-ui/react';
import { GrowthBookProvider } from '@growthbook/growthbook-react';
import * as Sentry from '@sentry/react';
import { QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import type { AppProps } from 'next/app';
import React from 'react';

import type { NextPageWithLayout } from 'nextjs/types';

import config from 'configs/app';
import useQueryClientConfig from 'lib/api/useQueryClientConfig';
import { AppContextProvider } from 'lib/contexts/app';
import { ChakraProvider } from 'lib/contexts/chakra';
import { MarketplaceContextProvider } from 'lib/contexts/marketplace';
import { ScrollDirectionProvider } from 'lib/contexts/scrollDirection';
import { growthBook } from 'lib/growthbook/init';
import useLoadFeatures from 'lib/growthbook/useLoadFeatures';
import useNotifyOnNavigation from 'lib/hooks/useNotifyOnNavigation';
import { SocketProvider } from 'lib/socket/context';
import AppErrorBoundary from 'ui/shared/AppError/AppErrorBoundary';
import AppErrorGlobalContainer from 'ui/shared/AppError/AppErrorGlobalContainer';
import GoogleAnalytics from 'ui/shared/GoogleAnalytics';
import Layout from 'ui/shared/layout/Layout';
import Web3ModalProvider from 'ui/shared/Web3ModalProvider';

import 'lib/setLocale';
// import 'focus-visible/dist/focus-visible';

type AppPropsWithLayout = AppProps & {
Component: NextPageWithLayout;
}

const ERROR_SCREEN_STYLES: ChakraProps = {
h: '100vh',
display: 'flex',
flexDirection: 'column',
alignItems: 'flex-start',
justifyContent: 'center',
width: 'fit-content',
maxW: '800px',
margin: { base: '0 auto', lg: '0 auto' },
p: { base: 4, lg: 0 },
};

function MyApp({ Component, pageProps }: AppPropsWithLayout) {

useLoadFeatures();
useNotifyOnNavigation();

const queryClient = useQueryClientConfig();

const handleError = React.useCallback((error: Error) => {
Sentry.captureException(error);
}, []);

const getLayout = Component.getLayout ?? ((page) => <Layout>{ page }</Layout>);

return (
<ChakraProvider cookies={ pageProps.cookies }>
<AppErrorBoundary
{ ...ERROR_SCREEN_STYLES }
onError={ handleError }
Container={ AppErrorGlobalContainer }
>
<Web3ModalProvider>
<AppContextProvider pageProps={ pageProps }>
<QueryClientProvider client={ queryClient }>
<GrowthBookProvider growthbook={ growthBook }>
<ScrollDirectionProvider>
<SocketProvider url={ `${ config.api.socket }${ config.api.basePath }/socket/v2` }>
<MarketplaceContextProvider>
{ getLayout(<Component { ...pageProps }/>) }
</MarketplaceContextProvider>
</SocketProvider>
</ScrollDirectionProvider>
</GrowthBookProvider>
<ReactQueryDevtools buttonPosition="bottom-left" position="left"/>
<GoogleAnalytics/>
</QueryClientProvider>
</AppContextProvider>
</Web3ModalProvider>
</AppErrorBoundary>
</ChakraProvider>
<Component { ...pageProps }/>
);
}

Expand Down
7 changes: 2 additions & 5 deletions pages/tx/[hash].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ import dynamic from 'next/dynamic';
import React from 'react';

import type { Props } from 'nextjs/getServerSideProps';
import PageNextJs from 'nextjs/PageNextJs';

const Transaction = dynamic(() => import('ui/pages/Transaction'), { ssr: false });

const Page: NextPage<Props> = (props: Props) => {
const Page: NextPage<Props> = () => {
return (
<PageNextJs pathname="/tx/[hash]" query={ props.query }>
<Transaction/>
</PageNextJs>
<Transaction/>
);
};

Expand Down

0 comments on commit 361ccad

Please sign in to comment.