From 40dc63313857182782618f2eba82bfd94dc66bbf Mon Sep 17 00:00:00 2001 From: Louis Beaumont Date: Mon, 30 Sep 2024 09:05:57 -0700 Subject: [PATCH] fix: settings update issue --- .../components/dev-dialog.tsx | 149 ------------------ .../components/pipe-store.tsx | 2 - .../components/recording-settings.tsx | 52 +++--- .../components/screenpipe-status.tsx | 4 +- screenpipe-app-tauri/components/settings.tsx | 26 ++- screenpipe-app-tauri/src-tauri/Cargo.toml | 4 +- 6 files changed, 41 insertions(+), 196 deletions(-) delete mode 100644 screenpipe-app-tauri/components/dev-dialog.tsx diff --git a/screenpipe-app-tauri/components/dev-dialog.tsx b/screenpipe-app-tauri/components/dev-dialog.tsx deleted file mode 100644 index f818c47d9..000000000 --- a/screenpipe-app-tauri/components/dev-dialog.tsx +++ /dev/null @@ -1,149 +0,0 @@ -import React, { useEffect, useState } from "react"; -import { Button } from "@/components/ui/button"; -import { - Dialog, - DialogContent, - DialogHeader, - DialogTitle, - DialogTrigger, -} from "@/components/ui/dialog"; -import { Input } from "@/components/ui/input"; -import { Label } from "@/components/ui/label"; -import { Switch } from "@/components/ui/switch"; -import { Textarea } from "@/components/ui/textarea"; -import { useSettings } from "@/lib/hooks/use-settings"; -import { useToast } from "@/components/ui/use-toast"; - -export function DevSettings() { - const { settings, updateSettings } = useSettings(); - const [localSettings, setLocalSettings] = React.useState(settings); - const [isSaving, setIsSaving] = useState(false); - const { toast } = useToast(); - - React.useEffect(() => { - setLocalSettings(settings); - }, [settings]); - - const handleChange = (key: keyof typeof settings, value: any) => { - setLocalSettings((prev) => ({ ...prev, [key]: value })); - }; - - const handleSave = async () => { - setIsSaving(true); - toast({ - title: "updating dev settings", - description: "this may take a few moments...", - }); - - try { - // Create an object to store only the changed settings - const changedSettings = Object.entries(localSettings).reduce( - (acc, [key, value]) => { - if (value !== settings[key as keyof typeof settings]) { - acc[key as keyof typeof settings] = value; - } - return acc; - }, - {} as Partial - ); - - // Only update if there are changes - if (Object.keys(changedSettings).length > 0) { - await updateSettings(changedSettings); - await new Promise((resolve) => setTimeout(resolve, 1000)); - - toast({ - title: "dev settings updated successfully", - description: "your changes have been saved.", - }); - } else { - toast({ - title: "no changes detected", - description: "no settings were updated.", - }); - } - } catch (error) { - console.error("failed to update dev settings:", error); - toast({ - title: "error updating dev settings", - description: "please try again or check the logs for more information.", - variant: "destructive", - }); - } finally { - setIsSaving(false); - } - }; - - return ( - - - - - - - dev settings - -
- {Object.entries(localSettings).map(([key, value]) => ( -
- - {typeof value === "boolean" ? ( - - handleChange(key as any, checked) - } - /> - ) : typeof value === "string" ? ( - key === "customPrompt" ? ( -