1
0

App.vue 11 KB

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