App.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. if (_this.$route.query.err) {
  100. let err = _this.$route.query.err;
  101. err = err
  102. .replace(new RegExp("<", "g"), "&lt;")
  103. .replace(new RegExp(">", "g"), "&gt;");
  104. Toast.methods.addToast(err, 20000);
  105. }
  106. io.getSocket(true, socket => {
  107. socket.on("keep.event:user.session.removed", () => {
  108. location.reload();
  109. });
  110. });
  111. },
  112. components: {
  113. Toast,
  114. WhatIsNew,
  115. MobileAlert,
  116. LoginModal,
  117. RegisterModal,
  118. Banned
  119. }
  120. };
  121. </script>
  122. <style lang="scss">
  123. .center {
  124. text-align: center;
  125. }
  126. #toast-container {
  127. z-index: 10000 !important;
  128. }
  129. html {
  130. overflow: auto !important;
  131. a {
  132. color: #03a9f4;
  133. text-decoration: none;
  134. }
  135. }
  136. .modal-card {
  137. margin: 0 !important;
  138. }
  139. .absolute-a {
  140. width: 100%;
  141. height: 100%;
  142. position: absolute;
  143. top: 0;
  144. left: 0;
  145. }
  146. .alert {
  147. padding: 20px;
  148. color: white;
  149. background-color: red;
  150. position: fixed;
  151. top: 50px;
  152. right: 50px;
  153. font-size: 2em;
  154. border-radius: 5px;
  155. z-index: 10000000;
  156. }
  157. .tooltip {
  158. position: relative;
  159. &:after {
  160. position: absolute;
  161. min-width: 80px;
  162. margin-left: -75%;
  163. text-align: center;
  164. padding: 7.5px 6px;
  165. border-radius: 2px;
  166. background-color: #323232;
  167. font-size: 0.9em;
  168. color: #fff;
  169. content: attr(data-tooltip);
  170. opacity: 0;
  171. transition: all 0.2s ease-in-out 0.1s;
  172. visibility: hidden;
  173. }
  174. &:hover:after {
  175. opacity: 1;
  176. visibility: visible;
  177. }
  178. }
  179. .tooltip-top {
  180. &:after {
  181. bottom: 150%;
  182. }
  183. &:hover {
  184. &:after {
  185. bottom: 120%;
  186. }
  187. }
  188. }
  189. .tooltip-bottom {
  190. &:after {
  191. top: 155%;
  192. }
  193. &:hover {
  194. &:after {
  195. top: 125%;
  196. }
  197. }
  198. }
  199. .tooltip-left {
  200. &:after {
  201. bottom: -10px;
  202. right: 130%;
  203. min-width: 100px;
  204. }
  205. &:hover {
  206. &:after {
  207. right: 110%;
  208. }
  209. }
  210. }
  211. .tooltip-right {
  212. &:after {
  213. bottom: -10px;
  214. left: 190%;
  215. min-width: 100px;
  216. }
  217. &:hover {
  218. &:after {
  219. left: 200%;
  220. }
  221. }
  222. }
  223. .button:focus,
  224. .button:active {
  225. border-color: #dbdbdb !important;
  226. }
  227. .input:focus,
  228. .input:active {
  229. border-color: #03a9f4 !important;
  230. }
  231. button.delete:focus {
  232. background-color: rgba(10, 10, 10, 0.3);
  233. }
  234. .tag {
  235. padding-right: 6px !important;
  236. }
  237. .button.is-success {
  238. background-color: #00b16a !important;
  239. }
  240. </style>