diff --git a/src/components/PluginSelector/PluginSelector.tsx b/src/components/PluginSelector/PluginSelector.tsx index 04e3a1c..2d4ea73 100644 --- a/src/components/PluginSelector/PluginSelector.tsx +++ b/src/components/PluginSelector/PluginSelector.tsx @@ -31,15 +31,16 @@ export default function PluginSelector({ plugin: string; onPluginChange: (plugin: string) => void; }) { + const [wereFetched, setWereFetched] = React.useState(false); const [plugins, setPlugins] = React.useState< - { displayName: string; name: string }[] + { displayName: string; name: string; }[] >([]); const { credential, checkExpired } = useAuthContext(); React.useEffect(() => { const expired = checkExpired(); - if (expired) { + if (expired || wereFetched) { return; } const url = new URL(window.config.VITE_API_BASE_URL || process.env.VITE_API_BASE_URL || ""); @@ -54,10 +55,16 @@ export default function PluginSelector({ throw new Error("Failed to fetch"); } response.json().then((data) => { - setPlugins(data); + if (data.length > 0) { + setPlugins(data); + if (data.length === 1) { + onPluginChange(data[0].name); + } + } + setWereFetched(true); }); }); - }, [checkExpired, credential?.credential]); + }, [checkExpired, credential?.credential, wereFetched, setWereFetched]); return ( @@ -65,7 +72,7 @@ export default function PluginSelector({ Plugin