thelounge/client/components/App.vue

85 lines
2.2 KiB
Vue
Raw Normal View History

<template>
2019-02-22 15:21:32 +01:00
<div
id="viewport"
2019-02-27 15:15:34 +01:00
:class="{notified: $store.state.isNotified}"
2019-02-22 15:21:32 +01:00
role="tablist">
<Sidebar
:networks="networks"
:active-channel="activeChannel" />
<article id="windows">
2018-07-08 15:42:54 +02:00
<Chat
v-if="activeChannel"
:network="activeChannel.network"
2019-02-18 10:18:32 +01:00
:channel="activeChannel.channel" />
<component
2019-02-27 19:15:58 +01:00
:is="$store.state.activeWindow"
2019-02-18 10:18:32 +01:00
ref="window" />
</article>
</div>
</template>
<script>
const throttle = require("lodash/throttle");
2019-02-22 15:21:32 +01:00
import Sidebar from "./Sidebar.vue";
import NetworkList from "./NetworkList.vue";
import Chat from "./Chat.vue";
2019-02-18 10:18:32 +01:00
import SignIn from "./Windows/SignIn.vue";
2019-02-20 10:10:18 +01:00
import Settings from "./Windows/Settings.vue";
import NetworkEdit from "./Windows/NetworkEdit.vue";
import Connect from "./Windows/Connect.vue";
2019-02-20 16:01:33 +01:00
import Help from "./Windows/Help.vue";
2019-02-20 16:09:44 +01:00
import Changelog from "./Windows/Changelog.vue";
export default {
name: "App",
components: {
2019-02-22 15:21:32 +01:00
Sidebar,
NetworkList,
Chat,
2019-02-18 10:18:32 +01:00
SignIn,
2019-02-20 10:10:18 +01:00
Settings,
NetworkEdit,
Connect,
2019-02-20 16:01:33 +01:00
Help,
2019-02-20 16:09:44 +01:00
Changelog,
},
props: {
2019-02-18 10:18:32 +01:00
activeWindow: String,
activeChannel: Object,
networks: Array,
},
mounted() {
// Make a single throttled resize listener available to all components
this.debouncedResize = throttle(() => {
this.$root.$emit("resize");
}, 100);
window.addEventListener("resize", this.debouncedResize, {passive: true});
// Emit a daychange event every time the day changes so date markers know when to update themselves
const emitDayChange = () => {
this.$root.$emit("daychange");
// This should always be 24h later but re-computing exact value just in case
this.dayChangeTimeout = setTimeout(emitDayChange, this.msUntilNextDay());
};
this.dayChangeTimeout = setTimeout(emitDayChange, this.msUntilNextDay());
},
beforeDestroy() {
window.removeEventListener("resize", this.debouncedResize);
clearTimeout(this.dayChangeTimeout);
},
methods: {
isPublic: () => document.body.classList.contains("public"),
msUntilNextDay() {
// Compute how many milliseconds are remaining until the next day starts
const today = new Date();
const tommorow = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1);
return tommorow - today;
},
},
};
</script>