App.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <template>
  2. <div>
  3. <banned v-if="banned" />
  4. <div v-else>
  5. <router-view :key="$route.fullPath" />
  6. <what-is-new />
  7. <mobile-alert />
  8. <login-modal v-if="modals.header.login" />
  9. <register-modal v-if="modals.header.register" />
  10. </div>
  11. </div>
  12. </template>
  13. <script>
  14. import { mapState, mapActions } from "vuex";
  15. import Toast from "toasters";
  16. import Banned from "./components/pages/Banned.vue";
  17. import WhatIsNew from "./components/Modals/WhatIsNew.vue";
  18. import MobileAlert from "./components/Modals/MobileAlert.vue";
  19. import LoginModal from "./components/Modals/Login.vue";
  20. import RegisterModal from "./components/Modals/Register.vue";
  21. import io from "./io";
  22. import keyboardShortcuts from "./keyboardShortcuts";
  23. export default {
  24. replace: false,
  25. data() {
  26. return {
  27. serverDomain: "",
  28. socketConnected: true,
  29. keyIsDown: false
  30. };
  31. },
  32. computed: mapState({
  33. loggedIn: state => state.user.auth.loggedIn,
  34. role: state => state.user.auth.role,
  35. username: state => state.user.auth.username,
  36. userId: state => state.user.auth.userId,
  37. banned: state => state.user.auth.banned,
  38. modals: state => state.modals.modals,
  39. currentlyActive: state => state.modals.currentlyActive,
  40. nightmode: state => state.user.preferences.nightmode
  41. }),
  42. methods: {
  43. submitOnEnter: (cb, event) => {
  44. if (event.which === 13) cb();
  45. },
  46. enableNightMode: () => {
  47. document
  48. .getElementsByTagName("body")[0]
  49. .classList.add("night-mode");
  50. },
  51. disableNightMode: () => {
  52. document
  53. .getElementsByTagName("body")[0]
  54. .classList.remove("night-mode");
  55. },
  56. ...mapActions("modals", ["closeCurrentModal"]),
  57. ...mapActions("user/preferences", ["changeNightmode"])
  58. },
  59. watch: {
  60. socketConnected: connected => {
  61. console.log(connected);
  62. if (!connected)
  63. new Toast({
  64. content: "Could not connect to the server.",
  65. persistant: true
  66. });
  67. else {
  68. // better implementation once vue-roaster is updated
  69. document
  70. .getElementById("toasts-content")
  71. .childNodes.forEach(toast => {
  72. if (
  73. toast.innerHTML ===
  74. "Could not connect to the server."
  75. ) {
  76. toast.remove();
  77. }
  78. });
  79. }
  80. },
  81. nightmode(nightmode) {
  82. if (nightmode) this.enableNightMode();
  83. else this.disableNightMode();
  84. }
  85. },
  86. beforeMount() {
  87. const nightmode =
  88. false || JSON.parse(localStorage.getItem("nightmode"));
  89. this.changeNightmode(nightmode);
  90. if (nightmode) this.enableNightMode();
  91. else this.disableNightMode();
  92. },
  93. mounted() {
  94. document.onkeydown = ev => {
  95. const event = ev || window.event;
  96. const { keyCode } = event;
  97. const shift = event.shiftKey;
  98. const ctrl = event.ctrlKey;
  99. const identifier = `${keyCode}.${shift}.${ctrl}`;
  100. if (this.keyIsDown === identifier) return;
  101. this.keyIsDown = identifier;
  102. keyboardShortcuts.handleKeyDown(keyCode, shift, ctrl);
  103. };
  104. document.onkeyup = () => {
  105. this.keyIsDown = "";
  106. };
  107. keyboardShortcuts.registerShortcut("closeModal", {
  108. keyCode: 27,
  109. shift: false,
  110. ctrl: false,
  111. handler: () => {
  112. if (Object.keys(this.currentlyActive).length !== 0)
  113. this.closeCurrentModal();
  114. }
  115. });
  116. if (localStorage.getItem("github_redirect")) {
  117. this.$router.go(localStorage.getItem("github_redirect"));
  118. localStorage.removeItem("github_redirect");
  119. }
  120. io.onConnect(true, () => {
  121. this.socketConnected = true;
  122. });
  123. io.onConnectError(true, () => {
  124. this.socketConnected = false;
  125. });
  126. io.onDisconnect(true, () => {
  127. this.socketConnected = false;
  128. });
  129. lofig.get("serverDomain").then(serverDomain => {
  130. this.serverDomain = serverDomain;
  131. });
  132. this.$router.onReady(() => {
  133. if (this.$route.query.err) {
  134. let { err } = this.$route.query;
  135. err = err
  136. .replace(new RegExp("<", "g"), "&lt;")
  137. .replace(new RegExp(">", "g"), "&gt;");
  138. this.$router.push({ query: {} });
  139. new Toast({ content: err, timeout: 20000 });
  140. }
  141. if (this.$route.query.msg) {
  142. let { msg } = this.$route.query;
  143. msg = msg
  144. .replace(new RegExp("<", "g"), "&lt;")
  145. .replace(new RegExp(">", "g"), "&gt;");
  146. this.$router.push({ query: {} });
  147. new Toast({ content: msg, timeout: 20000 });
  148. }
  149. });
  150. io.getSocket(true, socket => {
  151. socket.on("keep.event:user.session.removed", () => {
  152. window.location.reload();
  153. });
  154. });
  155. },
  156. components: {
  157. WhatIsNew,
  158. MobileAlert,
  159. LoginModal,
  160. RegisterModal,
  161. Banned
  162. }
  163. };
  164. </script>
  165. <style lang="scss">
  166. @import "styles/global.scss";
  167. .night-mode {
  168. div {
  169. // background-color: #000;
  170. color: #ddd;
  171. }
  172. #toasts-container .toast {
  173. background-color: #ddd;
  174. color: #333;
  175. }
  176. }
  177. body.night-mode {
  178. background-color: #000 !important;
  179. }
  180. #toasts-container {
  181. z-index: 10000 !important;
  182. .toast {
  183. font-weight: 600;
  184. }
  185. }
  186. .toast:not(:first-of-type) {
  187. margin-top: 5px;
  188. }
  189. html {
  190. overflow: auto !important;
  191. }
  192. body {
  193. background-color: $light-grey;
  194. color: $dark-grey;
  195. font-family: "Roboto", Helvetica, Arial, sans-serif;
  196. }
  197. a {
  198. color: $primary-color;
  199. text-decoration: none;
  200. }
  201. .modal-card {
  202. margin: 0 !important;
  203. }
  204. .absolute-a {
  205. width: 100%;
  206. height: 100%;
  207. position: absolute;
  208. top: 0;
  209. left: 0;
  210. }
  211. .alert {
  212. padding: 20px;
  213. color: $white;
  214. background-color: $red;
  215. position: fixed;
  216. top: 50px;
  217. right: 50px;
  218. font-size: 2em;
  219. border-radius: 5px;
  220. z-index: 10000000;
  221. }
  222. .tooltip {
  223. position: relative;
  224. &:after {
  225. position: absolute;
  226. min-width: 80px;
  227. margin-left: -75%;
  228. text-align: center;
  229. padding: 7.5px 6px;
  230. border-radius: 2px;
  231. background-color: $dark-grey;
  232. font-size: 0.9em;
  233. color: $white;
  234. content: attr(data-tooltip);
  235. opacity: 0;
  236. transition: all 0.2s ease-in-out 0.1s;
  237. visibility: hidden;
  238. }
  239. &:hover:after {
  240. opacity: 1;
  241. visibility: visible;
  242. }
  243. }
  244. .tooltip-top {
  245. &:after {
  246. bottom: 150%;
  247. }
  248. &:hover {
  249. &:after {
  250. bottom: 120%;
  251. }
  252. }
  253. }
  254. .tooltip-bottom {
  255. &:after {
  256. top: 155%;
  257. }
  258. &:hover {
  259. &:after {
  260. top: 125%;
  261. }
  262. }
  263. }
  264. .tooltip-left {
  265. &:after {
  266. bottom: -10px;
  267. right: 130%;
  268. min-width: 100px;
  269. }
  270. &:hover {
  271. &:after {
  272. right: 110%;
  273. }
  274. }
  275. }
  276. .tooltip-right {
  277. &:after {
  278. bottom: -10px;
  279. left: 190%;
  280. min-width: 100px;
  281. }
  282. &:hover {
  283. &:after {
  284. left: 200%;
  285. }
  286. }
  287. }
  288. .button:focus,
  289. .button:active {
  290. border-color: #dbdbdb !important;
  291. }
  292. .input:focus,
  293. .input:active {
  294. border-color: $primary-color !important;
  295. }
  296. button.delete:focus {
  297. background-color: rgba(10, 10, 10, 0.3);
  298. }
  299. .tag {
  300. padding-right: 6px !important;
  301. }
  302. .button {
  303. &.is-success {
  304. background-color: $green !important;
  305. &:hover,
  306. &:focus {
  307. background-color: darken($green, 5%) !important;
  308. }
  309. }
  310. &.is-primary {
  311. background-color: $primary-color !important;
  312. &:hover,
  313. &:focus {
  314. background-color: darken($primary-color, 5%) !important;
  315. }
  316. }
  317. &.is-danger {
  318. background-color: $red !important;
  319. &:hover,
  320. &:focus {
  321. background-color: darken($red, 5%) !important;
  322. }
  323. }
  324. &.is-info {
  325. background-color: $blue !important;
  326. &:hover,
  327. &:focus {
  328. background-color: darken($blue, 5%) !important;
  329. }
  330. }
  331. }
  332. .center {
  333. text-align: center;
  334. }
  335. </style>