Compare commits

..

No commits in common. "0a17ea2ac6b12c3241b72b743964edb303051374" and "06e081d7853ef2b3f7f8193302ffd23fc3258c34" have entirely different histories.

4 changed files with 10 additions and 58 deletions

View file

@ -1,22 +0,0 @@
import gateway from './gateway';
import { getItem, init, setItem, removeItem } from './storage';
import { allStores } from './stores';
import { authWithToken, logOut } from './auth';
export function useDebuggingApi() {
window.__waffle = {
gateway,
storage: {
getItem,
setItem,
removeItem,
init
},
auth: {
authWithToken,
logOut
},
stores: allStores,
app: null
};
}

View file

@ -1,10 +1,14 @@
import Main from './components/Main.svelte';
import { getItem } from './storage';
import gateway from './gateway';
import { getItem, init } from './storage';
import { authWithToken, useAuthHandlers } from './auth';
import { initResponsiveHandlers } from './responsive';
import { useDebuggingApi } from './debuggingapi';
useDebuggingApi();
window.__waffle = {
gateway
};
init();
initResponsiveHandlers();
useAuthHandlers();
authWithToken(getItem("auth:token"));
@ -18,6 +22,5 @@ if (loadingElement) {
const app = new Main({
target: document.body
});
window.__waffle.app = app;
export default app;

View file

@ -3,13 +3,11 @@ const defaults = {
"server:gatewayBase": `${location.protocol === "https:" ? "wss" : "ws"}://${location.host}/gateway`,
"auth:token": "",
"app:behavior:doAnimations": true,
"app:cache:openChannelId": -1,
"loggingSink:Gateway": false,
"loggingSink:Store": false
};
const store = new Map(Object.entries(defaults));
const persistentProvider = localStorage;
let didCacheProvider = false;
export function setItem(key, value) {
store.set(key, value);
@ -19,9 +17,6 @@ export function setItem(key, value) {
}
export function getItem(key) {
if (!didCacheProvider) {
init();
}
return store.get(key);
}
@ -47,8 +42,6 @@ export function init() {
}
}
});
didCacheProvider = true;
}
export function apiRoute(fragment) {

View file

@ -1,7 +1,7 @@
import gateway, { GatewayEventType } from "./gateway";
import logger from "./logging";
import request from "./request";
import { apiRoute, getItem, setItem } from "./storage";
import { apiRoute } from "./storage";
const storeLog = logger("Store");
@ -42,14 +42,7 @@ class ChannelsStore extends Store {
gateway.subscribe(GatewayEventType.Ready, ({ channels }) => {
this.value = channels;
if (channels.length >= 1) {
if (!selectedChannel.value || selectedChannel.value.id === -1) {
selectedChannel.set(channels[0]);
} else {
// if a channel id is already selected, we'll populate it with the data we just got from the gateway
const index = this.value.findIndex(e => e.id === selectedChannel.value.id);
if (index !== -1)
selectedChannel.set(this.value[index]);
}
}
this.updated();
});
@ -293,7 +286,7 @@ class OverlayStore extends Store {
}
}
export const selectedChannel = new Store({ id: getItem("app:cache:openChannelId"), name: "none", creator_id: -1 }, "selectedChannel");
export const selectedChannel = new Store({ id: -1, name: "none", creator_id: -1 }, "selectedChannel");
export const showSidebar = new Store(false, "showSidebar");
export const showChannelView = new Store(true, "showChannelView");
export const smallViewport = new Store(false, "smallViewport");
@ -302,18 +295,3 @@ export const gatewayStatus = new GatewayStatusStore();
export const messagesStoreProvider = new MessagesStoreProvider();
export const userInfoStore = new UserInfoStore();
export const overlayStore = new OverlayStore();
export const allStores = {
selectedChannel,
showSidebar,
showChannelView,
smallViewport,
channels,
gatewayStatus,
messagesStoreProvider,
userInfoStore,
overlayStore,
};
selectedChannel.subscribe((newSelectedChannel) => {
setItem("app:cache:openChannelId", newSelectedChannel.id);
});