App.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  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.modals.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. if (Object.keys(this.currentlyActive).length !== 0)
  94. this.closeCurrentModal();
  95. }
  96. });
  97. if (localStorage.getItem("github_redirect")) {
  98. this.$router.go(localStorage.getItem("github_redirect"));
  99. localStorage.removeItem("github_redirect");
  100. }
  101. io.onConnect(true, () => {
  102. this.socketConnected = true;
  103. });
  104. io.onConnectError(true, () => {
  105. this.socketConnected = false;
  106. });
  107. io.onDisconnect(true, () => {
  108. this.socketConnected = false;
  109. });
  110. this.serverDomain = await lofig.get("serverDomain");
  111. this.$router.onReady(() => {
  112. if (this.$route.query.err) {
  113. let { err } = this.$route.query;
  114. err = err
  115. .replace(new RegExp("<", "g"), "&lt;")
  116. .replace(new RegExp(">", "g"), "&gt;");
  117. this.$router.push({ query: {} });
  118. new Toast({ content: err, timeout: 20000 });
  119. }
  120. if (this.$route.query.msg) {
  121. let { msg } = this.$route.query;
  122. msg = msg
  123. .replace(new RegExp("<", "g"), "&lt;")
  124. .replace(new RegExp(">", "g"), "&gt;");
  125. this.$router.push({ query: {} });
  126. new Toast({ content: msg, timeout: 20000 });
  127. }
  128. });
  129. io.getSocket(true, socket => {
  130. this.socket = socket;
  131. this.socket.emit("users.getPreferences", res => {
  132. if (res.status === "success") {
  133. this.changeAutoSkipDisliked(res.data.autoSkipDisliked);
  134. this.changeNightmode(res.data.nightmode);
  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. },
  144. methods: {
  145. submitOnEnter: (cb, event) => {
  146. if (event.which === 13) cb();
  147. },
  148. enableNightMode: () => {
  149. document
  150. .getElementsByTagName("body")[0]
  151. .classList.add("night-mode");
  152. },
  153. disableNightMode: () => {
  154. document
  155. .getElementsByTagName("body")[0]
  156. .classList.remove("night-mode");
  157. },
  158. ...mapActions("modalVisibility", ["closeCurrentModal"]),
  159. ...mapActions("user/preferences", [
  160. "changeNightmode",
  161. "changeAutoSkipDisliked"
  162. ])
  163. }
  164. };
  165. </script>
  166. <style lang="scss">
  167. @import "./styles/global.scss";
  168. .night-mode {
  169. div {
  170. // background-color: #000;
  171. color: $night-mode-text;
  172. }
  173. #toasts-container .toast {
  174. color: #333;
  175. background-color: $light-grey-2 !important;
  176. &:last-of-type {
  177. background-color: $light-grey !important;
  178. }
  179. }
  180. h1,
  181. h2,
  182. h3,
  183. h4,
  184. h5,
  185. h6 {
  186. color: #fff !important;
  187. }
  188. p:not(.help),
  189. label {
  190. color: $night-mode-text !important;
  191. }
  192. .content {
  193. background-color: $night-mode-bg-secondary !important;
  194. }
  195. }
  196. body.night-mode {
  197. background-color: #000 !important;
  198. }
  199. #toasts-container {
  200. z-index: 10000 !important;
  201. .toast {
  202. font-weight: 600;
  203. background-color: $dark-grey !important;
  204. &:last-of-type {
  205. background-color: $dark-grey-2 !important;
  206. }
  207. }
  208. }
  209. html {
  210. overflow: auto !important;
  211. height: 100%;
  212. }
  213. body {
  214. background-color: $light-grey;
  215. color: $dark-grey;
  216. height: 100%;
  217. font-family: "Inter", Helvetica, Arial, sans-serif;
  218. }
  219. h1,
  220. h2,
  221. h3,
  222. h4,
  223. h5,
  224. h6,
  225. .sidebar-title {
  226. font-family: "Inter", Helvetica, Arial, sans-serif;
  227. }
  228. .modal-card-title {
  229. font-weight: 600;
  230. font-family: "Inter", Helvetica, Arial, sans-serif;
  231. }
  232. p,
  233. button,
  234. input,
  235. select,
  236. textarea {
  237. font-family: "Inter", Helvetica, Arial, sans-serif;
  238. }
  239. .upper-container {
  240. height: 100%;
  241. }
  242. .main-container {
  243. height: 100%;
  244. display: flex;
  245. flex-direction: column;
  246. > .container {
  247. flex: 1 0 auto;
  248. }
  249. }
  250. a {
  251. color: $primary-color;
  252. text-decoration: none;
  253. }
  254. .modal-card {
  255. margin: 0 !important;
  256. }
  257. .absolute-a {
  258. width: 100%;
  259. height: 100%;
  260. position: absolute;
  261. top: 0;
  262. left: 0;
  263. }
  264. .alert {
  265. padding: 20px;
  266. color: $white;
  267. background-color: $red;
  268. position: fixed;
  269. top: 50px;
  270. right: 50px;
  271. font-size: 2em;
  272. border-radius: 5px;
  273. z-index: 10000000;
  274. }
  275. .tooltip {
  276. position: relative;
  277. &:after {
  278. position: absolute;
  279. min-width: 80px;
  280. margin-left: -75%;
  281. text-align: center;
  282. padding: 7.5px 6px;
  283. border-radius: 2px;
  284. background-color: $dark-grey;
  285. font-size: 0.9em;
  286. color: $white;
  287. content: attr(data-tooltip);
  288. opacity: 0;
  289. transition: all 0.2s ease-in-out 0.1s;
  290. visibility: hidden;
  291. }
  292. &:hover:after {
  293. opacity: 1;
  294. visibility: visible;
  295. }
  296. }
  297. .tooltip-top {
  298. &:after {
  299. bottom: 150%;
  300. }
  301. &:hover {
  302. &:after {
  303. bottom: 120%;
  304. }
  305. }
  306. }
  307. .tooltip-bottom {
  308. &:after {
  309. top: 155%;
  310. }
  311. &:hover {
  312. &:after {
  313. top: 125%;
  314. }
  315. }
  316. }
  317. .tooltip-left {
  318. &:after {
  319. bottom: -10px;
  320. right: 130%;
  321. min-width: 100px;
  322. }
  323. &:hover {
  324. &:after {
  325. right: 110%;
  326. }
  327. }
  328. }
  329. .tooltip-right {
  330. &:after {
  331. bottom: -10px;
  332. left: 190%;
  333. min-width: 100px;
  334. }
  335. &:hover {
  336. &:after {
  337. left: 200%;
  338. }
  339. }
  340. }
  341. .select {
  342. &:after {
  343. border-color: $musare-blue;
  344. border-width: 1.5px;
  345. margin-top: -3px;
  346. }
  347. select {
  348. height: 36px;
  349. }
  350. }
  351. .button:focus,
  352. .button:active {
  353. border-color: #dbdbdb !important;
  354. }
  355. .input:focus,
  356. .input:active,
  357. .textarea:focus,
  358. .textarea:active,
  359. .select select:focus,
  360. .select select:active {
  361. border-color: $primary-color !important;
  362. }
  363. button.delete:focus {
  364. background-color: rgba(10, 10, 10, 0.3);
  365. }
  366. .tag {
  367. padding-right: 6px !important;
  368. }
  369. .button {
  370. &.is-success {
  371. background-color: $green !important;
  372. &:hover,
  373. &:focus {
  374. background-color: darken($green, 5%) !important;
  375. }
  376. }
  377. &.is-primary {
  378. background-color: $primary-color !important;
  379. &:hover,
  380. &:focus {
  381. background-color: darken($primary-color, 5%) !important;
  382. }
  383. }
  384. &.is-danger {
  385. background-color: $red !important;
  386. &:hover,
  387. &:focus {
  388. background-color: darken($red, 5%) !important;
  389. }
  390. }
  391. &.is-info {
  392. background-color: $musare-blue !important;
  393. &:hover,
  394. &:focus {
  395. background-color: darken($musare-blue, 5%) !important;
  396. }
  397. }
  398. &.is-warning {
  399. background-color: $yellow !important;
  400. &:hover,
  401. &:focus {
  402. background-color: darken($yellow, 5%) !important;
  403. }
  404. }
  405. }
  406. .input,
  407. .button {
  408. height: 36px;
  409. }
  410. .fadein-helpbox-enter-active {
  411. transition-duration: 0.3s;
  412. transition-timing-function: ease-in;
  413. }
  414. .fadein-helpbox-leave-active {
  415. transition-duration: 0.3s;
  416. transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
  417. }
  418. .fadein-helpbox-enter-to,
  419. .fadein-helpbox-leave {
  420. max-height: 100px;
  421. overflow: hidden;
  422. }
  423. .fadein-helpbox-enter,
  424. .fadein-helpbox-leave-to {
  425. overflow: hidden;
  426. max-height: 0;
  427. }
  428. .control {
  429. margin-bottom: 5px !important;
  430. }
  431. .input-with-button {
  432. .control {
  433. margin-right: 0px !important;
  434. }
  435. input,
  436. select {
  437. width: 100%;
  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. /** Universial items e.g. playlist items, queue items, activity items */
  483. .item-draggable {
  484. cursor: move;
  485. }
  486. .universal-item {
  487. display: flex;
  488. flex-direction: row;
  489. align-items: center;
  490. justify-content: space-between;
  491. padding: 7.5px;
  492. border: 1px solid $light-grey-2;
  493. border-radius: 3px;
  494. .item-thumbnail {
  495. width: 65px;
  496. height: 65px;
  497. margin: -7.5px;
  498. border-radius: 3px 0 0 3px;
  499. }
  500. .item-title {
  501. font-size: 20px;
  502. overflow: hidden;
  503. text-overflow: ellipsis;
  504. white-space: nowrap;
  505. }
  506. .item-description {
  507. font-size: 14px;
  508. overflow: hidden;
  509. text-overflow: ellipsis;
  510. white-space: nowrap;
  511. }
  512. .universal-item-actions {
  513. display: flex;
  514. flex-direction: row;
  515. margin-left: 10px;
  516. justify-content: center;
  517. @media screen and (max-width: 800px) {
  518. flex-wrap: wrap;
  519. }
  520. .button {
  521. width: 146px;
  522. }
  523. i {
  524. cursor: pointer;
  525. color: #4a4a4a;
  526. &:hover,
  527. &:focus {
  528. filter: brightness(90%);
  529. }
  530. &:not(:first-of-type) {
  531. margin-left: 5px;
  532. }
  533. }
  534. .play-icon {
  535. color: $green;
  536. }
  537. .edit-icon,
  538. .view-icon {
  539. color: $primary-color;
  540. }
  541. .hide-icon {
  542. color: #bdbdbd;
  543. }
  544. .stop-icon,
  545. .delete-icon {
  546. color: $red;
  547. }
  548. .report-icon {
  549. color: $yellow;
  550. }
  551. }
  552. }
  553. </style>