App.vue 5.5 KB

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