App.vue 6.2 KB

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