App.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  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. <login-modal v-if="modals.header.login" />
  8. <register-modal v-if="modals.header.register" />
  9. </div>
  10. </div>
  11. </template>
  12. <script>
  13. import { mapState, mapActions, mapGetters } from "vuex";
  14. import Toast from "toasters";
  15. import ws from "./ws";
  16. import keyboardShortcuts from "./keyboardShortcuts";
  17. export default {
  18. components: {
  19. WhatIsNew: () => import("./components/modals/WhatIsNew.vue"),
  20. LoginModal: () => import("./components/modals/Login.vue"),
  21. RegisterModal: () => import("./components/modals/Register.vue"),
  22. Banned: () => import("./pages/Banned.vue")
  23. },
  24. replace: false,
  25. data() {
  26. return {
  27. apiDomain: "",
  28. socketConnected: true,
  29. keyIsDown: false
  30. };
  31. },
  32. computed: {
  33. ...mapState({
  34. loggedIn: state => state.user.auth.loggedIn,
  35. role: state => state.user.auth.role,
  36. username: state => state.user.auth.username,
  37. userId: state => state.user.auth.userId,
  38. banned: state => state.user.auth.banned,
  39. modals: state => state.modalVisibility.modals,
  40. currentlyActive: state => state.modalVisibility.currentlyActive,
  41. nightmode: state => state.user.preferences.nightmode
  42. }),
  43. ...mapGetters({
  44. socket: "websockets/getSocket"
  45. })
  46. },
  47. watch: {
  48. socketConnected(connected) {
  49. if (!connected)
  50. new Toast({
  51. content: "Could not connect to the server.",
  52. persistant: true
  53. });
  54. else {
  55. // better implementation once vue-roaster is updated
  56. document
  57. .getElementById("toasts-content")
  58. .childNodes.forEach(toast => {
  59. if (
  60. toast.innerHTML ===
  61. "Could not connect to the server."
  62. ) {
  63. toast.remove();
  64. }
  65. });
  66. }
  67. },
  68. nightmode(nightmode) {
  69. if (nightmode) this.enableNightMode();
  70. else this.disableNightMode();
  71. }
  72. },
  73. async mounted() {
  74. document.onkeydown = ev => {
  75. const event = ev || window.event;
  76. const { keyCode } = event;
  77. const shift = event.shiftKey;
  78. const ctrl = event.ctrlKey;
  79. const alt = event.altKey;
  80. const identifier = `${keyCode}.${shift}.${ctrl}`;
  81. if (this.keyIsDown === identifier) return;
  82. this.keyIsDown = identifier;
  83. keyboardShortcuts.handleKeyDown(event, keyCode, shift, ctrl, alt);
  84. };
  85. document.onkeyup = () => {
  86. this.keyIsDown = "";
  87. };
  88. keyboardShortcuts.registerShortcut("closeModal", {
  89. keyCode: 27,
  90. shift: false,
  91. ctrl: false,
  92. handler: () => {
  93. if (Object.keys(this.currentlyActive).length !== 0)
  94. this.closeCurrentModal();
  95. }
  96. });
  97. if (localStorage.getItem("github_redirect")) {
  98. this.$router.push(localStorage.getItem("github_redirect"));
  99. localStorage.removeItem("github_redirect");
  100. }
  101. ws.onConnect(true, () => {
  102. this.socketConnected = true;
  103. });
  104. ws.onDisconnect(true, () => {
  105. this.socketConnected = false;
  106. });
  107. this.apiDomain = await lofig.get("apiDomain");
  108. this.$router.onReady(() => {
  109. if (this.$route.query.err) {
  110. let { err } = this.$route.query;
  111. err = err
  112. .replace(new RegExp("<", "g"), "&lt;")
  113. .replace(new RegExp(">", "g"), "&gt;");
  114. this.$router.push({ query: {} });
  115. new Toast({ content: err, timeout: 20000 });
  116. }
  117. if (this.$route.query.msg) {
  118. let { msg } = this.$route.query;
  119. msg = msg
  120. .replace(new RegExp("<", "g"), "&lt;")
  121. .replace(new RegExp(">", "g"), "&gt;");
  122. this.$router.push({ query: {} });
  123. new Toast({ content: msg, timeout: 20000 });
  124. }
  125. });
  126. this.socket.dispatch("users.getPreferences", res => {
  127. if (res.status === "success") {
  128. this.changeAutoSkipDisliked(res.data.autoSkipDisliked);
  129. this.changeNightmode(res.data.nightmode);
  130. this.changeActivityLogPublic(res.data.activityLogPublic);
  131. if (this.nightmode) this.enableNightMode();
  132. else this.disableNightMode();
  133. }
  134. });
  135. this.socket.on("keep.event:user.session.removed", () =>
  136. window.location.reload()
  137. );
  138. },
  139. methods: {
  140. submitOnEnter: (cb, event) => {
  141. if (event.which === 13) cb();
  142. },
  143. enableNightMode: () => {
  144. document
  145. .getElementsByTagName("body")[0]
  146. .classList.add("night-mode");
  147. },
  148. disableNightMode: () => {
  149. document
  150. .getElementsByTagName("body")[0]
  151. .classList.remove("night-mode");
  152. },
  153. ...mapActions("modalVisibility", ["closeCurrentModal"]),
  154. ...mapActions("user/preferences", [
  155. "changeNightmode",
  156. "changeAutoSkipDisliked",
  157. "changeActivityLogPublic"
  158. ])
  159. }
  160. };
  161. </script>
  162. <style lang="scss">
  163. :root {
  164. --primary-color: var(--blue);
  165. --blue: rgb(2, 166, 242);
  166. --light-blue: rgb(163, 224, 255);
  167. --dark-blue: rgb(0, 102, 244);
  168. --teal: rgb(0, 209, 178);
  169. --purple: rgb(143, 40, 140);
  170. --light-purple: rgb(170, 141, 216);
  171. --yellow: rgb(241, 196, 15);
  172. --light-pink: rgb(228, 155, 166);
  173. --dark-pink: rgb(234, 72, 97);
  174. --orange: rgb(255, 94, 0);
  175. --dark-orange: rgb(250, 50, 0);
  176. --green: rgb(68, 189, 50);
  177. --red: rgb(231, 77, 60);
  178. --white: rgb(255, 255, 255);
  179. --black: rgb(0, 0, 0);
  180. --light-grey: rgb(245, 245, 245);
  181. --light-grey-2: rgb(221, 221, 221);
  182. --light-grey-3: rgb(195, 193, 195);
  183. --grey: rgb(107, 107, 107);
  184. --grey-2: rgb(113, 113, 113);
  185. --grey-3: rgb(126, 126, 126);
  186. --dark-grey: rgb(77, 77, 77);
  187. --dark-grey-2: rgb(51, 51, 51);
  188. --dark-grey-3: rgb(34, 34, 34);
  189. --dark-grey-4: rgb(26, 26, 26);
  190. --youtube: rgb(189, 46, 46);
  191. }
  192. .night-mode {
  193. div {
  194. // background-color: var(--black);
  195. color: var(--light-grey-2);
  196. }
  197. #toasts-container .toast {
  198. color: var(--dark-grey-2);
  199. background-color: var(--light-grey-3) !important;
  200. &:last-of-type {
  201. background-color: var(--light-grey) !important;
  202. }
  203. }
  204. h1,
  205. h2,
  206. h3,
  207. h4,
  208. h5,
  209. h6 {
  210. color: var(--white) !important;
  211. }
  212. p:not(.help),
  213. label {
  214. color: var(--light-grey-2) !important;
  215. }
  216. .content {
  217. background-color: var(--dark-grey-3) !important;
  218. }
  219. }
  220. body.night-mode {
  221. background-color: var(--black) !important;
  222. }
  223. #toasts-container {
  224. z-index: 10000 !important;
  225. .toast {
  226. font-weight: 600;
  227. background-color: var(--dark-grey) !important;
  228. &:last-of-type {
  229. background-color: var(--dark-grey-2) !important;
  230. }
  231. }
  232. }
  233. html {
  234. overflow: auto !important;
  235. height: 100%;
  236. }
  237. body {
  238. background-color: var(--light-grey);
  239. color: var(--dark-grey);
  240. height: 100%;
  241. font-family: "Inter", Helvetica, Arial, sans-serif;
  242. }
  243. h1,
  244. h2,
  245. h3,
  246. h4,
  247. h5,
  248. h6,
  249. .sidebar-title {
  250. font-family: "Inter", Helvetica, Arial, sans-serif;
  251. }
  252. .modal-card-title {
  253. font-weight: 600;
  254. font-family: "Inter", Helvetica, Arial, sans-serif;
  255. }
  256. p,
  257. button,
  258. input,
  259. select,
  260. textarea {
  261. font-family: "Inter", Helvetica, Arial, sans-serif;
  262. }
  263. .upper-container {
  264. height: 100%;
  265. }
  266. .main-container {
  267. height: 100%;
  268. display: flex;
  269. flex-direction: column;
  270. > .container {
  271. flex: 1 0 auto;
  272. }
  273. }
  274. a {
  275. color: var(--primary-color);
  276. text-decoration: none;
  277. }
  278. .modal-card {
  279. margin: 0 !important;
  280. }
  281. .absolute-a {
  282. width: 100%;
  283. height: 100%;
  284. position: absolute;
  285. top: 0;
  286. left: 0;
  287. }
  288. .alert {
  289. padding: 20px;
  290. color: var(--white);
  291. background-color: var(--red);
  292. position: fixed;
  293. top: 50px;
  294. right: 50px;
  295. font-size: 2em;
  296. border-radius: 5px;
  297. z-index: 10000000;
  298. }
  299. .tooltip {
  300. position: relative;
  301. &:after {
  302. position: absolute;
  303. min-width: 80px;
  304. margin-left: -75%;
  305. text-align: center;
  306. padding: 7.5px 6px;
  307. border-radius: 2px;
  308. background-color: var(--dark-grey);
  309. font-size: 14px;
  310. line-height: 24px;
  311. text-transform: none;
  312. color: var(--white);
  313. content: attr(data-tooltip);
  314. opacity: 0;
  315. transition: all 0.2s ease-in-out 0.1s;
  316. visibility: hidden;
  317. z-index: 5;
  318. }
  319. &:hover:after,
  320. &:focus:after {
  321. opacity: 1;
  322. visibility: visible;
  323. }
  324. }
  325. .tooltip-top {
  326. &:after {
  327. bottom: 150%;
  328. }
  329. &:hover {
  330. &:after {
  331. bottom: 120%;
  332. }
  333. }
  334. }
  335. .tooltip-bottom {
  336. &:after {
  337. top: 155%;
  338. }
  339. &:hover {
  340. &:after {
  341. top: 125%;
  342. }
  343. }
  344. }
  345. .tooltip-left {
  346. &:after {
  347. bottom: -10px;
  348. right: 130%;
  349. min-width: 100px;
  350. }
  351. &:hover {
  352. &:after {
  353. right: 110%;
  354. }
  355. }
  356. }
  357. .tooltip-right {
  358. &:after {
  359. bottom: -10px;
  360. left: 190%;
  361. min-width: 100px;
  362. }
  363. &:hover {
  364. &:after {
  365. left: 200%;
  366. }
  367. }
  368. }
  369. .tooltip-center {
  370. &:after {
  371. margin-left: 0;
  372. }
  373. &:hover {
  374. &:after {
  375. margin-left: 0;
  376. }
  377. }
  378. }
  379. .select {
  380. &:after {
  381. border-color: var(--primary-color);
  382. border-width: 1.5px;
  383. margin-top: -3px;
  384. }
  385. select {
  386. height: 36px;
  387. }
  388. }
  389. .button:focus,
  390. .button:active {
  391. border-color: var(--light-grey-2) !important;
  392. }
  393. .input:focus,
  394. .input:active,
  395. .textarea:focus,
  396. .textarea:active,
  397. .select select:focus,
  398. .select select:active {
  399. border-color: var(--primary-color) !important;
  400. }
  401. button.delete:focus {
  402. background-color: rgba(10, 10, 10, 0.3);
  403. }
  404. .tag {
  405. padding-right: 6px !important;
  406. }
  407. .button {
  408. &:hover,
  409. &:focus {
  410. filter: brightness(95%);
  411. }
  412. &.is-success {
  413. background-color: var(--green) !important;
  414. }
  415. &.is-primary {
  416. background-color: var(--primary-color) !important;
  417. }
  418. &.is-danger {
  419. background-color: var(--red) !important;
  420. }
  421. &.is-info {
  422. background-color: var(--primary-color) !important;
  423. }
  424. &.is-warning {
  425. background-color: var(--yellow) !important;
  426. }
  427. }
  428. .input,
  429. .button {
  430. height: 36px;
  431. }
  432. .fadein-helpbox-enter-active {
  433. transition-duration: 0.3s;
  434. transition-timing-function: ease-in;
  435. }
  436. .fadein-helpbox-leave-active {
  437. transition-duration: 0.3s;
  438. transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
  439. }
  440. .fadein-helpbox-enter-to,
  441. .fadein-helpbox-leave {
  442. max-height: 100px;
  443. overflow: hidden;
  444. }
  445. .fadein-helpbox-enter,
  446. .fadein-helpbox-leave-to {
  447. overflow: hidden;
  448. max-height: 0;
  449. }
  450. .control {
  451. margin-bottom: 5px !important;
  452. }
  453. .input-with-button {
  454. .control {
  455. margin-right: 0px !important;
  456. }
  457. input,
  458. select {
  459. width: 100%;
  460. height: 36px;
  461. border-radius: 3px 0 0 3px;
  462. border-right: 0;
  463. border-color: var(--light-grey-3);
  464. }
  465. .button {
  466. height: 36px;
  467. border-radius: 0 3px 3px 0;
  468. }
  469. }
  470. .page-title {
  471. margin: 0 0 50px 0;
  472. }
  473. .material-icons {
  474. user-select: none;
  475. -webkit-user-select: none;
  476. }
  477. .icon-with-button {
  478. margin-right: 3px;
  479. font-size: 18px;
  480. }
  481. .verified-song {
  482. font-size: 22px;
  483. color: var(--primary-color);
  484. vertical-align: top;
  485. }
  486. .section-title,
  487. h4.section-title {
  488. font-size: 26px;
  489. font-weight: 600;
  490. margin: 0px;
  491. }
  492. .section-description {
  493. font-size: 16px;
  494. font-weight: 400;
  495. margin-bottom: 10px !important;
  496. }
  497. .section-horizontal-rule {
  498. margin: 15px 0 30px 0;
  499. }
  500. .section-margin-bottom {
  501. height: 30px;
  502. }
  503. .margin-top-zero {
  504. margin-top: 0 !important;
  505. }
  506. .margin-bottom-zero {
  507. margin-bottom: 0 !important;
  508. }
  509. /** Universial items e.g. playlist items, queue items, activity items */
  510. .item-draggable {
  511. cursor: move;
  512. }
  513. .universal-item {
  514. display: flex;
  515. flex-direction: row;
  516. align-items: center;
  517. justify-content: space-between;
  518. padding: 7.5px;
  519. border: 1px solid var(--light-grey-3);
  520. border-radius: 3px;
  521. .item-thumbnail {
  522. width: 65px;
  523. height: 65px;
  524. margin: -7.5px;
  525. border-radius: 3px 0 0 3px;
  526. }
  527. .item-title {
  528. font-size: 20px;
  529. overflow: hidden;
  530. text-overflow: ellipsis;
  531. white-space: nowrap;
  532. }
  533. .item-description {
  534. font-size: 14px;
  535. overflow: hidden;
  536. text-overflow: ellipsis;
  537. white-space: nowrap;
  538. }
  539. .universal-item-actions {
  540. display: flex;
  541. flex-direction: row;
  542. margin-left: 10px;
  543. justify-content: center;
  544. @media screen and (max-width: 800px) {
  545. flex-wrap: wrap;
  546. }
  547. .button {
  548. width: 146px;
  549. }
  550. i {
  551. cursor: pointer;
  552. color: var(--dark-grey);
  553. &:hover,
  554. &:focus {
  555. filter: brightness(90%);
  556. }
  557. &:not(:first-of-type) {
  558. margin-left: 5px;
  559. }
  560. }
  561. .play-icon {
  562. color: var(--green);
  563. }
  564. .edit-icon,
  565. .view-icon,
  566. .add-to-playlist-icon {
  567. color: var(--primary-color);
  568. }
  569. .hide-icon {
  570. color: var(--light-grey-3);
  571. }
  572. .stop-icon,
  573. .delete-icon {
  574. color: var(--red);
  575. }
  576. .report-icon {
  577. color: var(--yellow);
  578. }
  579. }
  580. }
  581. .save-button-mixin {
  582. min-width: 200px;
  583. &:disabled {
  584. background-color: var(--light-grey) !important;
  585. color: var(--black);
  586. }
  587. }
  588. .save-button-transition-enter-active {
  589. transition: all 0.1s ease;
  590. }
  591. .save-button-transition-enter {
  592. transform: translateX(20px);
  593. opacity: 0;
  594. }
  595. </style>