App.vue 9.4 KB

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