App.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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.modalVisibility.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("modalVisibility", ["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. .content {
  198. background-color: $night-mode-bg-secondary !important;
  199. }
  200. }
  201. body.night-mode {
  202. background-color: #000 !important;
  203. }
  204. #toasts-container {
  205. z-index: 10000 !important;
  206. .toast {
  207. font-weight: 600;
  208. background-color: $dark-grey !important;
  209. &:last-of-type {
  210. background-color: $dark-grey-2 !important;
  211. }
  212. }
  213. }
  214. html {
  215. overflow: auto !important;
  216. height: 100%;
  217. }
  218. body {
  219. background-color: $light-grey;
  220. color: $dark-grey;
  221. height: 100%;
  222. font-family: "Inter", Helvetica, Arial, sans-serif;
  223. }
  224. h1,
  225. h2,
  226. h3,
  227. h4,
  228. h5,
  229. h6,
  230. .sidebar-title {
  231. font-family: "Inter", Helvetica, Arial, sans-serif;
  232. }
  233. .modal-card-title {
  234. font-weight: 600;
  235. font-family: "Inter", Helvetica, Arial, sans-serif;
  236. }
  237. p,
  238. button,
  239. input,
  240. select,
  241. textarea {
  242. font-family: "Inter", Helvetica, Arial, sans-serif;
  243. }
  244. .upper-container {
  245. height: 100%;
  246. }
  247. .main-container {
  248. height: 100%;
  249. display: flex;
  250. flex-direction: column;
  251. > .container {
  252. flex: 1 0 auto;
  253. }
  254. }
  255. a {
  256. color: $primary-color;
  257. text-decoration: none;
  258. }
  259. .modal-card {
  260. margin: 0 !important;
  261. }
  262. .absolute-a {
  263. width: 100%;
  264. height: 100%;
  265. position: absolute;
  266. top: 0;
  267. left: 0;
  268. }
  269. .alert {
  270. padding: 20px;
  271. color: $white;
  272. background-color: $red;
  273. position: fixed;
  274. top: 50px;
  275. right: 50px;
  276. font-size: 2em;
  277. border-radius: 5px;
  278. z-index: 10000000;
  279. }
  280. .tooltip {
  281. position: relative;
  282. &:after {
  283. position: absolute;
  284. min-width: 80px;
  285. margin-left: -75%;
  286. text-align: center;
  287. padding: 7.5px 6px;
  288. border-radius: 2px;
  289. background-color: $dark-grey;
  290. font-size: 0.9em;
  291. color: $white;
  292. content: attr(data-tooltip);
  293. opacity: 0;
  294. transition: all 0.2s ease-in-out 0.1s;
  295. visibility: hidden;
  296. }
  297. &:hover:after {
  298. opacity: 1;
  299. visibility: visible;
  300. }
  301. }
  302. .tooltip-top {
  303. &:after {
  304. bottom: 150%;
  305. }
  306. &:hover {
  307. &:after {
  308. bottom: 120%;
  309. }
  310. }
  311. }
  312. .tooltip-bottom {
  313. &:after {
  314. top: 155%;
  315. }
  316. &:hover {
  317. &:after {
  318. top: 125%;
  319. }
  320. }
  321. }
  322. .tooltip-left {
  323. &:after {
  324. bottom: -10px;
  325. right: 130%;
  326. min-width: 100px;
  327. }
  328. &:hover {
  329. &:after {
  330. right: 110%;
  331. }
  332. }
  333. }
  334. .tooltip-right {
  335. &:after {
  336. bottom: -10px;
  337. left: 190%;
  338. min-width: 100px;
  339. }
  340. &:hover {
  341. &:after {
  342. left: 200%;
  343. }
  344. }
  345. }
  346. .select {
  347. &:after {
  348. border-color: $musare-blue;
  349. border-width: 1.5px;
  350. margin-top: -3px;
  351. }
  352. select {
  353. height: 36px;
  354. }
  355. }
  356. .button:focus,
  357. .button:active {
  358. border-color: #dbdbdb !important;
  359. }
  360. .input:focus,
  361. .input:active,
  362. .textarea:focus,
  363. .textarea:active,
  364. .select select:focus,
  365. .select select:active {
  366. border-color: $primary-color !important;
  367. }
  368. button.delete:focus {
  369. background-color: rgba(10, 10, 10, 0.3);
  370. }
  371. .tag {
  372. padding-right: 6px !important;
  373. }
  374. .button {
  375. &.is-success {
  376. background-color: $green !important;
  377. &:hover,
  378. &:focus {
  379. background-color: darken($green, 5%) !important;
  380. }
  381. }
  382. &.is-primary {
  383. background-color: $primary-color !important;
  384. &:hover,
  385. &:focus {
  386. background-color: darken($primary-color, 5%) !important;
  387. }
  388. }
  389. &.is-danger {
  390. background-color: $red !important;
  391. &:hover,
  392. &:focus {
  393. background-color: darken($red, 5%) !important;
  394. }
  395. }
  396. &.is-info {
  397. background-color: $musare-blue !important;
  398. &:hover,
  399. &:focus {
  400. background-color: darken($musare-blue, 5%) !important;
  401. }
  402. }
  403. &.is-warning {
  404. background-color: $yellow !important;
  405. &:hover,
  406. &:focus {
  407. background-color: darken($yellow, 5%) !important;
  408. }
  409. }
  410. }
  411. .input,
  412. .button {
  413. height: 36px;
  414. }
  415. .fadein-helpbox-enter-active {
  416. transition-duration: 0.3s;
  417. transition-timing-function: ease-in;
  418. }
  419. .fadein-helpbox-leave-active {
  420. transition-duration: 0.3s;
  421. transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
  422. }
  423. .fadein-helpbox-enter-to,
  424. .fadein-helpbox-leave {
  425. max-height: 100px;
  426. overflow: hidden;
  427. }
  428. .fadein-helpbox-enter,
  429. .fadein-helpbox-leave-to {
  430. overflow: hidden;
  431. max-height: 0;
  432. }
  433. .control {
  434. margin-bottom: 5px !important;
  435. }
  436. .input-with-button {
  437. .control {
  438. margin-right: 0px !important;
  439. }
  440. input,
  441. select {
  442. width: 100%;
  443. height: 36px;
  444. border-radius: 3px 0 0 3px;
  445. border-right: 0;
  446. border-color: $light-grey-2;
  447. }
  448. .button {
  449. height: 36px;
  450. border-radius: 0 3px 3px 0;
  451. }
  452. }
  453. .page-title {
  454. margin: 0 0 50px 0;
  455. }
  456. .material-icons {
  457. user-select: none;
  458. -webkit-user-select: none;
  459. }
  460. .icon-with-button {
  461. margin-right: 3px;
  462. font-size: 18px;
  463. }
  464. .section-title,
  465. h4.section-title {
  466. font-size: 26px;
  467. font-weight: 600;
  468. margin: 0px;
  469. }
  470. .section-description {
  471. font-size: 16px;
  472. font-weight: 400;
  473. margin-bottom: 10px !important;
  474. }
  475. .section-horizontal-rule {
  476. margin: 15px 0 30px 0;
  477. }
  478. .section-margin-bottom {
  479. height: 30px;
  480. }
  481. .margin-top-zero {
  482. margin-top: 0 !important;
  483. }
  484. .margin-bottom-zero {
  485. margin-bottom: 0 !important;
  486. }
  487. /** Universial items e.g. playlist items, queue items, activity items */
  488. .item-draggable {
  489. cursor: move;
  490. }
  491. .universal-item {
  492. display: flex;
  493. flex-direction: row;
  494. align-items: center;
  495. justify-content: space-between;
  496. padding: 7.5px;
  497. border: 1px solid $light-grey-2;
  498. border-radius: 3px;
  499. .item-thumbnail {
  500. width: 65px;
  501. height: 65px;
  502. margin: -7.5px;
  503. border-radius: 3px 0 0 3px;
  504. }
  505. .item-title {
  506. font-size: 20px;
  507. overflow: hidden;
  508. text-overflow: ellipsis;
  509. white-space: nowrap;
  510. }
  511. .item-description {
  512. font-size: 14px;
  513. overflow: hidden;
  514. text-overflow: ellipsis;
  515. white-space: nowrap;
  516. }
  517. .universal-item-actions {
  518. display: flex;
  519. flex-direction: row;
  520. margin-left: 10px;
  521. justify-content: center;
  522. @media screen and (max-width: 800px) {
  523. flex-wrap: wrap;
  524. }
  525. .button {
  526. width: 146px;
  527. }
  528. i {
  529. cursor: pointer;
  530. color: #4a4a4a;
  531. &:hover,
  532. &:focus {
  533. filter: brightness(90%);
  534. }
  535. &:not(:first-of-type) {
  536. margin-left: 5px;
  537. }
  538. }
  539. .play-icon {
  540. color: $green;
  541. }
  542. .edit-icon,
  543. .view-icon {
  544. color: $primary-color;
  545. }
  546. .hide-icon {
  547. color: #bdbdbd;
  548. }
  549. .stop-icon,
  550. .delete-icon {
  551. color: $red;
  552. }
  553. .report-icon {
  554. color: $yellow;
  555. }
  556. }
  557. }
  558. </style>