App.vue 9.2 KB

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