Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add explanatory comments to root layout.tsx #48

Open
wants to merge 1 commit into
base: overhaul
Choose a base branch
from
Open
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
127 changes: 68 additions & 59 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,60 +1,69 @@
import { Toaster } from "@/components/ui/sonner"
import { ThemeProvider } from "@/components/utility/theme-provider"
import { cn } from "@/lib/utils"
import { ClerkProvider } from "@clerk/nextjs"
import { dark } from "@clerk/themes"
import type { Metadata } from "next"
import { Inter as FontSans } from "next/font/google"
import "./globals.css"

const fontSans = FontSans({
subsets: ["latin"],
variable: "--font-sans"
})

export const metadata: Metadata = {
title: "Buildware",
description: "Build software with AI."
}

export default function RootLayout({
children
}: Readonly<{
children: React.ReactNode
}>) {
const appMode = process.env.NEXT_PUBLIC_APP_MODE

const content = (
<html lang="en" suppressHydrationWarning>
<body
className={cn(
"bg-background min-h-screen font-sans antialiased",
fontSans.variable
)}
>
<ThemeProvider
attribute="class"
defaultTheme="dark"
disableTransitionOnChange
>
{children}
<Toaster />
</ThemeProvider>
</body>
</html>
)

if (appMode === "simple") {
return content
}

return (
<ClerkProvider
appearance={{
baseTheme: dark
}}
>
{content}
</ClerkProvider>
)
}
import { ThemeProvider } from "@/components/utility/theme-provider"
import { cn } from "@/lib/utils"
import { ClerkProvider } from "@clerk/nextjs"
import { dark } from "@clerk/themes"
import type { Metadata } from "next"
import { Inter as FontSans } from "next/font/google"
import "./globals.css"

const fontSans = FontSans({
subsets: ["latin"],
variable: "--font-sans"
})

export const metadata: Metadata = {
title: "Buildware",
description: "Build software with AI."
}

/**
* RootLayout component wraps all pages and provides global styles and context.
* It conditionally includes ClerkProvider based on the app mode for authentication.
*/
export default function RootLayout({
children
}: Readonly<{
children: React.ReactNode
}>) {
const appMode = process.env.NEXT_PUBLIC_APP_MODE

// Define the main content structure with global styles and Toaster for notifications.
const content = (
<html lang="en" suppressHydrationWarning>
<body
className={cn(
"bg-background min-h-screen font-sans antialiased",
fontSans.variable
)}
>
{/* ThemeProvider manages the application's theme (dark/light) */}
<ThemeProvider
attribute="class"
defaultTheme="dark"
disableTransitionOnChange
>
{children}
{/* Toaster component displays toast notifications */}
<Toaster />
</ThemeProvider>
</body>
</html>
)

// If the app mode is "simple", render content without ClerkProvider.
if (appMode === "simple") {
return content
}

// In "advanced" mode, wrap content with ClerkProvider for user authentication.
return (
<ClerkProvider
appearance={{
baseTheme: dark
}}
>
{content}
</ClerkProvider>
)
}