App.vue 5.5 KB

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