App.vue 5.7 KB

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