1
Fork 0
mirror of https://github.com/Steffo99/bluelib.git synced 2024-12-22 11:34:21 +00:00
This commit is contained in:
Steffo 2020-06-23 23:26:34 +02:00
parent cd54429034
commit 2a13b0fdf6
Signed by: steffo
GPG key ID: 896A80F55F7C97F0
2 changed files with 7 additions and 5 deletions

View file

@ -1,7 +1,7 @@
{
"private": false,
"name": "bluelib",
"version": "0.12.5",
"version": "0.12.6",
"license": "AGPL-3.0-or-later",
"source": "src/index.js",
"main": "dist/index.js",

View file

@ -1,6 +1,5 @@
import { useEffect, useState } from 'preact/hooks';
import { royalnetApiRequest } from '../utils/royalnetApiRequest';
import { route } from 'preact-router';
export default function(defaultInstanceUrl) {
const [instanceUrl, setInstanceUrl] = useState(defaultInstanceUrl);
@ -35,20 +34,23 @@ export default function(defaultInstanceUrl) {
}, []);
function storeValues(newInstanceUrl, newLoginStatus) {
if(newLoginStatus !== null) {
console.debug(`Successfully logged in as ${newLoginStatus.user.username} @ ${newInstanceUrl} !`);
}
else {
console.debug(`Changed instanceUrl to ${newInstanceUrl} !`);
}
setInstanceUrl(newInstanceUrl);
setLoginStatus(newLoginStatus);
console.debug("Saving login data in the localStorage...");
window.localStorage.setItem("instanceUrl", newInstanceUrl);
window.localStorage.setItem("loginStatus", JSON.stringify(newLoginStatus));
route("/");
}
function logout() {
console.debug("User requested logout, clearing loginStatus and localStorage...");
setLoginStatus(null);
window.localStorage.setItem("loginStatus", null);
route("/");
}
return [instanceUrl, loginStatus, storeValues, logout]