App.vue 6.4 KB

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