From ac1b1c3cdd1c8ec43835e8205c0faa3d3b343f84 Mon Sep 17 00:00:00 2001 From: Siddhant Rai Date: Wed, 19 Feb 2025 13:58:40 +0530 Subject: [PATCH] feat: add loading spinner to AddToolModal and improve label spacing in General settings --- frontend/src/modals/AddToolModal.tsx | 83 +++++++------ frontend/src/settings/General.tsx | 2 +- frontend/src/settings/Tools.tsx | 172 +++++++++++++++------------ 3 files changed, 142 insertions(+), 115 deletions(-) diff --git a/frontend/src/modals/AddToolModal.tsx b/frontend/src/modals/AddToolModal.tsx index c8652c5b..8b4e98be 100644 --- a/frontend/src/modals/AddToolModal.tsx +++ b/frontend/src/modals/AddToolModal.tsx @@ -7,6 +7,7 @@ import { useOutsideAlerter } from '../hooks'; import { ActiveState } from '../models/misc'; import ConfigToolModal from './ConfigToolModal'; import { AvailableToolType } from './types'; +import Spinner from '../components/Spinner'; export default function AddToolModal({ message, @@ -21,6 +22,8 @@ export default function AddToolModal({ getUserTools: () => void; onToolAdded: (toolId: string) => void; }) { + const { t } = useTranslation(); + const modalRef = useRef(null); const [availableTools, setAvailableTools] = React.useState< AvailableToolType[] >([]); @@ -28,8 +31,7 @@ export default function AddToolModal({ React.useState(null); const [configModalState, setConfigModalState] = React.useState('INACTIVE'); - const modalRef = useRef(null); - const { t } = useTranslation(); + const [loading, setLoading] = React.useState(false); useOutsideAlerter(modalRef, () => { if (modalState === 'ACTIVE') { @@ -38,6 +40,7 @@ export default function AddToolModal({ }, [modalState]); const getAvailableTools = () => { + setLoading(true); userService .getAvailableTools() .then((res) => { @@ -45,6 +48,7 @@ export default function AddToolModal({ }) .then((data) => { setAvailableTools(data.data); + setLoading(false); }); }; @@ -85,7 +89,6 @@ export default function AddToolModal({ React.useEffect(() => { if (modalState === 'ACTIVE') getAvailableTools(); }, [modalState]); - return ( <>
- {availableTools.map((tool, index) => ( -
{ - setSelectedTool(tool); - handleAddTool(tool); - }} - onKeyDown={(e) => { - if (e.key === 'Enter' || e.key === ' ') { + {loading ? ( +
+ +
+ ) : ( + availableTools.map((tool, index) => ( +
{ setSelectedTool(tool); handleAddTool(tool); - } - }} - > -
-
- -
-
-

- {tool.displayName} -

-

- {tool.description} -

+ }} + onKeyDown={(e) => { + if (e.key === 'Enter' || e.key === ' ') { + setSelectedTool(tool); + handleAddTool(tool); + } + }} + > +
+
+ +
+
+

+ {tool.displayName} +

+

+ {tool.description} +

+
-
- ))} + )) + )}
diff --git a/frontend/src/settings/General.tsx b/frontend/src/settings/General.tsx index d974eab7..86c4f4ab 100644 --- a/frontend/src/settings/General.tsx +++ b/frontend/src/settings/General.tsx @@ -84,7 +84,7 @@ export default function General() { return (
-