App.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <template>
  2. <div class="upper-container">
  3. <banned v-if="banned" />
  4. <div v-else class="upper-container">
  5. <router-view :key="$route.fullPath" class="main-container" />
  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. height: 100%;
  192. }
  193. body {
  194. background-color: $light-grey;
  195. color: $dark-grey;
  196. font-family: "Roboto", Helvetica, Arial, sans-serif;
  197. height: 100%;
  198. }
  199. .upper-container {
  200. height: 100%;
  201. }
  202. .main-container {
  203. height: 100%;
  204. display: flex;
  205. flex-direction: column;
  206. > .container {
  207. flex: 1 0 auto;
  208. }
  209. }
  210. a {
  211. color: $primary-color;
  212. text-decoration: none;
  213. }
  214. .modal-card {
  215. margin: 0 !important;
  216. }
  217. .absolute-a {
  218. width: 100%;
  219. height: 100%;
  220. position: absolute;
  221. top: 0;
  222. left: 0;
  223. }
  224. .alert {
  225. padding: 20px;
  226. color: $white;
  227. background-color: $red;
  228. position: fixed;
  229. top: 50px;
  230. right: 50px;
  231. font-size: 2em;
  232. border-radius: 5px;
  233. z-index: 10000000;
  234. }
  235. .tooltip {
  236. position: relative;
  237. &:after {
  238. position: absolute;
  239. min-width: 80px;
  240. margin-left: -75%;
  241. text-align: center;
  242. padding: 7.5px 6px;
  243. border-radius: 2px;
  244. background-color: $dark-grey;
  245. font-size: 0.9em;
  246. color: $white;
  247. content: attr(data-tooltip);
  248. opacity: 0;
  249. transition: all 0.2s ease-in-out 0.1s;
  250. visibility: hidden;
  251. }
  252. &:hover:after {
  253. opacity: 1;
  254. visibility: visible;
  255. }
  256. }
  257. .tooltip-top {
  258. &:after {
  259. bottom: 150%;
  260. }
  261. &:hover {
  262. &:after {
  263. bottom: 120%;
  264. }
  265. }
  266. }
  267. .tooltip-bottom {
  268. &:after {
  269. top: 155%;
  270. }
  271. &:hover {
  272. &:after {
  273. top: 125%;
  274. }
  275. }
  276. }
  277. .tooltip-left {
  278. &:after {
  279. bottom: -10px;
  280. right: 130%;
  281. min-width: 100px;
  282. }
  283. &:hover {
  284. &:after {
  285. right: 110%;
  286. }
  287. }
  288. }
  289. .tooltip-right {
  290. &:after {
  291. bottom: -10px;
  292. left: 190%;
  293. min-width: 100px;
  294. }
  295. &:hover {
  296. &:after {
  297. left: 200%;
  298. }
  299. }
  300. }
  301. .button:focus,
  302. .button:active {
  303. border-color: #dbdbdb !important;
  304. }
  305. .input:focus,
  306. .input:active {
  307. border-color: $primary-color !important;
  308. }
  309. button.delete:focus {
  310. background-color: rgba(10, 10, 10, 0.3);
  311. }
  312. .tag {
  313. padding-right: 6px !important;
  314. }
  315. .button {
  316. &.is-success {
  317. background-color: $green !important;
  318. &:hover,
  319. &:focus {
  320. background-color: darken($green, 5%) !important;
  321. }
  322. }
  323. &.is-primary {
  324. background-color: $primary-color !important;
  325. &:hover,
  326. &:focus {
  327. background-color: darken($primary-color, 5%) !important;
  328. }
  329. }
  330. &.is-danger {
  331. background-color: $red !important;
  332. &:hover,
  333. &:focus {
  334. background-color: darken($red, 5%) !important;
  335. }
  336. }
  337. &.is-info {
  338. background-color: $blue !important;
  339. &:hover,
  340. &:focus {
  341. background-color: darken($blue, 5%) !important;
  342. }
  343. }
  344. }
  345. .center {
  346. text-align: center;
  347. }
  348. </style>