frontend: change storage value naming scheme

This commit is contained in:
hippoz 2022-05-05 21:30:21 +03:00
parent 144877e682
commit 06e081d785
Signed by: hippoz
GPG key ID: 7C52899193467641
6 changed files with 15 additions and 14 deletions

View file

@ -2,11 +2,11 @@ import { fade, fly } from "svelte/transition";
import { getItem } from "./storage";
export function maybeFly(...e) {
if (getItem("doAnimations"))
if (getItem("app:behavior:doAnimations"))
return fly(...e);
}
export function maybeFade(...e) {
if (getItem("doAnimations"))
if (getItem("app:behavior:doAnimations"))
return fade(...e);
}

View file

@ -15,12 +15,12 @@ export function useAuthHandlers() {
export function authWithToken(token, shouldUpdate=false) {
if (shouldUpdate)
setItem("token", token);
setItem("auth:token", token);
gateway.init(token);
}
export function logOut() {
removeItem("token");
removeItem("auth:token");
gateway.close();
gateway.dispatch(GatewayEventType.BadAuth, -1);
}

View file

@ -54,8 +54,8 @@ export default {
this.dispatch(GatewayEventType.BadAuth, 0);
return false;
}
log(`connecting to gateway - gatewayBase: ${getItem("gatewayBase")}`);
this.ws = new WebSocket(getItem("gatewayBase"));
log(`connecting to gateway - gatewayBase: ${getItem("server:gatewayBase")}`);
this.ws = new WebSocket(getItem("server:gatewayBase"));
this.ws.onopen = () => {
if (this.reconnectTimeout) {
clearTimeout(this.reconnectTimeout);

View file

@ -11,7 +11,7 @@ window.__waffle = {
init();
initResponsiveHandlers();
useAuthHandlers();
authWithToken(getItem("token"));
authWithToken(getItem("auth:token"));
// Remove loading screen
const loadingElement = document.getElementById("pre--loading-screen");

View file

@ -14,7 +14,7 @@ export default async function(method, endpoint, auth=true, body=null) {
}
if (auth) {
const token = getItem("token");
const token = getItem("auth:token");
if (token) {
options.headers = {
...options.headers || {},

View file

@ -1,8 +1,8 @@
const defaults = {
apiBase: `${window.location.origin}/api/v1`,
gatewayBase: `${location.protocol === "https:" ? "wss" : "ws"}://${location.host}/gateway`,
doAnimations: true,
token: "",
"server:apiBase": `${window.location.origin}/api/v1`,
"server:gatewayBase": `${location.protocol === "https:" ? "wss" : "ws"}://${location.host}/gateway`,
"auth:token": "",
"app:behavior:doAnimations": true,
"loggingSink:Gateway": false,
"loggingSink:Store": false
};
@ -37,12 +37,13 @@ export function init() {
try {
store.set(key, typeof defaultValue === "string" ? override : JSON.parse(override));
} catch (o_O) {
console.warn("[Storage]", `init(): An exception was thrown while parsing the value of key "${key}" from _persistentProvider`, o_O);
console.warn("[Storage]", `init(): An exception was thrown while parsing the value of key "${key}" from persistentProvider. The key "${key}" will be removed from persistentProvider.`, o_O);
persistentProvider.removeItem(key);
}
}
});
}
export function apiRoute(fragment) {
return `${getItem("apiBase")}/${fragment}`
return `${getItem("server:apiBase")}/${fragment}`
}