2018-07-06 18:15:15 +00:00
|
|
|
<template>
|
2019-08-03 19:03:45 +00:00
|
|
|
<div id="viewport" :class="viewportClasses" role="tablist">
|
2022-06-19 00:25:21 +00:00
|
|
|
<Sidebar v-if="store.state.appLoaded" :overlay="overlay" />
|
2021-04-21 01:04:31 +00:00
|
|
|
<div
|
|
|
|
id="sidebar-overlay"
|
|
|
|
ref="overlay"
|
2021-07-01 19:14:02 +00:00
|
|
|
aria-hidden="true"
|
2022-06-19 00:25:21 +00:00
|
|
|
@click="store.commit('sidebarOpen', false)"
|
2021-04-21 01:04:31 +00:00
|
|
|
/>
|
2022-06-19 00:25:21 +00:00
|
|
|
<router-view ref="loungeWindow"></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>
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import constants from "../js/constants";
|
2020-03-16 17:58:40 +00:00
|
|
|
import eventbus from "../js/eventbus";
|
2022-06-19 00:25:21 +00:00
|
|
|
import Mousetrap, {ExtendedKeyboardEvent} 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";
|
2022-06-19 00:25:21 +00:00
|
|
|
import {
|
|
|
|
computed,
|
|
|
|
provide,
|
|
|
|
defineComponent,
|
|
|
|
onBeforeUnmount,
|
|
|
|
onMounted,
|
|
|
|
ref,
|
|
|
|
Ref,
|
|
|
|
InjectionKey,
|
|
|
|
} from "vue";
|
|
|
|
import {useStore} from "../js/store";
|
|
|
|
import type {DebouncedFunc} from "lodash";
|
|
|
|
|
|
|
|
export const imageViewerKey = Symbol() as InjectionKey<Ref<typeof ImageViewer | null>>;
|
|
|
|
const contextMenuKey = Symbol() as InjectionKey<Ref<typeof ContextMenu | null>>;
|
|
|
|
const confirmDialogKey = Symbol() as InjectionKey<Ref<typeof ConfirmDialog | null>>;
|
|
|
|
|
|
|
|
export default defineComponent({
|
2018-07-06 18:15:15 +00:00
|
|
|
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
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
setup() {
|
|
|
|
const store = useStore();
|
|
|
|
const overlay = ref(null);
|
|
|
|
const loungeWindow = ref(null);
|
|
|
|
const imageViewer = ref(null);
|
|
|
|
const contextMenu = ref(null);
|
|
|
|
const confirmDialog = ref(null);
|
|
|
|
|
|
|
|
provide(imageViewerKey, imageViewer);
|
|
|
|
provide(contextMenuKey, contextMenu);
|
|
|
|
provide(confirmDialogKey, confirmDialog);
|
|
|
|
|
|
|
|
const viewportClasses = computed(() => {
|
2019-04-13 20:44:04 +00:00
|
|
|
return {
|
2022-06-19 00:25:21 +00:00
|
|
|
notified: store.getters.highlightCount > 0,
|
|
|
|
"menu-open": store.state.appLoaded && store.state.sidebarOpen,
|
|
|
|
"menu-dragging": store.state.sidebarDragging,
|
|
|
|
"userlist-open": store.state.userlistOpen,
|
2019-04-13 20:44:04 +00:00
|
|
|
};
|
2022-06-19 00:25:21 +00:00
|
|
|
});
|
2018-09-12 17:14:45 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const debouncedResize = ref<DebouncedFunc<() => void>>();
|
|
|
|
const dayChangeTimeout = ref<any>();
|
|
|
|
|
|
|
|
const escapeKey = () => {
|
2020-03-16 17:58:40 +00:00
|
|
|
eventbus.emit("escapekey");
|
2022-06-19 00:25:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const toggleSidebar = (e: ExtendedKeyboardEvent) => {
|
2020-03-17 10:00:33 +00:00
|
|
|
if (isIgnoredKeybind(e)) {
|
2020-01-23 20:50:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
store.commit("toggleSidebar");
|
2020-01-23 20:50:37 +00:00
|
|
|
|
|
|
|
return false;
|
2022-06-19 00:25:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const toggleUserList = (e: ExtendedKeyboardEvent) => {
|
2020-03-17 10:00:33 +00:00
|
|
|
if (isIgnoredKeybind(e)) {
|
2020-01-23 20:50:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
store.commit("toggleUserlist");
|
2020-01-23 20:50:37 +00:00
|
|
|
|
|
|
|
return false;
|
2022-06-19 00:25:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const toggleMentions = () => {
|
|
|
|
if (store.state.networks.length !== 0) {
|
2021-06-12 23:49:23 +00:00
|
|
|
eventbus.emit("mentions:toggle");
|
|
|
|
}
|
2022-06-19 00:25:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const msUntilNextDay = () => {
|
2018-09-12 17:14:45 +00:00
|
|
|
// Compute how many milliseconds are remaining until the next day starts
|
2018-09-20 07:50:00 +00:00
|
|
|
const today = new Date();
|
2022-06-19 00:25:21 +00:00
|
|
|
const tommorow = new Date(
|
|
|
|
today.getFullYear(),
|
|
|
|
today.getMonth(),
|
|
|
|
today.getDate() + 1
|
|
|
|
).getTime();
|
|
|
|
|
|
|
|
return tommorow - today.getTime();
|
|
|
|
};
|
2018-09-20 07:50:00 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const 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) {
|
2022-06-19 00:25:21 +00:00
|
|
|
store.commit("sidebarOpen", storage.get("thelounge.state.sidebar") !== "false");
|
2019-11-12 11:09:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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";
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
store.commit("userlistOpen", isUserlistOpen === "true");
|
|
|
|
};
|
|
|
|
|
|
|
|
prepareOpenStates();
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
Mousetrap.bind("esc", escapeKey);
|
|
|
|
Mousetrap.bind("alt+u", toggleUserList);
|
|
|
|
Mousetrap.bind("alt+s", toggleSidebar);
|
|
|
|
Mousetrap.bind("alt+m", toggleMentions);
|
|
|
|
|
|
|
|
debouncedResize.value = throttle(() => {
|
|
|
|
eventbus.emit("resize");
|
|
|
|
}, 100);
|
|
|
|
|
|
|
|
window.addEventListener("resize", debouncedResize.value, {passive: true});
|
|
|
|
|
|
|
|
// Emit a daychange event every time the day changes so date markers know when to update themselves
|
|
|
|
const emitDayChange = () => {
|
|
|
|
eventbus.emit("daychange");
|
|
|
|
// This should always be 24h later but re-computing exact value just in case
|
|
|
|
dayChangeTimeout.value = setTimeout(emitDayChange, msUntilNextDay());
|
|
|
|
};
|
|
|
|
|
|
|
|
dayChangeTimeout.value = setTimeout(emitDayChange, msUntilNextDay());
|
|
|
|
});
|
|
|
|
|
|
|
|
onBeforeUnmount(() => {
|
|
|
|
Mousetrap.unbind("esc");
|
|
|
|
Mousetrap.unbind("alt+u");
|
|
|
|
Mousetrap.unbind("alt+s");
|
|
|
|
Mousetrap.unbind("alt+m");
|
|
|
|
|
|
|
|
if (debouncedResize.value) {
|
|
|
|
window.removeEventListener("resize", debouncedResize.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dayChangeTimeout.value) {
|
|
|
|
clearTimeout(dayChangeTimeout.value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
viewportClasses,
|
|
|
|
escapeKey,
|
|
|
|
toggleSidebar,
|
|
|
|
toggleUserList,
|
|
|
|
toggleMentions,
|
|
|
|
store,
|
|
|
|
overlay,
|
|
|
|
loungeWindow,
|
|
|
|
imageViewer,
|
|
|
|
contextMenu,
|
|
|
|
confirmDialog,
|
|
|
|
};
|
2018-08-31 18:37:39 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
});
|
2018-07-06 18:15:15 +00:00
|
|
|
</script>
|