App.vue 5.1 KB

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