Fix up login and initial window

This commit is contained in:
Pavel Djundik 2019-11-03 19:09:10 +02:00
parent 2b5a13a043
commit 743ae987ec
4 changed files with 30 additions and 92 deletions

View File

@ -3,7 +3,7 @@
<Sidebar :overlay="$refs.overlay" /> <Sidebar :overlay="$refs.overlay" />
<div id="sidebar-overlay" ref="overlay" @click="$root.setSidebar(false)" /> <div id="sidebar-overlay" ref="overlay" @click="$root.setSidebar(false)" />
<article id="windows"> <article id="windows">
<router-view></router-view> <router-view ref="window"></router-view>
</article> </article>
<ImageViewer ref="imageViewer" /> <ImageViewer ref="imageViewer" />
</div> </div>
@ -21,9 +21,6 @@ export default {
Sidebar, Sidebar,
ImageViewer, ImageViewer,
}, },
props: {
activeWindow: String,
},
computed: { computed: {
viewportClasses() { viewportClasses() {
return { return {

View File

@ -17,26 +17,21 @@ const RoutedChat = require("../components/RoutedChat.vue").default;
const router = new VueRouter({ const router = new VueRouter({
routes: [ routes: [
{ {
name: "SignIn",
path: "/sign-in", path: "/sign-in",
component: SignIn, component: SignIn,
meta: {
isChat: false,
windowName: "SignIn",
},
}, },
], ],
}); });
router.afterEach((to) => { router.afterEach((to) => {
if (!router.app.initialized) { if (router.app.initialized) {
return; router.app.closeSidebarIfNeeded();
} }
router.app.closeSidebarIfNeeded(); if (to.name !== "RoutedChat") {
if (!to.meta.isChat) {
// Navigating out of a chat window // Navigating out of a chat window
store.commit("activeWindow", to.meta.windowName); store.commit("activeWindow", to.name);
if (store.state.activeChannel && store.state.activeChannel.channel) { if (store.state.activeChannel && store.state.activeChannel.channel) {
router.app.switchOutOfChannel(store.state.activeChannel.channel); router.app.switchOutOfChannel(store.state.activeChannel.channel);
@ -49,60 +44,34 @@ router.afterEach((to) => {
function initialize() { function initialize() {
router.addRoutes([ router.addRoutes([
{ {
path: "/sign-in", name: "Connect",
component: SignIn,
meta: {
isChat: false,
windowName: "SignIn",
},
},
{
path: "/connect", path: "/connect",
component: Connect, component: Connect,
meta: {
isChat: false,
windowName: "Connect",
},
}, },
{ {
name: "Settings",
path: "/settings", path: "/settings",
component: Settings, component: Settings,
meta: {
isChat: false,
windowName: "Settings",
},
}, },
{ {
name: "Help",
path: "/help", path: "/help",
component: Help, component: Help,
meta: {
isChat: false,
windowName: "Help",
},
}, },
{ {
name: "Changelog",
path: "/changelog", path: "/changelog",
component: Changelog, component: Changelog,
meta: {
isChat: false,
windowName: "Changelog",
},
}, },
{ {
name: "NetworkEdit",
path: "/edit-network/:uuid", path: "/edit-network/:uuid",
component: NetworkEdit, component: NetworkEdit,
meta: {
isChat: false,
windowName: "NetworkEdit",
},
}, },
{ {
name: "RoutedChat",
path: "/chan-*", path: "/chan-*",
component: RoutedChat, component: RoutedChat,
meta: {
isChat: true,
windowName: "RoutedChat",
},
}, },
]); ]);
} }

View File

@ -1,10 +1,8 @@
"use strict"; "use strict";
const $ = require("jquery"); const $ = require("jquery");
const escape = require("css.escape");
const socket = require("../socket"); const socket = require("../socket");
const webpush = require("../webpush"); const webpush = require("../webpush");
const sidebar = $("#sidebar");
const storage = require("../localStorage"); const storage = require("../localStorage");
const constants = require("../constants"); const constants = require("../constants");
const {vueApp, initChannel} = require("../vue"); const {vueApp, initChannel} = require("../vue");
@ -16,8 +14,6 @@ socket.on("init", function(data) {
$("#loading-page-message").text(store.state.currentUserVisibleError); $("#loading-page-message").text(store.state.currentUserVisibleError);
const previousActive = store.state.activeChannel && store.state.activeChannel.channel.id;
store.commit("networks", mergeNetworkData(data.networks)); store.commit("networks", mergeNetworkData(data.networks));
store.commit("isConnected", true); store.commit("isConnected", true);
store.commit("currentUserVisibleError", null); store.commit("currentUserVisibleError", null);
@ -54,9 +50,23 @@ socket.on("init", function(data) {
window.removeEventListener("error", window.g_LoungeErrorHandler); window.removeEventListener("error", window.g_LoungeErrorHandler);
window.g_LoungeErrorHandler = null; window.g_LoungeErrorHandler = null;
} }
if (!vueApp.$route.name || vueApp.$route.name === "SignIn") {
const channel = store.getters.findChannel(data.active);
if (channel) {
vueApp.switchToChannel(channel.channel);
} else if (store.state.networks.length > 0) {
// Server is telling us to open a channel that does not exist
// For example, it can be unset if you first open the page after server start
vueApp.switchToChannel(store.state.networks[0].channels[0]);
} else {
// TODO: Use vue router
$("#footer .connect").trigger("click");
}
}
} }
vueApp.$nextTick(() => openCorrectChannel(previousActive, data.active));
vueApp.synchronizeNotifiedState(); vueApp.synchronizeNotifiedState();
if (document.body.classList.contains("public")) { if (document.body.classList.contains("public")) {
@ -67,44 +77,6 @@ socket.on("init", function(data) {
} }
}); });
function openCorrectChannel(clientActive, serverActive) {
let target = $();
// Open last active channel
if (clientActive > 0) {
target = sidebar.find(`.chan[data-id="${clientActive}"]`);
}
// Open window provided in location.hash
if (target.length === 0 && window.location.hash) {
target = $(`[data-target="${escape(window.location.hash)}"]`).first();
}
// Open last active channel according to the server
if (serverActive > 0 && target.length === 0) {
target = sidebar.find(`.chan[data-id="${serverActive}"]`);
}
// Open first available channel
if (target.length === 0) {
target = sidebar.find(".chan").first();
}
// If target channel is found, open it
if (target.length > 0) {
target.trigger("click", {
replaceHistory: true,
});
return;
}
// Open the connect window
$("#footer .connect").trigger("click", {
pushState: false,
});
}
function mergeNetworkData(newNetworks) { function mergeNetworkData(newNetworks) {
const collapsedNetworks = new Set(JSON.parse(storage.get("thelounge.networks.collapsed"))); const collapsedNetworks = new Set(JSON.parse(storage.get("thelounge.networks.collapsed")));

View File

@ -48,9 +48,9 @@ const vueApp = new Vue({
document.body.classList.add("is-apple"); document.body.classList.add("is-apple");
} }
document.addEventListener("visibilitychange", this.synchronizeNotifiedState()); document.addEventListener("visibilitychange", this.synchronizeNotifiedState);
document.addEventListener("focus", this.synchronizeNotifiedState()); document.addEventListener("focus", this.synchronizeNotifiedState);
document.addEventListener("click", this.synchronizeNotifiedState()); document.addEventListener("click", this.synchronizeNotifiedState);
// TODO: Hackfix because socket-events require vueApp somewhere // TODO: Hackfix because socket-events require vueApp somewhere
// and that breaks due to cyclical depenency as by this point vue.js // and that breaks due to cyclical depenency as by this point vue.js