A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
feat(web): Add System theme option (#3159)
Soumyadeep Ghoshf83d561ed8f4
diff --git a/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx b/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsxindex d4cb34ec..e8e13e90 100644--- a/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx+++ b/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx@@ -123,7 +123,7 @@ function BulkEditSelectionOverlay({ bookmark }: { bookmark: ZBookmark }) {);const isBulkEditEnabled = useBulkActionsStore((s) => s.isBulkEditEnabled);const toggleBookmark = useBulkActionsStore((state) => state.toggleBookmark);- const { theme } = useTheme();+ const { resolvedTheme } = useTheme();const { data: session } = useSession();// Don't show selector for non-owned bookmarks or when bulk edit is disabled@@ -137,7 +137,7 @@ function BulkEditSelectionOverlay({ bookmark }: { bookmark: ZBookmark }) {{"bg-opacity-10": isSelected,},- theme === "dark" ? "bg-white" : "bg-black",+ resolvedTheme === "dark" ? "bg-white" : "bg-black",)}onClick={() => toggleBookmark(bookmark.id)}></button>diff --git a/apps/web/components/dashboard/header/ProfileOptions.tsx b/apps/web/components/dashboard/header/ProfileOptions.tsxindex 64de9fbf..2f9c4812 100644--- a/apps/web/components/dashboard/header/ProfileOptions.tsx+++ b/apps/web/components/dashboard/header/ProfileOptions.tsx@@ -3,7 +3,6 @@import { useMemo } from "react";import Link from "next/link";import { redirect, useRouter } from "next/navigation";-import { useToggleTheme } from "@/components/theme-provider";import { Button } from "@/components/ui/button";import {DropdownMenu,@@ -17,9 +16,11 @@ import { useSession } from "@/lib/auth/client";import { useTranslation } from "@/lib/i18n/client";import { useInBookmarkGridStore } from "@/lib/store/useInBookmarkGridStore";import { useKeyboardNavigationStore } from "@/lib/store/useKeyboardNavigationStore";+import { cn } from "@/lib/utils";import {BookOpen,Keyboard,+ Laptop,LogOut,Moon,Paintbrush,@@ -27,6 +28,7 @@ import {Settings,Shield,Sun,+ SunMoon,Twitter,} from "lucide-react";import { useTheme } from "next-themes";@@ -35,30 +37,51 @@ import { useWhoAmI } from "@karakeep/shared-react/hooks/users";import { AdminNoticeBadge } from "../../admin/AdminNotices";-function DarkModeToggle() {+const THEME_OPTIONS = [+ { value: "light", icon: Sun, label: "options.light_mode" },+ { value: "dark", icon: Moon, label: "options.dark_mode" },+ { value: "system", icon: Laptop, label: "options.system_mode" },+] as const;++function ThemeSelector() {const { t } = useTranslation();- const { theme } = useTheme();+ const { theme, setTheme } = useTheme();- if (theme == "dark") {- return (- <>- <Sun className="size-4" />- <span>{t("options.light_mode")}</span>- </>- );- } else {- return (- <>- <Moon className="size-4" />- <span>{t("options.dark_mode")}</span>- </>- );- }+ return (+ <div className="flex items-center justify-between gap-2 px-2 py-1 text-sm">+ <div className="flex items-center gap-2">+ <SunMoon className="size-4 text-muted-foreground" />+ {t("options.theme")}+ </div>+ <div className="flex items-center gap-0.5 rounded-md bg-muted p-0.5">+ {THEME_OPTIONS.map(({ value, icon: Icon, label }) => (+ <DropdownMenuItem+ key={value}+ role="menuitemradio"+ aria-checked={theme === value}+ aria-label={t(label)}+ title={t(label)}+ // Keep the menu open so the change can be previewed+ onSelect={(e) => {+ e.preventDefault();+ setTheme(value);+ }}+ className={cn(+ "rounded px-2 py-1 focus:bg-background/60",+ theme === value &&+ "bg-background shadow-sm focus:bg-background [&_svg]:text-foreground",+ )}+ >+ <Icon className="size-3.5" />+ </DropdownMenuItem>+ ))}+ </div>+ </div>+ );}export default function SidebarProfileOptions() {const { t } = useTranslation();- const toggleTheme = useToggleTheme();const { data: session } = useSession();const { data: whoami } = useWhoAmI();const router = useRouter();@@ -128,9 +151,7 @@ export default function SidebarProfileOptions() {{t("cleanups.cleanups")}</Link></DropdownMenuItem>- <DropdownMenuItem onClick={toggleTheme}>- <DarkModeToggle />- </DropdownMenuItem>+ <ThemeSelector />{inBookmarkGrid && (<DropdownMenuItem onClick={() => setShortcutsDialogOpen(true)}><Keyboard className="size-4" />diff --git a/apps/web/components/dashboard/tags/MultiTagSelector.tsx b/apps/web/components/dashboard/tags/MultiTagSelector.tsxindex c7511eec..1083c17c 100644--- a/apps/web/components/dashboard/tags/MultiTagSelector.tsx+++ b/apps/web/components/dashboard/tags/MultiTagSelector.tsx@@ -15,18 +15,18 @@ export const MultiTagSelector = React.memo(function MultiTagSelector({count: number;}) {const toggleTag = useBulkTagActionsStore((state) => state.toggleTag);- const { theme } = useTheme();+ const { resolvedTheme } = useTheme();const isSelected = useBulkTagActionsStore((state) => state.isTagSelected(id));const getIconColor = () => {- if (theme === "dark") {+ if (resolvedTheme === "dark") {return isSelected ? "black" : "white";}return isSelected ? "white" : "black";};const getIconBackgroundColor = () => {- if (theme === "dark") {+ if (resolvedTheme === "dark") {return isSelected ? "bg-white" : "bg-white bg-opacity-10";}return isSelected ? "bg-black" : "bg-white";diff --git a/apps/web/components/theme-provider.tsx b/apps/web/components/theme-provider.tsxindex 1179bdfe..8224cff9 100644--- a/apps/web/components/theme-provider.tsx+++ b/apps/web/components/theme-provider.tsx@@ -2,7 +2,7 @@import type { ThemeProviderProps } from "next-themes";import * as React from "react";-import { ThemeProvider as NextThemesProvider, useTheme } from "next-themes";+import { ThemeProvider as NextThemesProvider } from "next-themes";export function ThemeProvider({ children, ...props }: ThemeProviderProps) {return (@@ -11,12 +11,3 @@ export function ThemeProvider({ children, ...props }: ThemeProviderProps) {</NextThemesProvider>);}--export function useToggleTheme() {- const { theme, setTheme } = useTheme();- if (theme == "dark") {- return () => setTheme("light");- } else {- return () => setTheme("dark");- }-}diff --git a/apps/web/lib/i18n/locales/en/translation.json b/apps/web/lib/i18n/locales/en/translation.jsonindex 5bd1f3b9..b9eb41b1 100644--- a/apps/web/lib/i18n/locales/en/translation.json+++ b/apps/web/lib/i18n/locales/en/translation.json@@ -784,8 +784,10 @@}},"options": {+ "theme": "Theme","dark_mode": "Dark Mode","light_mode": "Light Mode",+ "system_mode": "System Mode","apps_extensions": "Apps & Extensions","documentation": "Documentation","follow_us_on_x": "Follow us on X"