import React, { useEffect, useState } from "react"; import { apiService } from "../services/api.service"; import { Check, Save, Loader } from "lucide-react"; const Config = () => { const [config, setConfig] = useState(null); const [isLoading, setIsLoading] = useState(true); const [isSaving, setIsSaving] = useState(false); const [saveSuccess, setSaveSuccess] = useState(false); const editableKeys = [ "pick", "use_agg", "put_back", "drop_object", "vel_mul", "range_", "save_point_clouds", "save_to_db", "same_object", "same_place_index", ]; // Descriptions are always visible instead of in a tooltip, so they're also readable on touch const descriptions = { "pick": "Enables the part-picking function", "use_agg": "Uses the matplotlib Agg backend to avoid opening a chart window", "put_back": "Puts the part back where it was picked from", "drop_object": "Enables dropping the object in the scene", "vel_mul": "Motion speed multiplier", "range_": "Loop range", "save_point_clouds": "Saves point clouds to disk", "save_to_db": "Saves results to the database", "same_object": "Treats it as the same object", "same_place_index": "The index the part will be picked from each time (enter -1 to disable this feature)" }; useEffect(() => { const fetchConfig = async () => { try { const data = await apiService.GetConfig(); setConfig(data); } catch (error) { console.error("Config loading failed:", error); } finally { setIsLoading(false); } }; fetchConfig(); }, []); const handleChange = (key, value) => { setConfig((prev) => ({ ...prev, [key]: value, })); setSaveSuccess(false); }; const handleSubmit = async () => { setIsSaving(true); try { await apiService.SetConfig(config); setSaveSuccess(true); // Reset success message after 3 seconds setTimeout(() => { setSaveSuccess(false); }, 3000); } catch (error) { console.error("Config update failed:", error); alert("Could not save. Please try again."); } finally { setIsSaving(false); } }; const formatLabel = (key) => { return key .replace(/_/g, ' ') .trim() .split(' ') .map(word => word.charAt(0).toUpperCase() + word.slice(1)) .join(' '); }; if (isLoading) { return (