From b52e505327228a96967e6b921984c5ee6c0cbbd2 Mon Sep 17 00:00:00 2001 From: "Visal .In" Date: Thu, 22 Aug 2024 23:30:42 +0700 Subject: [PATCH] feat: add theme and disable theme toggle option (#151) * feat: add theme and disable theme toggle option * feat(embed): override theme variables (#152) --------- Co-authored-by: Georges KABBOUCHI --- src/app/(theme)/client/layout.tsx | 4 +- src/app/(theme)/connect/page.tsx | 7 ++- src/app/(theme)/embed/sqlite/page-client.tsx | 22 ++++++++++ src/app/(theme)/embed/sqlite/page.tsx | 46 +++++++++++++------- src/app/(theme)/layout.tsx | 30 ------------- src/app/(theme)/playground/client/page.tsx | 7 ++- src/app/(theme)/theme_layout.tsx | 42 ++++++++++++++++++ src/components/gui/connection-dialog.tsx | 4 +- src/components/gui/sidebar-tab.tsx | 40 +++++++++-------- src/components/gui/studio.tsx | 4 -- src/components/my-studio.tsx | 4 -- src/context/theme-provider.tsx | 29 +++++++++--- 12 files changed, 152 insertions(+), 87 deletions(-) create mode 100644 src/app/(theme)/embed/sqlite/page-client.tsx delete mode 100644 src/app/(theme)/layout.tsx create mode 100644 src/app/(theme)/theme_layout.tsx diff --git a/src/app/(theme)/client/layout.tsx b/src/app/(theme)/client/layout.tsx index 63a1aac0..ca668d44 100644 --- a/src/app/(theme)/client/layout.tsx +++ b/src/app/(theme)/client/layout.tsx @@ -1,9 +1,9 @@ -import { Fragment } from "react"; +import ThemeLayout from "../theme_layout"; export default async function RootLayout({ children, }: { children: React.ReactNode; }) { - return {children}; + return {children}; } diff --git a/src/app/(theme)/connect/page.tsx b/src/app/(theme)/connect/page.tsx index ad89ef0f..c02987af 100644 --- a/src/app/(theme)/connect/page.tsx +++ b/src/app/(theme)/connect/page.tsx @@ -1,6 +1,7 @@ import { Metadata } from "next"; import { getSessionFromCookie } from "@/lib/auth"; import ConnectBody from "./page-client"; +import ThemeLayout from "../theme_layout"; export const metadata: Metadata = { title: "LibSQL Studio", @@ -10,5 +11,9 @@ export const metadata: Metadata = { export default async function Home() { const { user } = await getSessionFromCookie(); - return ; + return ( + + + + ); } diff --git a/src/app/(theme)/embed/sqlite/page-client.tsx b/src/app/(theme)/embed/sqlite/page-client.tsx new file mode 100644 index 00000000..db8cc506 --- /dev/null +++ b/src/app/(theme)/embed/sqlite/page-client.tsx @@ -0,0 +1,22 @@ +"use client"; +import { Studio } from "@/components/gui/studio"; +import IframeDriver from "@/drivers/iframe-driver"; +import { useSearchParams } from "next/navigation"; +import { useEffect, useMemo } from "react"; + +export default function EmbedPageClient() { + const searchParams = useSearchParams(); + const driver = useMemo(() => new IframeDriver(), []); + + useEffect(() => { + return driver.listen(); + }, [driver]); + + return ( + + ); +} diff --git a/src/app/(theme)/embed/sqlite/page.tsx b/src/app/(theme)/embed/sqlite/page.tsx index 225e87a1..abe190a1 100644 --- a/src/app/(theme)/embed/sqlite/page.tsx +++ b/src/app/(theme)/embed/sqlite/page.tsx @@ -1,23 +1,37 @@ -"use client"; +import ThemeLayout from "../../theme_layout"; +import EmbedPageClient from "./page-client"; -import MyStudio from "@/components/my-studio"; -import IframeDriver from "@/drivers/iframe-driver"; -import { useSearchParams } from "next/navigation"; -import { useEffect, useMemo } from "react"; +export default async function EmbedPage(props: { + searchParams: { + theme?: string; + disableThemeToggle?: string; + [key: string]: any; + }; +}) { + let overrideTheme: "dark" | "light" | undefined = undefined; + const disableToggle = props.searchParams.disableThemeToggle === "1"; -export default function EmbedPageClient() { - const searchParams = useSearchParams(); - const driver = useMemo(() => new IframeDriver(), []); + if (props.searchParams.theme) { + overrideTheme = props.searchParams.theme === "dark" ? "dark" : "light"; + } - useEffect(() => { - return driver.listen(); - }, [driver]); + const overrideThemeVariables: Record = {}; + + for (const key in props.searchParams) { + if (!key.startsWith("themeVariables[")) { + continue; + } + + overrideThemeVariables[key.slice(15, -1)] = props.searchParams[key]; + } return ( - + + + ); } diff --git a/src/app/(theme)/layout.tsx b/src/app/(theme)/layout.tsx deleted file mode 100644 index 33a13bb1..00000000 --- a/src/app/(theme)/layout.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import { Analytics } from "@vercel/analytics/react"; -import { Inter } from "next/font/google"; -import ThemeProvider from "@/context/theme-provider"; -import { cookies } from "next/headers"; -import { Toaster } from "@/components/ui/sonner"; -import { Fragment } from "react"; -import Script from "next/script"; -import { cn } from "@/lib/utils"; - -const inter = Inter({ subsets: ["latin"] }); - -export default async function RootLayout({ - children, -}: { - children: React.ReactNode; -}) { - const cookieStore = cookies(); - const theme = cookieStore.get("theme")?.value === "dark" ? "dark" : "light"; - - return ( - - - {children} - - - -