App.vue 5.3 KB

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