App.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <template>
  2. <div class="upper-container">
  3. <banned v-if="banned" />
  4. <div v-else class="upper-container">
  5. <router-view :key="$route.fullPath" class="main-container" />
  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. import keyboardShortcuts from "./keyboardShortcuts";
  23. export default {
  24. replace: false,
  25. data() {
  26. return {
  27. serverDomain: "",
  28. socketConnected: true,
  29. keyIsDown: false
  30. };
  31. },
  32. computed: mapState({
  33. loggedIn: state => state.user.auth.loggedIn,
  34. role: state => state.user.auth.role,
  35. username: state => state.user.auth.username,
  36. userId: state => state.user.auth.userId,
  37. banned: state => state.user.auth.banned,
  38. modals: state => state.modals.modals,
  39. currentlyActive: state => state.modals.currentlyActive,
  40. nightmode: state => state.user.preferences.nightmode
  41. }),
  42. methods: {
  43. submitOnEnter: (cb, event) => {
  44. if (event.which === 13) cb();
  45. },
  46. enableNightMode: () => {
  47. document
  48. .getElementsByTagName("body")[0]
  49. .classList.add("night-mode");
  50. },
  51. disableNightMode: () => {
  52. document
  53. .getElementsByTagName("body")[0]
  54. .classList.remove("night-mode");
  55. },
  56. ...mapActions("modals", ["closeCurrentModal"]),
  57. ...mapActions("user/preferences", ["changeNightmode"])
  58. },
  59. watch: {
  60. socketConnected(connected) {
  61. console.log(connected);
  62. if (!connected)
  63. new Toast({
  64. content: "Could not connect to the server.",
  65. persistant: true
  66. });
  67. else {
  68. // better implementation once vue-roaster is updated
  69. document
  70. .getElementById("toasts-content")
  71. .childNodes.forEach(toast => {
  72. if (
  73. toast.innerHTML ===
  74. "Could not connect to the server."
  75. ) {
  76. toast.remove();
  77. }
  78. });
  79. }
  80. },
  81. nightmode(nightmode) {
  82. if (nightmode) this.enableNightMode();
  83. else this.disableNightMode();
  84. }
  85. },
  86. beforeMount() {
  87. const nightmode =
  88. false || JSON.parse(localStorage.getItem("nightmode"));
  89. this.changeNightmode(nightmode);
  90. if (nightmode) this.enableNightMode();
  91. else this.disableNightMode();
  92. },
  93. mounted() {
  94. document.onkeydown = ev => {
  95. const event = ev || window.event;
  96. const { keyCode } = event;
  97. const shift = event.shiftKey;
  98. const ctrl = event.ctrlKey;
  99. const alt = event.altKey;
  100. const identifier = `${keyCode}.${shift}.${ctrl}`;
  101. if (this.keyIsDown === identifier) return;
  102. this.keyIsDown = identifier;
  103. keyboardShortcuts.handleKeyDown(event, keyCode, shift, ctrl, alt);
  104. };
  105. document.onkeyup = () => {
  106. this.keyIsDown = "";
  107. };
  108. keyboardShortcuts.registerShortcut("closeModal", {
  109. keyCode: 27,
  110. shift: false,
  111. ctrl: false,
  112. handler: () => {
  113. if (Object.keys(this.currentlyActive).length !== 0)
  114. this.closeCurrentModal();
  115. }
  116. });
  117. if (localStorage.getItem("github_redirect")) {
  118. this.$router.go(localStorage.getItem("github_redirect"));
  119. localStorage.removeItem("github_redirect");
  120. }
  121. io.onConnect(true, () => {
  122. this.socketConnected = true;
  123. });
  124. io.onConnectError(true, () => {
  125. this.socketConnected = false;
  126. });
  127. io.onDisconnect(true, () => {
  128. this.socketConnected = false;
  129. });
  130. lofig.get("serverDomain").then(serverDomain => {
  131. this.serverDomain = serverDomain;
  132. });
  133. this.$router.onReady(() => {
  134. if (this.$route.query.err) {
  135. let { err } = this.$route.query;
  136. err = err
  137. .replace(new RegExp("<", "g"), "&lt;")
  138. .replace(new RegExp(">", "g"), "&gt;");
  139. this.$router.push({ query: {} });
  140. new Toast({ content: err, timeout: 20000 });
  141. }
  142. if (this.$route.query.msg) {
  143. let { msg } = this.$route.query;
  144. msg = msg
  145. .replace(new RegExp("<", "g"), "&lt;")
  146. .replace(new RegExp(">", "g"), "&gt;");
  147. this.$router.push({ query: {} });
  148. new Toast({ content: msg, timeout: 20000 });
  149. }
  150. });
  151. io.getSocket(true, socket => {
  152. socket.on("keep.event:user.session.removed", () => {
  153. window.location.reload();
  154. });
  155. });
  156. },
  157. components: {
  158. WhatIsNew,
  159. MobileAlert,
  160. LoginModal,
  161. RegisterModal,
  162. Banned
  163. }
  164. };
  165. </script>
  166. <style lang="scss">
  167. @import "styles/global.scss";
  168. .night-mode {
  169. div {
  170. // background-color: #000;
  171. color: #ddd;
  172. }
  173. #toasts-container .toast {
  174. background-color: #ddd;
  175. color: #333;
  176. }
  177. }
  178. body.night-mode {
  179. background-color: #000 !important;
  180. }
  181. #toasts-container {
  182. z-index: 10000 !important;
  183. .toast {
  184. font-weight: 600;
  185. }
  186. }
  187. .toast:not(:first-of-type) {
  188. margin-top: 5px;
  189. }
  190. html {
  191. overflow: auto !important;
  192. height: 100%;
  193. }
  194. body {
  195. background-color: $light-grey;
  196. color: $dark-grey;
  197. height: 100%;
  198. font-family: "Karla", Helvetica, Arial, sans-serif;
  199. }
  200. h1,
  201. h2,
  202. h3,
  203. h4,
  204. h5,
  205. h6,
  206. .sidebar-title {
  207. font-family: "Hind", Helvetica, Arial, sans-serif;
  208. }
  209. .modal-card-title {
  210. font-weight: 600;
  211. font-family: "Hind", Helvetica, Arial, sans-serif;
  212. }
  213. p,
  214. button,
  215. input,
  216. select,
  217. textarea {
  218. font-family: "Karla", Helvetica, Arial, sans-serif;
  219. }
  220. .upper-container {
  221. height: 100%;
  222. }
  223. .main-container {
  224. height: 100%;
  225. display: flex;
  226. flex-direction: column;
  227. > .container {
  228. flex: 1 0 auto;
  229. }
  230. }
  231. a {
  232. color: $primary-color;
  233. text-decoration: none;
  234. }
  235. .modal-card {
  236. margin: 0 !important;
  237. }
  238. .absolute-a {
  239. width: 100%;
  240. height: 100%;
  241. position: absolute;
  242. top: 0;
  243. left: 0;
  244. }
  245. .alert {
  246. padding: 20px;
  247. color: $white;
  248. background-color: $red;
  249. position: fixed;
  250. top: 50px;
  251. right: 50px;
  252. font-size: 2em;
  253. border-radius: 5px;
  254. z-index: 10000000;
  255. }
  256. .tooltip {
  257. position: relative;
  258. &:after {
  259. position: absolute;
  260. min-width: 80px;
  261. margin-left: -75%;
  262. text-align: center;
  263. padding: 7.5px 6px;
  264. border-radius: 2px;
  265. background-color: $dark-grey;
  266. font-size: 0.9em;
  267. color: $white;
  268. content: attr(data-tooltip);
  269. opacity: 0;
  270. transition: all 0.2s ease-in-out 0.1s;
  271. visibility: hidden;
  272. }
  273. &:hover:after {
  274. opacity: 1;
  275. visibility: visible;
  276. }
  277. }
  278. .tooltip-top {
  279. &:after {
  280. bottom: 150%;
  281. }
  282. &:hover {
  283. &:after {
  284. bottom: 120%;
  285. }
  286. }
  287. }
  288. .tooltip-bottom {
  289. &:after {
  290. top: 155%;
  291. }
  292. &:hover {
  293. &:after {
  294. top: 125%;
  295. }
  296. }
  297. }
  298. .tooltip-left {
  299. &:after {
  300. bottom: -10px;
  301. right: 130%;
  302. min-width: 100px;
  303. }
  304. &:hover {
  305. &:after {
  306. right: 110%;
  307. }
  308. }
  309. }
  310. .tooltip-right {
  311. &:after {
  312. bottom: -10px;
  313. left: 190%;
  314. min-width: 100px;
  315. }
  316. &:hover {
  317. &:after {
  318. left: 200%;
  319. }
  320. }
  321. }
  322. .button:focus,
  323. .button:active {
  324. border-color: #dbdbdb !important;
  325. }
  326. .input:focus,
  327. .input:active {
  328. border-color: $primary-color !important;
  329. }
  330. button.delete:focus {
  331. background-color: rgba(10, 10, 10, 0.3);
  332. }
  333. .tag {
  334. padding-right: 6px !important;
  335. }
  336. .button {
  337. &.is-success {
  338. background-color: $green !important;
  339. &:hover,
  340. &:focus {
  341. background-color: darken($green, 5%) !important;
  342. }
  343. }
  344. &.is-primary {
  345. background-color: $primary-color !important;
  346. &:hover,
  347. &:focus {
  348. background-color: darken($primary-color, 5%) !important;
  349. }
  350. }
  351. &.is-danger {
  352. background-color: $red !important;
  353. &:hover,
  354. &:focus {
  355. background-color: darken($red, 5%) !important;
  356. }
  357. }
  358. &.is-info {
  359. background-color: $blue !important;
  360. &:hover,
  361. &:focus {
  362. background-color: darken($blue, 5%) !important;
  363. }
  364. }
  365. }
  366. .page-title {
  367. margin: 0 0 50px 0;
  368. }
  369. .icon-with-button {
  370. margin-right: 3px;
  371. font-size: 18px;
  372. }
  373. .modal-section-title {
  374. font-size: 26px;
  375. margin: 0px;
  376. }
  377. .modal-section-description {
  378. margin-bottom: 5px;
  379. }
  380. </style>