diff --git a/package.json b/package.json index c6d70fb..930b00e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": false, "name": "bluelib", - "version": "0.12.3", + "version": "0.12.4", "license": "AGPL-3.0-or-later", "source": "src/index.js", "main": "dist/index.js", diff --git a/src/hooks/useLoginDataStorage.js b/src/hooks/useLoginDataStorage.js index 160838d..4891d8c 100644 --- a/src/hooks/useLoginDataStorage.js +++ b/src/hooks/useLoginDataStorage.js @@ -34,7 +34,7 @@ export default function(defaultInstanceUrl) { }) }, []); - function onSuccessfulLogin(newInstanceUrl, newLoginStatus) { + function storeValues(newInstanceUrl, newLoginStatus) { console.debug(`Successfully logged in as ${newLoginStatus.user.username} @ ${newInstanceUrl} !`); setInstanceUrl(newInstanceUrl); setLoginStatus(newLoginStatus); @@ -44,12 +44,12 @@ export default function(defaultInstanceUrl) { route("/"); } - function requestLogout() { + function logout() { console.debug("User requested logout, clearing loginStatus and localStorage..."); setLoginStatus(null); window.localStorage.setItem("loginStatus", null); route("/"); } - return [instanceUrl, loginStatus, onSuccessfulLogin, requestLogout] + return [instanceUrl, loginStatus, storeValues, logout] } diff --git a/src/hooks/useRoyalnetData.js b/src/hooks/useRoyalnetData.js index a931700..a5d7cab 100644 --- a/src/hooks/useRoyalnetData.js +++ b/src/hooks/useRoyalnetData.js @@ -10,6 +10,7 @@ export default function(method, path, body) { const loginStatus = useContext(LoginStatus); const [data, setData] = useState(undefined); const [error, setError] = useState(undefined); + const [instanceTesterAbort, setInstanceTesterAbort] = useState(null); if(body === undefined) { body = {} @@ -22,11 +23,18 @@ export default function(method, path, body) { function refresh() { setData(undefined); setError(undefined); - royalnetApiRequest(instanceUrl, method, path, body).then(d => setData(d)).catch((e => setError(e))); + + if(instanceTesterAbort !== null) { + instanceTesterAbort.abort(); + } + let abort = new AbortController(); + setInstanceTesterAbort(abort); + + royalnetApiRequest(instanceUrl, method, path, body, abort).then(d => setData(d)).catch((e => setError(e))); } useDeepCompareEffect(() => { - royalnetApiRequest(instanceUrl, method, path, body).then(d => setData(d)).catch((e => setError(e))); + refresh(); }, [instanceUrl, method, path, body]); return [data, error, refresh];