App.vue 12 KB

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