App.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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. 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. color: #333;
  175. background-color: $light-grey-2 !important;
  176. &:last-of-type {
  177. background-color: $light-grey !important;
  178. }
  179. }
  180. }
  181. body.night-mode {
  182. background-color: #000 !important;
  183. }
  184. #toasts-container {
  185. z-index: 10000 !important;
  186. .toast {
  187. font-weight: 600;
  188. background-color: $dark-grey !important;
  189. &:last-of-type {
  190. background-color: $dark-grey-2 !important;
  191. }
  192. }
  193. }
  194. html {
  195. overflow: auto !important;
  196. height: 100%;
  197. }
  198. body {
  199. background-color: $light-grey;
  200. color: $dark-grey;
  201. height: 100%;
  202. font-family: "Karla", Helvetica, Arial, sans-serif;
  203. }
  204. h1,
  205. h2,
  206. h3,
  207. h4,
  208. h5,
  209. h6,
  210. .sidebar-title {
  211. font-family: "Hind", Helvetica, Arial, sans-serif;
  212. }
  213. .modal-card-title {
  214. font-weight: 600;
  215. font-family: "Hind", Helvetica, Arial, sans-serif;
  216. }
  217. p,
  218. button,
  219. input,
  220. select,
  221. textarea {
  222. font-family: "Karla", Helvetica, Arial, sans-serif;
  223. }
  224. .upper-container {
  225. height: 100%;
  226. }
  227. .main-container {
  228. height: 100%;
  229. display: flex;
  230. flex-direction: column;
  231. > .container {
  232. flex: 1 0 auto;
  233. }
  234. }
  235. a {
  236. color: $primary-color;
  237. text-decoration: none;
  238. }
  239. .modal-card {
  240. margin: 0 !important;
  241. }
  242. .absolute-a {
  243. width: 100%;
  244. height: 100%;
  245. position: absolute;
  246. top: 0;
  247. left: 0;
  248. }
  249. .alert {
  250. padding: 20px;
  251. color: $white;
  252. background-color: $red;
  253. position: fixed;
  254. top: 50px;
  255. right: 50px;
  256. font-size: 2em;
  257. border-radius: 5px;
  258. z-index: 10000000;
  259. }
  260. .tooltip {
  261. position: relative;
  262. &:after {
  263. position: absolute;
  264. min-width: 80px;
  265. margin-left: -75%;
  266. text-align: center;
  267. padding: 7.5px 6px;
  268. border-radius: 2px;
  269. background-color: $dark-grey;
  270. font-size: 0.9em;
  271. color: $white;
  272. content: attr(data-tooltip);
  273. opacity: 0;
  274. transition: all 0.2s ease-in-out 0.1s;
  275. visibility: hidden;
  276. }
  277. &:hover:after {
  278. opacity: 1;
  279. visibility: visible;
  280. }
  281. }
  282. .tooltip-top {
  283. &:after {
  284. bottom: 150%;
  285. }
  286. &:hover {
  287. &:after {
  288. bottom: 120%;
  289. }
  290. }
  291. }
  292. .tooltip-bottom {
  293. &:after {
  294. top: 155%;
  295. }
  296. &:hover {
  297. &:after {
  298. top: 125%;
  299. }
  300. }
  301. }
  302. .tooltip-left {
  303. &:after {
  304. bottom: -10px;
  305. right: 130%;
  306. min-width: 100px;
  307. }
  308. &:hover {
  309. &:after {
  310. right: 110%;
  311. }
  312. }
  313. }
  314. .tooltip-right {
  315. &:after {
  316. bottom: -10px;
  317. left: 190%;
  318. min-width: 100px;
  319. }
  320. &:hover {
  321. &:after {
  322. left: 200%;
  323. }
  324. }
  325. }
  326. .select {
  327. &:after {
  328. border-color: $musare-blue;
  329. border-width: 1.5px;
  330. margin-top: -3px;
  331. }
  332. select {
  333. height: 36px;
  334. }
  335. }
  336. .button:focus,
  337. .button:active {
  338. border-color: #dbdbdb !important;
  339. }
  340. .input:focus,
  341. .input:active,
  342. .textarea:focus,
  343. .textarea:active,
  344. .select select:focus,
  345. .select select:active {
  346. border-color: $primary-color !important;
  347. }
  348. button.delete:focus {
  349. background-color: rgba(10, 10, 10, 0.3);
  350. }
  351. .tag {
  352. padding-right: 6px !important;
  353. }
  354. .button {
  355. &.is-success {
  356. background-color: $green !important;
  357. &:hover,
  358. &:focus {
  359. background-color: darken($green, 5%) !important;
  360. }
  361. }
  362. &.is-primary {
  363. background-color: $primary-color !important;
  364. &:hover,
  365. &:focus {
  366. background-color: darken($primary-color, 5%) !important;
  367. }
  368. }
  369. &.is-danger {
  370. background-color: $red !important;
  371. &:hover,
  372. &:focus {
  373. background-color: darken($red, 5%) !important;
  374. }
  375. }
  376. &.is-info {
  377. background-color: $blue !important;
  378. &:hover,
  379. &:focus {
  380. background-color: darken($blue, 5%) !important;
  381. }
  382. }
  383. }
  384. .input,
  385. .button {
  386. height: 36px;
  387. }
  388. .input-with-button {
  389. .control {
  390. margin-right: 0px !important;
  391. }
  392. input {
  393. height: 36px;
  394. border-radius: 3px 0 0 3px;
  395. border-right: 0;
  396. }
  397. .button {
  398. height: 36px;
  399. border-radius: 0 3px 3px 0;
  400. }
  401. }
  402. .page-title {
  403. margin: 0 0 50px 0;
  404. }
  405. .material-icons {
  406. user-select: none;
  407. -webkit-user-select: none;
  408. }
  409. .icon-with-button {
  410. margin-right: 3px;
  411. font-size: 18px;
  412. }
  413. .section-title,
  414. h4.section-title {
  415. font-size: 26px;
  416. margin: 0px;
  417. }
  418. .section-description {
  419. font-size: 16px;
  420. margin-bottom: 5px;
  421. }
  422. </style>