diff --git a/client/components/ChannelWrapper.vue b/client/components/ChannelWrapper.vue index feb62695..fddf1e14 100644 --- a/client/components/ChannelWrapper.vue +++ b/client/components/ChannelWrapper.vue @@ -84,7 +84,6 @@ export default { click() { // TODO: Find out why this sometimes throws `uncaught exception: Object` this.$router.push("chan-" + this.channel.id); - this.$root.closeSidebarIfNeeded(); }, }, }; diff --git a/client/components/Sidebar.vue b/client/components/Sidebar.vue index 389d671c..665197b6 100644 --- a/client/components/Sidebar.vue +++ b/client/components/Sidebar.vue @@ -17,36 +17,39 @@ @@ -182,16 +186,6 @@ export default { this.$store.commit("sidebarOpen", state); }; - this.navigate = (to) => { - if (this.activeChannel && this.activeChannel.channel) { - this.$root.switchOutOfChannel(this.activeChannel.channel); - } - - this.$root.activeChannel = null; - this.$root.closeSidebarIfNeeded(); - this.$router.push(to); - }; - document.body.addEventListener("touchstart", this.onTouchStart, {passive: true}); }, methods: { diff --git a/client/js/router.js b/client/js/router.js index 0c118446..9d7faeff 100644 --- a/client/js/router.js +++ b/client/js/router.js @@ -13,13 +13,74 @@ const RoutedChat = require("../components/RoutedChat.vue").default; const router = new VueRouter({ routes: [ - {path: "/sign-in", component: SignIn}, - {path: "/connect", component: Connect}, - {path: "/settings", component: Settings}, - {path: "/help", component: Help}, - {path: "/changelog", component: Changelog}, - {path: "/chan-*", component: RoutedChat}, + { + path: "/sign-in", + component: SignIn, + meta: { + isChat: false, + windowName: "SignIn", + }, + }, + { + path: "/connect", + component: Connect, + meta: { + isChat: false, + windowName: "Connect", + }, + }, + { + path: "/settings", + component: Settings, + meta: { + isChat: false, + windowName: "Settings", + }, + }, + { + path: "/help", + component: Help, + meta: { + isChat: false, + windowName: "Help", + }, + }, + { + path: "/changelog", + component: Changelog, + meta: { + isChat: false, + windowName: "Changelog", + }, + }, + { + path: "/chan-*", + component: RoutedChat, + meta: { + isChat: true, + windowName: "RoutedChat", + }, + }, ], }); +router.afterEach((to) => { + if (!router.app.initialized) { + return; + } + + router.app.closeSidebarIfNeeded(); + + if (!to.meta.isChat) { + // Navigating out of a chat window + router.app.$store.commit("activeWindow", to.meta.windowName); + + if (router.app.activeChannel && router.app.activeChannel.channel) { + router.app.switchOutOfChannel(router.app.activeChannel.channel); + } + + router.app.activeChannel = null; + } +}); + export default router;