App.vue 5.8 KB

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