Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Added Loading.tsx component and integrated Suspense #65

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/components/Loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

import React from 'react';

const Loading = () => {
return (
<div className="flex items-center justify-center h-screen">
<div className="animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-base-darkest"></div>
</div>
);
};
export default Loading;

41 changes: 29 additions & 12 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import App, { AppProps, AppContext, AppInitialProps } from 'next/app';
import React, { useEffect, useMemo, useRef } from 'react';
import React, { useState,useEffect, useMemo, useRef ,Suspense} from 'react';
import { MantineProvider } from '@mantine/core';
import { Faro, FaroErrorBoundary, withFaroProfiler } from '@grafana/faro-react';
import { initGrafanaFaro } from '../lib/Grafana/grafana';


import {
Gen3Provider,
TenStringArray,
Expand All @@ -29,6 +30,7 @@ import '@fontsource/poppins';
import { setDRSHostnames } from '@gen3/core';
import drsHostnames from '../../config/drsHostnames.json';
import { loadContent } from '@/lib/content/loadContent';
import Loading from '../components/Loading';

if (typeof window !== 'undefined' && process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
Expand Down Expand Up @@ -78,26 +80,41 @@ const Gen3App = ({
// }
}, []);


const theme = useMemo(
() => createMantineTheme(themeFonts, colors),
[themeFonts, colors],
);
const [isClient, setIsClient] = useState(false);

useEffect(() => {
setIsClient(true); // Only on client-side
}, []);
return (
<FaroErrorBoundary>
<MantineProvider theme={theme}>
<Gen3Provider
icons={icons}
sessionConfig={sessionConfig}
modalsConfig={modalsConfig}
>
<Component {...pageProps} />
</Gen3Provider>
</MantineProvider>
</FaroErrorBoundary>
<>
{isClient ? (
<Suspense fallback={<Loading />}>
<FaroErrorBoundary>
<MantineProvider theme={theme}>
<Gen3Provider
icons={icons}
sessionConfig={sessionConfig}
modalsConfig={modalsConfig}
>
<Component {...pageProps} />
</Gen3Provider>
</MantineProvider>
</FaroErrorBoundary>
</Suspense>
) : (
// Show some fallback UI while waiting for the client to load
<Loading />
)}
</>
);
};


// TODO: replace with page router
Gen3App.getInitialProps = async (
context: AppContext,
Expand Down