App.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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. <mobile-alert />
  8. <login-modal v-if="modals.header.login" />
  9. <register-modal v-if="modals.header.register" />
  10. </div>
  11. </div>
  12. </template>
  13. <script>
  14. import { mapState, mapActions } from "vuex";
  15. import Toast from "toasters";
  16. import Banned from "./pages/Banned.vue";
  17. import WhatIsNew from "./components/modals/WhatIsNew.vue";
  18. import MobileAlert from "./components/common/MobileAlert.vue";
  19. import LoginModal from "./components/modals/Login.vue";
  20. import RegisterModal from "./components/modals/Register.vue";
  21. import io from "./io";
  22. import keyboardShortcuts from "./keyboardShortcuts";
  23. export default {
  24. components: {
  25. WhatIsNew,
  26. MobileAlert,
  27. LoginModal,
  28. RegisterModal,
  29. Banned
  30. },
  31. replace: false,
  32. data() {
  33. return {
  34. serverDomain: "",
  35. socketConnected: true,
  36. keyIsDown: false
  37. };
  38. },
  39. computed: mapState({
  40. loggedIn: state => state.user.auth.loggedIn,
  41. role: state => state.user.auth.role,
  42. username: state => state.user.auth.username,
  43. userId: state => state.user.auth.userId,
  44. banned: state => state.user.auth.banned,
  45. modals: state => state.modals.modals,
  46. currentlyActive: state => state.modals.currentlyActive,
  47. nightmode: state => state.user.preferences.nightmode
  48. }),
  49. watch: {
  50. socketConnected(connected) {
  51. console.log(connected);
  52. if (!connected)
  53. new Toast({
  54. content: "Could not connect to the server.",
  55. persistant: true
  56. });
  57. else {
  58. // better implementation once vue-roaster is updated
  59. document
  60. .getElementById("toasts-content")
  61. .childNodes.forEach(toast => {
  62. if (
  63. toast.innerHTML ===
  64. "Could not connect to the server."
  65. ) {
  66. toast.remove();
  67. }
  68. });
  69. }
  70. },
  71. nightmode(nightmode) {
  72. if (nightmode) this.enableNightMode();
  73. else this.disableNightMode();
  74. }
  75. },
  76. beforeMount() {
  77. const nightmode =
  78. false || JSON.parse(localStorage.getItem("nightmode"));
  79. this.changeNightmode(nightmode);
  80. if (nightmode) this.enableNightMode();
  81. else this.disableNightMode();
  82. const autoSkipDisliked =
  83. false || JSON.parse(localStorage.getItem("autoSkipDisliked"));
  84. this.changeAutoSkipDisliked(autoSkipDisliked);
  85. },
  86. mounted() {
  87. document.onkeydown = ev => {
  88. const event = ev || window.event;
  89. const { keyCode } = event;
  90. const shift = event.shiftKey;
  91. const ctrl = event.ctrlKey;
  92. const alt = event.altKey;
  93. const identifier = `${keyCode}.${shift}.${ctrl}`;
  94. if (this.keyIsDown === identifier) return;
  95. this.keyIsDown = identifier;
  96. keyboardShortcuts.handleKeyDown(event, keyCode, shift, ctrl, alt);
  97. };
  98. document.onkeyup = () => {
  99. this.keyIsDown = "";
  100. };
  101. keyboardShortcuts.registerShortcut("closeModal", {
  102. keyCode: 27,
  103. shift: false,
  104. ctrl: false,
  105. handler: () => {
  106. if (Object.keys(this.currentlyActive).length !== 0)
  107. this.closeCurrentModal();
  108. }
  109. });
  110. if (localStorage.getItem("github_redirect")) {
  111. this.$router.go(localStorage.getItem("github_redirect"));
  112. localStorage.removeItem("github_redirect");
  113. }
  114. io.onConnect(true, () => {
  115. this.socketConnected = true;
  116. });
  117. io.onConnectError(true, () => {
  118. this.socketConnected = false;
  119. });
  120. io.onDisconnect(true, () => {
  121. this.socketConnected = false;
  122. });
  123. lofig.get("serverDomain").then(serverDomain => {
  124. this.serverDomain = serverDomain;
  125. });
  126. this.$router.onReady(() => {
  127. if (this.$route.query.err) {
  128. let { err } = this.$route.query;
  129. err = err
  130. .replace(new RegExp("<", "g"), "&lt;")
  131. .replace(new RegExp(">", "g"), "&gt;");
  132. this.$router.push({ query: {} });
  133. new Toast({ content: err, timeout: 20000 });
  134. }
  135. if (this.$route.query.msg) {
  136. let { msg } = this.$route.query;
  137. msg = msg
  138. .replace(new RegExp("<", "g"), "&lt;")
  139. .replace(new RegExp(">", "g"), "&gt;");
  140. this.$router.push({ query: {} });
  141. new Toast({ content: msg, timeout: 20000 });
  142. }
  143. });
  144. io.getSocket(true, socket => {
  145. socket.on("keep.event:user.session.removed", () => {
  146. window.location.reload();
  147. });
  148. });
  149. },
  150. methods: {
  151. submitOnEnter: (cb, event) => {
  152. if (event.which === 13) cb();
  153. },
  154. enableNightMode: () => {
  155. document
  156. .getElementsByTagName("body")[0]
  157. .classList.add("night-mode");
  158. },
  159. disableNightMode: () => {
  160. document
  161. .getElementsByTagName("body")[0]
  162. .classList.remove("night-mode");
  163. },
  164. ...mapActions("modals", ["closeCurrentModal"]),
  165. ...mapActions("user/preferences", [
  166. "changeNightmode",
  167. "changeAutoSkipDisliked"
  168. ])
  169. }
  170. };
  171. </script>
  172. <style lang="scss">
  173. @import "./styles/global.scss";
  174. .night-mode {
  175. div {
  176. // background-color: #000;
  177. color: $night-mode-text;
  178. }
  179. #toasts-container .toast {
  180. color: #333;
  181. background-color: $light-grey-2 !important;
  182. &:last-of-type {
  183. background-color: $light-grey !important;
  184. }
  185. }
  186. h1,
  187. h2,
  188. h3,
  189. h4,
  190. h5,
  191. h6 {
  192. color: #fff !important;
  193. }
  194. p:not(.help),
  195. label {
  196. color: $night-mode-text !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. height: 36px;
  440. border-radius: 3px 0 0 3px;
  441. border-right: 0;
  442. border-color: $light-grey-2;
  443. }
  444. .button {
  445. height: 36px;
  446. border-radius: 0 3px 3px 0;
  447. }
  448. }
  449. .page-title {
  450. margin: 0 0 50px 0;
  451. }
  452. .material-icons {
  453. user-select: none;
  454. -webkit-user-select: none;
  455. }
  456. .icon-with-button {
  457. margin-right: 3px;
  458. font-size: 18px;
  459. }
  460. .section-title,
  461. h4.section-title {
  462. font-size: 26px;
  463. font-weight: 600;
  464. margin: 0px;
  465. }
  466. .section-description {
  467. font-size: 16px;
  468. font-weight: 400;
  469. margin-bottom: 10px !important;
  470. }
  471. .section-horizontal-rule {
  472. margin: 15px 0 30px 0;
  473. }
  474. .section-margin-bottom {
  475. height: 30px;
  476. }
  477. .margin-top-zero {
  478. margin-top: 0 !important;
  479. }
  480. .margin-bottom-zero {
  481. margin-bottom: 0 !important;
  482. }
  483. </style>