import React from 'react'; import userService from '../api/services/userService'; import CogwheelIcon from '../assets/cogwheel.svg'; import NoFilesDarkIcon from '../assets/no-files-dark.svg'; import NoFilesIcon from '../assets/no-files.svg'; import Input from '../components/Input'; import { useDarkTheme } from '../hooks'; import AddToolModal from '../modals/AddToolModal'; import { ActiveState } from '../models/misc'; import ToolConfig from './ToolConfig'; import { UserTool } from './types'; export default function Tools() { const [isDarkTheme] = useDarkTheme(); const [searchTerm, setSearchTerm] = React.useState(''); const [addToolModalState, setAddToolModalState] = React.useState('INACTIVE'); const [userTools, setUserTools] = React.useState([]); const [selectedTool, setSelectedTool] = React.useState(null); const getUserTools = () => { userService .getUserTools() .then((res) => { return res.json(); }) .then((data) => { setUserTools(data.tools); }); }; const updateToolStatus = (toolId: string, newStatus: boolean) => { userService .updateToolStatus({ id: toolId, status: newStatus }) .then(() => { setUserTools((prevTools) => prevTools.map((tool) => tool.id === toolId ? { ...tool, status: newStatus } : tool, ), ); }) .catch((error) => { console.error('Failed to update tool status:', error); }); }; const handleSettingsClick = (tool: UserTool) => { setSelectedTool(tool); }; const handleGoBack = () => { setSelectedTool(null); getUserTools(); }; React.useEffect(() => { getUserTools(); }, []); return (
{selectedTool ? ( ) : (
setSearchTerm(e.target.value)} />
{userTools.filter((tool) => tool.displayName .toLowerCase() .includes(searchTerm.toLowerCase()), ).length === 0 ? (
No tools found No tools found
) : ( userTools .filter((tool) => tool.displayName .toLowerCase() .includes(searchTerm.toLowerCase()), ) .map((tool, index) => (

{tool.displayName}

{tool.description}

)) )}
)}
); }