2018-07-06 18:15:15 +00:00
|
|
|
<template>
|
2019-08-03 19:03:45 +00:00
|
|
|
<div id="viewport" :class="viewportClasses" role="tablist">
|
2019-11-12 11:09:12 +00:00
|
|
|
<Sidebar v-if="$store.state.appLoaded" :overlay="$refs.overlay" />
|
2019-11-07 23:47:45 +00:00
|
|
|
<div id="sidebar-overlay" ref="overlay" @click="$store.commit('sidebarOpen', false)" />
|
2019-12-04 06:58:23 +00:00
|
|
|
<router-view ref="window"></router-view>
|
2019-11-04 09:21:05 +00:00
|
|
|
<Mentions />
|
2019-09-20 18:10:48 +00:00
|
|
|
<ImageViewer ref="imageViewer" />
|
2019-11-09 22:21:34 +00:00
|
|
|
<ContextMenu ref="contextMenu" />
|
2020-02-25 09:16:05 +00:00
|
|
|
<ConfirmDialog ref="confirmDialog" />
|
2019-11-20 17:56:06 +00:00
|
|
|
<div id="upload-overlay"></div>
|
2018-07-06 18:15:15 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-12-17 22:10:50 +00:00
|
|
|
const constants = require("../js/constants");
|
2020-03-16 17:58:40 +00:00
|
|
|
import eventbus from "../js/eventbus";
|
2020-01-02 20:24:20 +00:00
|
|
|
import Mousetrap from "mousetrap";
|
2019-11-16 17:24:03 +00:00
|
|
|
import throttle from "lodash/throttle";
|
|
|
|
import storage from "../js/localStorage";
|
2020-03-17 10:00:33 +00:00
|
|
|
import isIgnoredKeybind from "../js/helpers/isIgnoredKeybind";
|
2018-08-31 18:15:46 +00:00
|
|
|
|
2019-02-22 14:21:32 +00:00
|
|
|
import Sidebar from "./Sidebar.vue";
|
2019-09-20 18:10:48 +00:00
|
|
|
import ImageViewer from "./ImageViewer.vue";
|
2019-11-09 22:21:34 +00:00
|
|
|
import ContextMenu from "./ContextMenu.vue";
|
2020-02-25 09:16:05 +00:00
|
|
|
import ConfirmDialog from "./ConfirmDialog.vue";
|
2019-11-04 09:21:05 +00:00
|
|
|
import Mentions from "./Mentions.vue";
|
2018-07-06 18:15:15 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: "App",
|
|
|
|
components: {
|
2019-02-22 14:21:32 +00:00
|
|
|
Sidebar,
|
2019-09-20 18:10:48 +00:00
|
|
|
ImageViewer,
|
2019-11-09 22:21:34 +00:00
|
|
|
ContextMenu,
|
2020-02-25 09:16:05 +00:00
|
|
|
ConfirmDialog,
|
2019-11-04 09:21:05 +00:00
|
|
|
Mentions,
|
2018-07-06 18:15:15 +00:00
|
|
|
},
|
2019-04-13 20:44:04 +00:00
|
|
|
computed: {
|
|
|
|
viewportClasses() {
|
|
|
|
return {
|
2019-11-08 00:04:25 +00:00
|
|
|
notified: this.$store.getters.highlightCount > 0,
|
2019-11-12 11:09:12 +00:00
|
|
|
"menu-open": this.$store.state.appLoaded && this.$store.state.sidebarOpen,
|
2019-08-05 12:24:44 +00:00
|
|
|
"menu-dragging": this.$store.state.sidebarDragging,
|
2019-04-13 20:44:04 +00:00
|
|
|
"userlist-open": this.$store.state.userlistOpen,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
2019-11-12 11:09:12 +00:00
|
|
|
created() {
|
|
|
|
this.prepareOpenStates();
|
|
|
|
},
|
2018-08-31 18:15:46 +00:00
|
|
|
mounted() {
|
2020-01-24 09:32:28 +00:00
|
|
|
Mousetrap.bind("esc", this.escapeKey);
|
2020-01-02 20:24:20 +00:00
|
|
|
Mousetrap.bind("alt+u", this.toggleUserList);
|
|
|
|
Mousetrap.bind("alt+s", this.toggleSidebar);
|
|
|
|
|
2018-08-31 18:15:46 +00:00
|
|
|
// Make a single throttled resize listener available to all components
|
|
|
|
this.debouncedResize = throttle(() => {
|
2020-03-16 17:58:40 +00:00
|
|
|
eventbus.emit("resize");
|
2018-08-31 18:15:46 +00:00
|
|
|
}, 100);
|
|
|
|
|
|
|
|
window.addEventListener("resize", this.debouncedResize, {passive: true});
|
2018-09-12 17:14:45 +00:00
|
|
|
|
|
|
|
// Emit a daychange event every time the day changes so date markers know when to update themselves
|
|
|
|
const emitDayChange = () => {
|
2020-03-16 17:58:40 +00:00
|
|
|
eventbus.emit("daychange");
|
2018-09-12 17:14:45 +00:00
|
|
|
// 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());
|
2018-08-31 18:15:46 +00:00
|
|
|
},
|
|
|
|
beforeDestroy() {
|
2020-01-24 09:32:28 +00:00
|
|
|
Mousetrap.unbind("esc", this.escapeKey);
|
2020-01-02 20:24:20 +00:00
|
|
|
Mousetrap.unbind("alt+u", this.toggleUserList);
|
|
|
|
Mousetrap.unbind("alt+s", this.toggleSidebar);
|
|
|
|
|
2018-08-31 18:15:46 +00:00
|
|
|
window.removeEventListener("resize", this.debouncedResize);
|
2018-09-12 17:14:45 +00:00
|
|
|
clearTimeout(this.dayChangeTimeout);
|
2018-08-31 18:15:46 +00:00
|
|
|
},
|
2018-08-31 18:37:39 +00:00
|
|
|
methods: {
|
2020-01-24 09:32:28 +00:00
|
|
|
escapeKey() {
|
2020-03-16 17:58:40 +00:00
|
|
|
eventbus.emit("escapekey");
|
2020-01-24 09:32:28 +00:00
|
|
|
},
|
2020-01-23 20:50:37 +00:00
|
|
|
toggleSidebar(e) {
|
2020-03-17 10:00:33 +00:00
|
|
|
if (isIgnoredKeybind(e)) {
|
2020-01-23 20:50:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-02 20:24:20 +00:00
|
|
|
this.$store.commit("toggleSidebar");
|
2020-01-23 20:50:37 +00:00
|
|
|
|
|
|
|
return false;
|
2020-01-02 20:24:20 +00:00
|
|
|
},
|
2020-01-23 20:50:37 +00:00
|
|
|
toggleUserList(e) {
|
2020-03-17 10:00:33 +00:00
|
|
|
if (isIgnoredKeybind(e)) {
|
2020-01-23 20:50:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-02 20:24:20 +00:00
|
|
|
this.$store.commit("toggleUserlist");
|
2020-01-23 20:50:37 +00:00
|
|
|
|
|
|
|
return false;
|
2020-01-02 20:24:20 +00:00
|
|
|
},
|
2018-09-12 17:14:45 +00:00
|
|
|
msUntilNextDay() {
|
|
|
|
// Compute how many milliseconds are remaining until the next day starts
|
2018-09-20 07:50:00 +00:00
|
|
|
const today = new Date();
|
|
|
|
const tommorow = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1);
|
|
|
|
|
|
|
|
return tommorow - today;
|
2018-09-12 17:14:45 +00:00
|
|
|
},
|
2019-11-12 11:09:12 +00:00
|
|
|
prepareOpenStates() {
|
2019-12-01 18:20:37 +00:00
|
|
|
const viewportWidth = window.innerWidth;
|
2019-11-12 11:09:12 +00:00
|
|
|
let isUserlistOpen = storage.get("thelounge.state.userlist");
|
|
|
|
|
|
|
|
if (viewportWidth > constants.mobileViewportPixels) {
|
|
|
|
this.$store.commit(
|
|
|
|
"sidebarOpen",
|
|
|
|
storage.get("thelounge.state.sidebar") !== "false"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If The Lounge is opened on a small screen (less than 1024px), and we don't have stored
|
|
|
|
// user list state, close it by default
|
|
|
|
if (viewportWidth >= 1024 && isUserlistOpen !== "true" && isUserlistOpen !== "false") {
|
|
|
|
isUserlistOpen = "true";
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$store.commit("userlistOpen", isUserlistOpen === "true");
|
|
|
|
},
|
2018-08-31 18:37:39 +00:00
|
|
|
},
|
2018-07-06 18:15:15 +00:00
|
|
|
};
|
|
|
|
</script>
|