Fixes to vue routing and activeWindow.

This commit is contained in:
Richard Lewis 2019-10-20 16:17:21 +00:00 committed by Pavel Djundik
parent f76ad57c63
commit c393dd1a11
3 changed files with 87 additions and 33 deletions

View File

@ -84,7 +84,6 @@ export default {
click() { click() {
// TODO: Find out why this sometimes throws `uncaught exception: Object` // TODO: Find out why this sometimes throws `uncaught exception: Object`
this.$router.push("chan-" + this.channel.id); this.$router.push("chan-" + this.channel.id);
this.$root.closeSidebarIfNeeded();
}, },
}, },
}; };

View File

@ -17,36 +17,39 @@
</div> </div>
<footer id="footer"> <footer id="footer">
<span class="tooltipped tooltipped-n tooltipped-no-touch" aria-label="Sign in" <span class="tooltipped tooltipped-n tooltipped-no-touch" aria-label="Sign in"
><button ><router-link
:class="['icon', 'sign-in', {active: $store.state.activeWindow === 'SignIn'}]" to="/sign-in"
tag="button"
active-class="active"
:class="['icon', 'sign-in']"
data-target="#sign-in" data-target="#sign-in"
data-component="SignIn" data-component="SignIn"
aria-label="Sign in" aria-label="Sign in"
role="tab" role="tab"
aria-controls="sign-in" aria-controls="sign-in"
:aria-selected="$store.state.activeWindow === 'SignIn'" :aria-selected="$store.state.activeWindow === 'SignIn'"
@click="navigate('sign-in')"
/></span> /></span>
<span <span
class="tooltipped tooltipped-n tooltipped-no-touch" class="tooltipped tooltipped-n tooltipped-no-touch"
aria-label="Connect to network" aria-label="Connect to network"
><button ><router-link
:class="['icon', 'connect', {active: $store.state.activeWindow === 'Connect'}]" to="/connect"
tag="button"
active-class="active"
:class="['icon', 'connect']"
data-target="#connect" data-target="#connect"
data-component="Connect" data-component="Connect"
aria-label="Connect to network" aria-label="Connect to network"
role="tab" role="tab"
aria-controls="connect" aria-controls="connect"
:aria-selected="$store.state.activeWindow === 'Connect'" :aria-selected="$store.state.activeWindow === 'Connect'"
@click="navigate('connect')"
/></span> /></span>
<span class="tooltipped tooltipped-n tooltipped-no-touch" aria-label="Settings" <span class="tooltipped tooltipped-n tooltipped-no-touch" aria-label="Settings"
><button ><router-link
:class="[ to="/settings"
'icon', tag="button"
'settings', active-class="active"
{active: $store.state.activeWindow === 'Settings'}, :class="['icon', 'settings']"
]"
class="icon settings" class="icon settings"
data-target="#settings" data-target="#settings"
data-component="Settings" data-component="Settings"
@ -54,18 +57,19 @@
role="tab" role="tab"
aria-controls="settings" aria-controls="settings"
:aria-selected="$store.state.activeWindow === 'Settings'" :aria-selected="$store.state.activeWindow === 'Settings'"
@click="navigate('settings')"
/></span> /></span>
<span class="tooltipped tooltipped-n tooltipped-no-touch" aria-label="Help" <span class="tooltipped tooltipped-n tooltipped-no-touch" aria-label="Help"
><button ><router-link
:class="['icon', 'help', {active: $store.state.activeWindow === 'Help'}]" to="/help"
tag="button"
active-class="active"
:class="['icon', 'help']"
data-target="#help" data-target="#help"
data-component="Help" data-component="Help"
aria-label="Help" aria-label="Help"
role="tab" role="tab"
aria-controls="help" aria-controls="help"
:aria-selected="$store.state.activeWindow === 'Help'" :aria-selected="$store.state.activeWindow === 'Help'"
@click="navigate('help')"
/></span> /></span>
</footer> </footer>
</aside> </aside>
@ -182,16 +186,6 @@ export default {
this.$store.commit("sidebarOpen", state); 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}); document.body.addEventListener("touchstart", this.onTouchStart, {passive: true});
}, },
methods: { methods: {

View File

@ -13,13 +13,74 @@ const RoutedChat = require("../components/RoutedChat.vue").default;
const router = new VueRouter({ const router = new VueRouter({
routes: [ routes: [
{path: "/sign-in", component: SignIn}, {
{path: "/connect", component: Connect}, path: "/sign-in",
{path: "/settings", component: Settings}, component: SignIn,
{path: "/help", component: Help}, meta: {
{path: "/changelog", component: Changelog}, isChat: false,
{path: "/chan-*", component: RoutedChat}, 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; export default router;