fix: open new tool after its added

This commit is contained in:
Alex
2025-02-10 16:52:59 +00:00
parent 60772889d5
commit 6e8a53a204
2 changed files with 34 additions and 2 deletions

View File

@@ -58,9 +58,27 @@ export default function Tools() {
getUserTools();
};
const handleToolAdded = (toolId: string) => {
userService
.getUserTools()
.then((res) => res.json())
.then((data) => {
const newTool = data.tools.find(
(tool: UserToolType) => tool.id === toolId,
);
if (newTool) {
setSelectedTool(newTool);
} else {
console.error('Newly added tool not found');
}
})
.catch((error) => console.error('Error fetching tools:', error));
};
React.useEffect(() => {
getUserTools();
}, []);
return (
<div>
{selectedTool ? (
@@ -185,6 +203,7 @@ export default function Tools() {
modalState={addToolModalState}
setModalState={setAddToolModalState}
getUserTools={getUserTools}
onToolAdded={handleToolAdded}
/>
</div>
)}