Compare commits

..

3 commits

Author SHA1 Message Date
hippoz
144877e682
frontend: rework logging system 2022-05-05 20:52:35 +03:00
hippoz
243036f29e
frontend: add useAuthHandlers in main.js 2022-05-05 20:39:24 +03:00
hippoz
d0a61450c5
fix sidebar fly animation 2022-05-05 20:35:00 +03:00
7 changed files with 25 additions and 35 deletions

View file

@ -2,7 +2,7 @@ import gateway, { GatewayEventType } from "./gateway";
import { removeItem, setItem } from "./storage"; import { removeItem, setItem } from "./storage";
import { overlayStore } from "./stores"; import { overlayStore } from "./stores";
function useAuthHandlers() { export function useAuthHandlers() {
gateway.subscribe(GatewayEventType.Ready, () => { gateway.subscribe(GatewayEventType.Ready, () => {
overlayStore.close("login"); overlayStore.close("login");
overlayStore.close("createAccount"); overlayStore.close("createAccount");
@ -24,5 +24,3 @@ export function logOut() {
gateway.close(); gateway.close();
gateway.dispatch(GatewayEventType.BadAuth, -1); gateway.dispatch(GatewayEventType.BadAuth, -1);
} }
useAuthHandlers();

View file

@ -1,8 +1,7 @@
<script> <script>
import { HashIcon, PlusIcon, MoreVerticalIcon, SettingsIcon } from "svelte-feather-icons"; import { HashIcon, PlusIcon, MoreVerticalIcon, SettingsIcon } from "svelte-feather-icons";
import { quadInOut } from "svelte/easing"; import { quadInOut } from "svelte/easing";
import { fly } from "svelte/transition"; import { maybeFly } from "../animations";
import { maybeFade } from "../animations";
import { channels, overlayStore, selectedChannel, showChannelView, showSidebar, smallViewport, userInfoStore } from "../stores"; import { channels, overlayStore, selectedChannel, showChannelView, showSidebar, smallViewport, userInfoStore } from "../stores";
import UserTopBar from "./UserTopBar.svelte"; import UserTopBar from "./UserTopBar.svelte";
@ -31,7 +30,7 @@ import { maybeFade } from "../animations";
}; };
</script> </script>
<div class="sidebar-container" transition:maybeFade="{{ duration: 200, easing: quadInOut, x: -10 }}" on:outroend="{ outroEnd }"> <div class="sidebar-container" transition:maybeFly="{{ duration: 200, easing: quadInOut, x: -10 }}" on:outroend="{ outroEnd }">
<UserTopBar /> <UserTopBar />
<div class="sidebar"> <div class="sidebar">
{#each $channels as channel (channel.id)} {#each $channels as channel (channel.id)}

View file

@ -1,4 +1,4 @@
import logging from "./logging"; import logger from "./logging";
import { getItem } from "./storage"; import { getItem } from "./storage";
export const GatewayErrors = { export const GatewayErrors = {
@ -35,7 +35,7 @@ export const GatewayEventType = {
BadAuth: -3, BadAuth: -3,
} }
const log = logging.logger("Gateway", true); const log = logger("Gateway");
export default { export default {
ws: null, ws: null,

View file

@ -1,9 +1,8 @@
export default { import { getItem } from "./storage";
sinks: new Map(),
logger(sink, enabled=false) { export default function logger(sink) {
this.sinks.set(sink, enabled);
return (...args) => { return (...args) => {
if (this.sinks.get(sink)) { if (getItem(`loggingSink:${sink}`)) {
console.log( console.log(
`%c[${sink}]`, `%c[${sink}]`,
"color: #8f3f71; font-weight: bold;", "color: #8f3f71; font-weight: bold;",
@ -11,11 +10,4 @@ export default {
); );
} }
}; };
}, }
enableSink(sink) {
this.sinks.set(sink, true);
},
disableSink(sink) {
this.sinks.set(sink, false);
}
};

View file

@ -1,17 +1,16 @@
import Main from './components/Main.svelte'; import Main from './components/Main.svelte';
import gateway from './gateway'; import gateway from './gateway';
import { getItem, init } from './storage'; import { getItem, init } from './storage';
import logging from "./logging"; import { authWithToken, useAuthHandlers } from './auth';
import { authWithToken } from './auth';
import { initResponsiveHandlers } from './responsive'; import { initResponsiveHandlers } from './responsive';
window.__waffle = { window.__waffle = {
logging,
gateway gateway
}; };
init(); init();
initResponsiveHandlers(); initResponsiveHandlers();
useAuthHandlers();
authWithToken(getItem("token")); authWithToken(getItem("token"));
// Remove loading screen // Remove loading screen

View file

@ -2,7 +2,9 @@ const defaults = {
apiBase: `${window.location.origin}/api/v1`, apiBase: `${window.location.origin}/api/v1`,
gatewayBase: `${location.protocol === "https:" ? "wss" : "ws"}://${location.host}/gateway`, gatewayBase: `${location.protocol === "https:" ? "wss" : "ws"}://${location.host}/gateway`,
doAnimations: true, doAnimations: true,
token: "" token: "",
"loggingSink:Gateway": false,
"loggingSink:Store": false
}; };
const store = new Map(Object.entries(defaults)); const store = new Map(Object.entries(defaults));
const persistentProvider = localStorage; const persistentProvider = localStorage;

View file

@ -1,9 +1,9 @@
import gateway, { GatewayEventType } from "./gateway"; import gateway, { GatewayEventType } from "./gateway";
import logging from "./logging"; import logger from "./logging";
import request from "./request"; import request from "./request";
import { apiRoute } from "./storage"; import { apiRoute } from "./storage";
const storeLog = logging.logger("Store", true); const storeLog = logger("Store");
class Store { class Store {
constructor(value=null, name="[unnamed]") { constructor(value=null, name="[unnamed]") {