From 3a8d197437868ca10d294f0174afa013f138ec33 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Sat, 5 Oct 2024 16:35:47 +0000 Subject: feature(web): Change the settings page to be tabbed --- apps/web/app/dashboard/settings/ai/page.tsx | 325 ---------------------------- apps/web/app/dashboard/settings/page.tsx | 70 ++++-- 2 files changed, 49 insertions(+), 346 deletions(-) delete mode 100644 apps/web/app/dashboard/settings/ai/page.tsx (limited to 'apps/web/app') diff --git a/apps/web/app/dashboard/settings/ai/page.tsx b/apps/web/app/dashboard/settings/ai/page.tsx deleted file mode 100644 index 009919a0..00000000 --- a/apps/web/app/dashboard/settings/ai/page.tsx +++ /dev/null @@ -1,325 +0,0 @@ -"use client"; - -import { ActionButton } from "@/components/ui/action-button"; -import { - Form, - FormControl, - FormField, - FormItem, - FormMessage, -} from "@/components/ui/form"; -import { FullPageSpinner } from "@/components/ui/full-page-spinner"; -import { Input } from "@/components/ui/input"; -import { - Select, - SelectContent, - SelectGroup, - SelectItem, - SelectTrigger, - SelectValue, -} from "@/components/ui/select"; -import { toast } from "@/components/ui/use-toast"; -import { useClientConfig } from "@/lib/clientConfig"; -import { api } from "@/lib/trpc"; -import { zodResolver } from "@hookform/resolvers/zod"; -import { Plus, Save, Trash2 } from "lucide-react"; -import { useForm } from "react-hook-form"; -import { z } from "zod"; - -import { buildImagePrompt, buildTextPrompt } from "@hoarder/shared/prompts"; -import { - zNewPromptSchema, - ZPrompt, - zUpdatePromptSchema, -} from "@hoarder/shared/types/prompts"; - -export function PromptEditor() { - const apiUtils = api.useUtils(); - - const form = useForm>({ - resolver: zodResolver(zNewPromptSchema), - defaultValues: { - text: "", - appliesTo: "all", - }, - }); - - const { mutateAsync: createPrompt, isPending: isCreating } = - api.prompts.create.useMutation({ - onSuccess: () => { - toast({ - description: "Prompt has been created!", - }); - apiUtils.prompts.list.invalidate(); - }, - }); - - return ( -
- { - await createPrompt(value); - form.resetField("text"); - })} - > - { - return ( - - - - - - - ); - }} - /> - - { - return ( - - - - - - - ); - }} - /> - - - Add - - - - ); -} - -export function PromptRow({ prompt }: { prompt: ZPrompt }) { - const apiUtils = api.useUtils(); - const { mutateAsync: updatePrompt, isPending: isUpdating } = - api.prompts.update.useMutation({ - onSuccess: () => { - toast({ - description: "Prompt has been updated!", - }); - apiUtils.prompts.list.invalidate(); - }, - }); - const { mutate: deletePrompt, isPending: isDeleting } = - api.prompts.delete.useMutation({ - onSuccess: () => { - toast({ - description: "Prompt has been deleted!", - }); - apiUtils.prompts.list.invalidate(); - }, - }); - - const form = useForm>({ - resolver: zodResolver(zUpdatePromptSchema), - defaultValues: { - promptId: prompt.id, - text: prompt.text, - appliesTo: prompt.appliesTo, - }, - }); - - return ( -
- { - await updatePrompt(value); - })} - > - { - return ( - - - - - - - ); - }} - /> - { - return ( - - - - - - - ); - }} - /> - - { - return ( - - - - - - - ); - }} - /> - - - Save - - deletePrompt({ promptId: prompt.id })} - className="items-center" - type="button" - > - - Delete - - - - ); -} - -export function TaggingRules() { - const { data: prompts, isLoading } = api.prompts.list.useQuery(); - - return ( -
-
Tagging Rules
-

- Prompts that you add here will be included as rules to the model during - tag generation. You can view the final prompts in the prompt preview - section. -

- {isLoading && } - {prompts && prompts.length == 0 && ( -

- You don't have any custom prompts yet. -

- )} - {prompts && - prompts.map((prompt) => )} - -
- ); -} - -export function PromptDemo() { - const { data: prompts } = api.prompts.list.useQuery(); - const clientConfig = useClientConfig(); - return ( -
-
- Prompt Preview -
-

Text Prompt

- - {buildTextPrompt( - clientConfig.inference.inferredTagLang, - (prompts ?? []) - .filter((p) => p.appliesTo == "text" || p.appliesTo == "all") - .map((p) => p.text), - "\n\n", - ).trim()} - -

Image Prompt

- - {buildImagePrompt( - clientConfig.inference.inferredTagLang, - (prompts ?? []) - .filter((p) => p.appliesTo == "images" || p.appliesTo == "all") - .map((p) => p.text), - ).trim()} - -
- ); -} - -export default function PromptsPage() { - return ( - <> -
-
-
- AI Settings -
- -
-
-
- -
- - ); -} diff --git a/apps/web/app/dashboard/settings/page.tsx b/apps/web/app/dashboard/settings/page.tsx index 97048657..c116fb86 100644 --- a/apps/web/app/dashboard/settings/page.tsx +++ b/apps/web/app/dashboard/settings/page.tsx @@ -1,32 +1,60 @@ -import Link from "next/link"; +import AISettings from "@/components/dashboard/settings/AISettings"; import ApiKeySettings from "@/components/dashboard/settings/ApiKeySettings"; import { ChangePassword } from "@/components/dashboard/settings/ChangePassword"; import ImportExport from "@/components/dashboard/settings/ImportExport"; import UserDetails from "@/components/dashboard/settings/UserDetails"; -import { ExternalLink } from "lucide-react"; +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; +import { Download, KeyRound, Sparkle, User } from "lucide-react"; export default async function Settings() { return ( - <> -
- - -
-
- + + + + + User Info + + + AI Settings - - -
-
- -
-
- + + + + Import / Export + + + + API Keys + + +
+ +
+ + +
+
+ + + + +
+ +
+
+ +
+ +
+
- + ); } -- cgit v1.2.3-70-g09d2