From 720568fb952d3a642ecbbf6bf75dc034a818ae36 Mon Sep 17 00:00:00 2001 From: Guy Korland Date: Sat, 20 Jan 2024 21:32:51 +0200 Subject: [PATCH 1/2] fix #10 add switch dark/light mode --- app/page.tsx | 8 +++--- app/providers.tsx | 18 ++++++++------ components/custom/navbar.tsx | 39 ++++++++++++++++++++++++++---- components/ui/switch.tsx | 29 ++++++++++++++++++++++ package-lock.json | 47 ++++++++++++++++++++++++++++++++++++ package.json | 1 + 6 files changed, 124 insertions(+), 18 deletions(-) create mode 100644 components/ui/switch.tsx diff --git a/app/page.tsx b/app/page.tsx index 7c52c0a..31cac53 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -18,13 +18,11 @@ export default function Home() { return (
-
+

- Welcome to{' '} - signIn("Credentials", { callbackUrl: '/graph' })} href="/"> - FalkorDB Browser - + Welcome to FalkorDB Browser

+
) diff --git a/app/providers.tsx b/app/providers.tsx index 4ef6807..b702f77 100644 --- a/app/providers.tsx +++ b/app/providers.tsx @@ -3,7 +3,7 @@ import Navbar from "@/components/custom/navbar"; import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "@/components/ui/resizable"; import { SessionProvider } from "next-auth/react"; -// import Navigation from "./components/navigation"; +import { ThemeProvider } from 'next-themes' type Props = { children?: React.ReactNode; @@ -12,13 +12,15 @@ type Props = { export const NextAuthProvider = ({ children }: Props) => { return ( - - - - - - {children} - + + + + + + + {children} + + ) }; \ No newline at end of file diff --git a/components/custom/navbar.tsx b/components/custom/navbar.tsx index fe5ef4c..fa4ddaf 100644 --- a/components/custom/navbar.tsx +++ b/components/custom/navbar.tsx @@ -1,14 +1,43 @@ import { LogOut, Menu } from "lucide-react"; import { signOut, useSession } from "next-auth/react"; import Link from "next/link"; +import { Switch } from "../ui/switch"; +import { Label } from "../ui/label"; +import { useEffect, useState } from "react"; +import { useTheme } from "next-themes"; export default function Navbar() { const { data: session, status } = useSession() + const { theme, setTheme, systemTheme} = useTheme() + + const [mounted, setMounted] = useState(false) + + useEffect(() => { + setMounted(true) + }, []) + + function setDarkMode(val: boolean) { + if (val) { + setTheme("dark") + } + else { + setTheme("light") + } + } + + let darkmode = theme=="dark" || (theme=="system" && systemTheme=="dark") return ( -