From 2a452867ce4148bccd4c79948526b564b1dd9e74 Mon Sep 17 00:00:00 2001 From: Nathan Windisch Date: Thu, 13 Mar 2025 04:39:36 +0000 Subject: [PATCH] updated variables names to make a bit more sense :) --- src/App.tsx | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 13de8c0..8217284 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -17,42 +17,38 @@ const uri = "https://login.microsoft.com/{tenant}/.well-known/openid-configuration"; function App() { - const [domain, setDomain] = useState(location.hash.replace("#", "")); + const [input, setInput] = useState(location.hash.replace("#", "")); const [tenantId, setTenantId] = useState(null); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); - // const location = useLocation(); - const [debouncedDomain, setDebouncedDomain] = useDebounce( - domain, - 500 - ); + const [domain, setDomain] = useDebounce(input, 500); const onChange = async (event: React.ChangeEvent) => - setDomain(event.target.value); + setInput(event.target.value); useEffect(() => { - location.hash = debouncedDomain; + location.hash = domain; if ( - (!debouncedDomain.includes("@") && !debouncedDomain.includes(".")) || - debouncedDomain.includes(" ") || - debouncedDomain.endsWith(".") || - debouncedDomain.length < 3 || - debouncedDomain.length > 254 + (!domain.includes("@") && !domain.includes(".")) || + domain.includes(" ") || + domain.endsWith(".") || + domain.length < 3 || + domain.length > 254 ) { setTenantId(null); setIsLoading(false); setError("Please enter a valid email address or domain."); return; } - if (debouncedDomain.includes("@")) { - const parts = debouncedDomain.split("@"); + if (domain.includes("@")) { + const parts = domain.split("@"); setIsLoading(false); - setDebouncedDomain(parts[parts.length - 1]); + setDomain(parts[parts.length - 1]); return; } setIsLoading(true); setError(null); (async function () { - const response = await fetch(uri.replace("{tenant}", debouncedDomain)); + const response = await fetch(uri.replace("{tenant}", domain)); const body = await response.json(); if (!response.ok) { setTenantId(null); @@ -64,7 +60,7 @@ function App() { setTenantId(myTenantId); setIsLoading(false); })(); - }, [debouncedDomain, setDebouncedDomain]); + }, [domain, setDomain]); return ( <> @@ -112,7 +108,7 @@ function App() { -- 2.17.1