Skip to content

Commit

Permalink
Add loading component with suspense on initial layout
Browse files Browse the repository at this point in the history
  • Loading branch information
alvinsjoy committed Nov 17, 2024
1 parent a53caac commit fabc5ca
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
24 changes: 14 additions & 10 deletions app/(root)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Suspense } from 'react';
import { ClerkProvider } from '@clerk/nextjs';
import { Inter } from 'next/font/google';
import { Metadata } from 'next';
Expand All @@ -10,6 +11,7 @@ import LeftSidebar from '@/components/shared/LeftSidebar';
import Bottombar from '@/components/shared/Bottombar';
import RightSidebar from '@/components/shared/RightSidebar';
import Topbar from '@/components/shared/Topbar';
import Loading from '@/components/shared/Loading';

export const metadata: Metadata = {
title: {
Expand All @@ -33,16 +35,18 @@ export default function RootLayout({
>
<html lang="en">
<body className={inter.className}>
<Topbar />
<main className="flex flex-row">
<LeftSidebar />
<section className="main-container">
<div className="w-full max-w-4xl">{children}</div>
</section>
<RightSidebar />
</main>
<Bottombar />
<Toaster />
<Suspense fallback={<Loading />}>
<Topbar />
<main className="flex flex-row">
<LeftSidebar />
<section className="main-container">
<div className="w-full max-w-4xl">{children}</div>
</section>
<RightSidebar />
</main>
<Bottombar />
<Toaster />
</Suspense>
<script
defer
src="https://cloud.umami.is/script.js"
Expand Down
12 changes: 12 additions & 0 deletions components/shared/Loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Image from 'next/image';

function Loading() {
return (
<div className="flex flex-col items-center justify-center h-screen bg-dark-2">
<Image src="/assets/logo.png" alt="Loading" width={80} height={80} />
<Image src="/assets/loading.svg" alt="Loading" width={80} height={80} />
</div>
);
}

export default Loading;
1 change: 1 addition & 0 deletions public/assets/loading.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fabc5ca

Please sign in to comment.