hardlounge/client/js/vue.js

80 lines
1.7 KiB
JavaScript
Raw Normal View History

"use strict";
2019-11-16 17:24:03 +00:00
import Vue from "vue";
import store from "./store";
import App from "../components/App.vue";
import localetime from "./helpers/localetime";
import storage from "./localStorage";
import {router, navigate} from "./router";
import constants from "./constants";
import socket from "./socket";
Vue.filter("localetime", localetime);
2019-11-16 17:24:03 +00:00
import "./socket-events";
import "./webpush";
import "./keybinds";
2019-11-12 15:51:40 +00:00
const favicon = document.getElementById("favicon");
const faviconNormal = favicon.getAttribute("href");
const faviconAlerted = favicon.dataset.other;
const vueApp = new Vue({
el: "#viewport",
2019-10-17 16:56:44 +00:00
router,
2018-07-10 09:40:55 +00:00
mounted() {
2019-11-12 15:51:40 +00:00
socket.open();
2018-07-10 09:40:55 +00:00
},
methods: {
2019-10-25 21:37:40 +00:00
switchToChannel(channel) {
2019-11-11 19:18:55 +00:00
navigate("RoutedChat", {id: channel.id});
2019-10-17 16:56:44 +00:00
},
},
render(createElement) {
return createElement(App, {
2019-02-18 09:18:32 +00:00
ref: "app",
props: this,
});
},
store,
});
store.watch(
(state) => state.sidebarOpen,
(sidebarOpen) => {
if (window.outerWidth > constants.mobileViewportPixels) {
storage.set("thelounge.state.sidebar", sidebarOpen);
}
vueApp.$emit("resize");
}
);
store.watch(
(state) => state.userlistOpen,
(userlistOpen) => {
storage.set("thelounge.state.userlist", userlistOpen);
vueApp.$emit("resize");
}
);
store.watch(
(_, getters) => getters.title,
(title) => {
document.title = title;
}
);
// Toggles the favicon to red when there are unread notifications
store.watch(
(_, getters) => getters.highlightCount,
(highlightCount) => {
favicon.setAttribute("href", highlightCount > 0 ? faviconAlerted : faviconNormal);
}
);
2018-09-14 15:44:26 +00:00
Vue.config.errorHandler = function(e) {
store.commit("currentUserVisibleError", `Vue error: ${e.message}`);
2018-09-14 15:44:26 +00:00
console.error(e); // eslint-disable-line
};