App.vue 12 KB

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