From 4ffddccfde68aa889cb21ec8141f56ec6fb7eade Mon Sep 17 00:00:00 2001 From: SarthakDev12 Date: Fri, 26 Jul 2024 12:18:13 +0530 Subject: [PATCH] make recommended changes --- frontend/components/Loading.tsx | 9 ------ frontend/pages/_app.tsx | 43 ++++--------------------- frontend/pages/_document.tsx | 57 --------------------------------- 3 files changed, 7 insertions(+), 102 deletions(-) delete mode 100644 frontend/components/Loading.tsx delete mode 100644 frontend/pages/_document.tsx diff --git a/frontend/components/Loading.tsx b/frontend/components/Loading.tsx deleted file mode 100644 index aa3570888..000000000 --- a/frontend/components/Loading.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import styled from 'styled-components'; - -const LoadingWrapper = styled.div` - background-color: #0000; -`; - -const Loading = () => ; - -export default Loading; diff --git a/frontend/pages/_app.tsx b/frontend/pages/_app.tsx index 2d4394736..68727cf8c 100644 --- a/frontend/pages/_app.tsx +++ b/frontend/pages/_app.tsx @@ -2,10 +2,9 @@ import '../styles/globals.scss'; import { ConfigProvider } from 'antd'; import type { AppProps } from 'next/app'; -import { useEffect, useRef, useState } from 'react'; +import { useEffect, useState } from 'react'; import { Layout } from '@/components/Layout'; -import Loading from '@/components/Loading'; import { BalanceProvider } from '@/context/BalanceProvider'; import { ElectronApiProvider } from '@/context/ElectronApiProvider'; import { MasterSafeProvider } from '@/context/MasterSafeProvider'; @@ -21,39 +20,11 @@ import { WalletProvider } from '@/context/WalletProvider'; import { mainTheme } from '@/theme'; export default function App({ Component, pageProps }: AppProps) { - const isMounted = useRef(false); - const [isLoaded, setIsLoaded] = useState(false); - const [loadingTimeReached, setLoadingTimeReached] = useState(false); - + const [isMounted, setIsMounted] = useState(false); useEffect(() => { - isMounted.current = true; - - const handleLoad = () => { - setIsLoaded(true); - }; - const checkStylesLoaded = () => { - const styles = document.querySelectorAll('link[rel="stylesheet"]'); - if (styles.length > 0) { - handleLoad(); - } - }; - - const timer = setTimeout(() => { - setLoadingTimeReached(true); - }, 1000); - - checkStylesLoaded(); - window.addEventListener('load', checkStylesLoaded); - return () => { - isMounted.current = false; - clearTimeout(timer); - window.removeEventListener('load', checkStylesLoaded); - }; + setIsMounted(true); }, []); - if (!loadingTimeReached || !isLoaded) { - return ; - } return ( @@ -67,13 +38,13 @@ export default function App({ Component, pageProps }: AppProps) { - {isMounted ? ( - + + {isMounted ? ( - - ) : null} + ) : null} + diff --git a/frontend/pages/_document.tsx b/frontend/pages/_document.tsx deleted file mode 100644 index 722104270..000000000 --- a/frontend/pages/_document.tsx +++ /dev/null @@ -1,57 +0,0 @@ -// _document.tsx -import Document, { - DocumentContext, - DocumentInitialProps, - Head, - Html, - Main, - NextScript, -} from 'next/document'; -import { ServerStyleSheet } from 'styled-components'; - -class MyDocument extends Document { - static async getInitialProps( - ctx: DocumentContext, - ): Promise { - const sheet = new ServerStyleSheet(); - const originalRenderPage = ctx.renderPage; - - try { - ctx.renderPage = () => - originalRenderPage({ - enhanceApp: (App) => (props) => - sheet.collectStyles(), - }); - - const initialProps = await Document.getInitialProps(ctx); - return { - ...initialProps, - styles: ( - <> - {initialProps.styles} - {sheet.getStyleElement()} - - ), - }; - } finally { - sheet.seal(); - } - } - - render() { - return ( - - - - - - -
- - - - ); - } -} - -export default MyDocument;