App.vue 5.9 KB

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