App.vue 4.9 KB

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