App.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. userIdMap: {},
  41. currentlyGettingUsernameFrom: {}
  42. };
  43. },
  44. computed: mapState({
  45. modals: state => state.modals.modals,
  46. currentlyActive: state => state.modals.currentlyActive
  47. }),
  48. methods: {
  49. logout: function() {
  50. let _this = this;
  51. _this.socket.emit("users.logout", result => {
  52. if (result.status === "success") {
  53. document.cookie =
  54. "SID=;expires=Thu, 01 Jan 1970 00:00:01 GMT;";
  55. location.reload();
  56. } else Toast.methods.addToast(result.message, 4000);
  57. });
  58. },
  59. submitOnEnter: (cb, event) => {
  60. if (event.which == 13) cb();
  61. },
  62. getUsernameFromId: function(userId) {
  63. // refactor
  64. if (
  65. typeof this.userIdMap[userId] !== "string" &&
  66. !this.currentlyGettingUsernameFrom[userId]
  67. ) {
  68. this.currentlyGettingUsernameFrom[userId] = true;
  69. io.getSocket(socket => {
  70. socket.emit("users.getUsernameFromId", userId, res => {
  71. if (res.status === "success") {
  72. this.$set(this.userIdMap, `Z${userId}`, res.data);
  73. }
  74. this.currentlyGettingUsernameFrom[userId] = false;
  75. });
  76. });
  77. }
  78. },
  79. ...mapActions("modals", ["closeCurrentModal"])
  80. },
  81. mounted: function() {
  82. document.onkeydown = event => {
  83. event = event || window.event;
  84. if (
  85. event.keyCode === 27 &&
  86. Object.keys(this.currentlyActive).length !== 0
  87. )
  88. this.closeCurrentModal();
  89. };
  90. let _this = this;
  91. if (localStorage.getItem("github_redirect")) {
  92. this.$router.go(localStorage.getItem("github_redirect"));
  93. localStorage.removeItem("github_redirect");
  94. }
  95. auth.isBanned((banned, ban) => {
  96. _this.ban = ban;
  97. _this.banned = banned;
  98. });
  99. auth.getStatus((authenticated, role, username, userId) => {
  100. _this.socket = window.socket;
  101. _this.loggedIn = authenticated;
  102. _this.role = role;
  103. _this.username = username;
  104. _this.userId = userId;
  105. });
  106. io.onConnect(true, () => {
  107. _this.socketConnected = true;
  108. });
  109. io.onConnectError(true, () => {
  110. _this.socketConnected = false;
  111. });
  112. io.onDisconnect(true, () => {
  113. _this.socketConnected = false;
  114. });
  115. lofig.get("serverDomain", res => {
  116. _this.serverDomain = res;
  117. });
  118. if (_this.$route.query.err) {
  119. let err = _this.$route.query.err;
  120. err = err
  121. .replace(new RegExp("<", "g"), "&lt;")
  122. .replace(new RegExp(">", "g"), "&gt;");
  123. Toast.methods.addToast(err, 20000);
  124. }
  125. io.getSocket(true, socket => {
  126. socket.on("keep.event:user.session.removed", () => {
  127. location.reload();
  128. });
  129. });
  130. },
  131. components: {
  132. Toast,
  133. WhatIsNew,
  134. MobileAlert,
  135. LoginModal,
  136. RegisterModal,
  137. Banned
  138. }
  139. };
  140. </script>
  141. <style lang="scss">
  142. .center {
  143. text-align: center;
  144. }
  145. #toast-container {
  146. z-index: 10000 !important;
  147. }
  148. html {
  149. overflow: auto !important;
  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: #323232;
  182. font-size: 0.9em;
  183. color: #fff;
  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: #03a9f4 !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.is-success {
  253. background-color: #00b16a !important;
  254. }
  255. </style>