From 5ab6c3304b4a2d055767b8195fac9c9eec776d16 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Tue, 9 Apr 2024 16:32:41 +0100 Subject: fix(web): Fix the toggle theme button allowing clicks from anywhere in the dropdown item --- .../components/dashboard/sidebar/SidebarProfileOptions.tsx | 14 ++++++++------ apps/web/components/theme-provider.tsx | 11 ++++++++++- 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'apps') diff --git a/apps/web/components/dashboard/sidebar/SidebarProfileOptions.tsx b/apps/web/components/dashboard/sidebar/SidebarProfileOptions.tsx index bf56b805..3fe4d52f 100644 --- a/apps/web/components/dashboard/sidebar/SidebarProfileOptions.tsx +++ b/apps/web/components/dashboard/sidebar/SidebarProfileOptions.tsx @@ -1,5 +1,6 @@ "use client"; +import { useToggleTheme } from "@/components/theme-provider"; import { Button } from "@/components/ui/button"; import { DropdownMenu, @@ -13,28 +14,29 @@ import { signOut } from "next-auth/react"; import { useTheme } from "next-themes"; function DarkModeToggle() { - const { theme, setTheme } = useTheme(); + const { theme } = useTheme(); let comp; if (theme == "dark") { comp = ( - + ); } else { comp = ( - + ); } return {comp}; } export default function SidebarProfileOptions() { + const toggleTheme = useToggleTheme(); return ( @@ -43,7 +45,7 @@ export default function SidebarProfileOptions() { - + {children}; } + +export function useToggleTheme() { + const { theme, setTheme } = useTheme(); + if (theme == "dark") { + return () => setTheme("light"); + } else { + return () => setTheme("dark"); + } +} -- cgit v1.2.3-70-g09d2