From 2c061a6f8e4b5c086d5281fae17bab83219d1f90 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Mon, 13 Oct 2025 14:01:05 +0200 Subject: [PATCH] Better settings ui --- src/app/settings/page.tsx | 71 ------------------- src/components/Sidebar.tsx | 15 ++-- .../settings/SettingSchema.tsx} | 4 +- src/components/settings/Settings.tsx | 66 +++++++++++++++++ src/components/settings/SettingsDialog.tsx | 53 ++++++++++++++ src/types/settings.ts | 5 +- 6 files changed, 131 insertions(+), 83 deletions(-) delete mode 100644 src/app/settings/page.tsx rename src/{app/settings/settings.tsx => components/settings/SettingSchema.tsx} (97%) create mode 100644 src/components/settings/Settings.tsx create mode 100644 src/components/settings/SettingsDialog.tsx diff --git a/src/app/settings/page.tsx b/src/app/settings/page.tsx deleted file mode 100644 index ad8883f..0000000 --- a/src/app/settings/page.tsx +++ /dev/null @@ -1,71 +0,0 @@ -"use client"; - -import { useProfileSettings, useClientSettings } from "@/hooks/use-settings"; -import { setClientSettings } from "@/lib/clientSettings"; -import Settings from "./settings"; -import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; -import { Card } from "@/components/ui/card"; -import { CardContent } from "@/components/ui/card"; -import { PROFILE_SCHEMA, CLIENT_SCHEMA } from "@/types/settings"; -import { useParams, useRouter, useSearchParams } from "next/navigation"; -import { Button } from "@/components/ui/button"; -import { ChevronLeftCircle } from "lucide-react"; -import axios from "axios"; -import { useEffect } from "react"; - -export default function SettingsPage() { - const [settings, setSettings] = useClientSettings(); - const [profileSettings, setProfileSettings] = useProfileSettings(); - const router = useRouter(); - const params = useSearchParams(); - - return ( -
- - - - Client Settings - Profile Settings - - - - - { - setClientSettings(settings); - router.refresh(); - }} - /> - - - - - - - { - await axios.post("/api/profile", profileSettings); - }} - /> - - - - -
- ); -} diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index 53ad5ed..7bd011c 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -33,6 +33,7 @@ import ProfilePicture from "./ProfilePicture"; import auth, { makeAddress } from "@/lib/auth"; import { toast } from "sonner"; import { StringMap } from "@/types/typeUtils"; +import SettingsDialog from "./settings/SettingsDialog"; export default function AppSidebar({ children, @@ -195,9 +196,7 @@ export default function AppSidebar({ @@ -271,12 +270,10 @@ function DMItem({ {status} {settings && ( - + )} ); diff --git a/src/app/settings/settings.tsx b/src/components/settings/SettingSchema.tsx similarity index 97% rename from src/app/settings/settings.tsx rename to src/components/settings/SettingSchema.tsx index ddbde59..840c1dc 100644 --- a/src/app/settings/settings.tsx +++ b/src/components/settings/SettingSchema.tsx @@ -25,7 +25,7 @@ export type SettingsSchema = StringMap< "boolean" | "string" | "number" | string[] | RegexSetting >; -export default function Settings({ +export default function SettingSchema({ settings, setSettings, schema, @@ -73,7 +73,7 @@ export default function Settings({ value={(settings as any)[key] || []} onValueChange={(val) => handleChange(key, val)} > - + diff --git a/src/components/settings/Settings.tsx b/src/components/settings/Settings.tsx new file mode 100644 index 0000000..6842abf --- /dev/null +++ b/src/components/settings/Settings.tsx @@ -0,0 +1,66 @@ +"use client"; + +import { useClientSettings } from "@/hooks/use-settings"; +import { setClientSettings } from "@/lib/clientSettings"; +import SettingSchema from "./SettingSchema"; +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; +import { Card } from "@/components/ui/card"; +import { CardContent } from "@/components/ui/card"; +import { + PROFILE_SCHEMA, + CLIENT_SCHEMA, + ProfileSettings, +} from "@/types/settings"; +import { useParams, useRouter, useSearchParams } from "next/navigation"; +import axios from "axios"; + +export default function Settings({ + tab, + profileSettings, + setProfileSettings, +}: { + tab?: string; + profileSettings: ProfileSettings; + setProfileSettings: React.Dispatch>; +}) { + const [settings, setSettings] = useClientSettings(); + const router = useRouter(); + + return ( + + + Client Settings + Profile Settings + + + + + { + setClientSettings(settings); + router.refresh(); + }} + /> + + + + + + + { + await axios.post("/api/profile", profileSettings); + }} + /> + + + + + ); +} diff --git a/src/components/settings/SettingsDialog.tsx b/src/components/settings/SettingsDialog.tsx new file mode 100644 index 0000000..4d98415 --- /dev/null +++ b/src/components/settings/SettingsDialog.tsx @@ -0,0 +1,53 @@ +import { SettingsIcon } from "lucide-react"; +import { Button } from "../ui/button"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "../ui/dialog"; +import { cn } from "@/lib/utils"; +import Settings from "./Settings"; +import { ProfileSettings } from "@/types/settings"; +import { useProfileSettings } from "@/hooks/use-settings"; + +export default function SettingsDialog({ + className, + tab, +}: { + className?: string; + tab?: string; + profile?: ProfileSettings; +}) { + const [profileSettings, setProfileSettings] = useProfileSettings(); + + return ( + + + + + + + Settings + + +
+ +
+
+
+ ); +} diff --git a/src/types/settings.ts b/src/types/settings.ts index 37d4374..132b3b0 100644 --- a/src/types/settings.ts +++ b/src/types/settings.ts @@ -1,4 +1,7 @@ -import { RegexSetting, SettingsSchema } from "@/app/settings/settings"; +import { + RegexSetting, + SettingsSchema, +} from "@/components/settings/SettingSchema"; export interface ClientSettings { theme: "light" | "dark";