Home.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <template>
  2. <div>
  3. <metadata title="Home" />
  4. <div class="app">
  5. <main-header />
  6. <div class="content-wrapper">
  7. <div class="stationsTitle">
  8. Stations&nbsp;
  9. <a
  10. v-if="loggedIn"
  11. href="#"
  12. @click="
  13. openModal({
  14. sector: 'home',
  15. modal: 'createCommunityStation'
  16. })
  17. "
  18. >
  19. <i class="material-icons community-button"
  20. >add_circle_outline</i
  21. >
  22. </a>
  23. </div>
  24. <div class="stations">
  25. <router-link
  26. v-for="(station, index) in filteredStations"
  27. :key="index"
  28. :to="{
  29. name: 'station',
  30. params: { id: station.name }
  31. }"
  32. :class="{
  33. stationCard: true,
  34. blueTheme: station.theme === 'blue',
  35. purpleTheme: station.theme === 'purple',
  36. tealTheme: station.theme === 'teal',
  37. darkTheme: station.theme === 'dark'
  38. }"
  39. >
  40. <div class="topContent">
  41. <div class="albumArt">
  42. <div
  43. v-if="station.currentSong.ytThumbnail"
  44. class="ytThumbnailBg"
  45. v-bind:style="{
  46. 'background-image':
  47. 'url(' +
  48. station.currentSong.ytThumbnail +
  49. ')'
  50. }"
  51. ></div>
  52. <img
  53. v-if="station.currentSong.ytThumbnail"
  54. :src="station.currentSong.ytThumbnail"
  55. onerror="this.src='/assets/notes-transparent.png'"
  56. class="ytThumbnail"
  57. />
  58. <div
  59. v-if="
  60. station.type === 'official' &&
  61. station.currentSong.thumbnail
  62. "
  63. class="albumArtBg"
  64. v-bind:style="{
  65. 'background-image':
  66. 'url(' +
  67. station.currentSong.thumbnail +
  68. ')'
  69. }"
  70. ></div>
  71. <img
  72. v-if="station.currentSong.thumbnail"
  73. :src="station.currentSong.thumbnail"
  74. onerror="this.src='/assets/notes-transparent.png'"
  75. />
  76. </div>
  77. <div class="info">
  78. <div class="displayName">
  79. <i
  80. v-if="loggedIn && !isFavorite(station)"
  81. @click="
  82. favoriteStation($event, station)
  83. "
  84. class="favorite material-icons"
  85. >star_border</i
  86. >
  87. <i
  88. v-if="loggedIn && isFavorite(station)"
  89. @click="
  90. unfavoriteStation($event, station)
  91. "
  92. class="favorite material-icons"
  93. >star</i
  94. >
  95. <h5>{{ station.displayName }}</h5>
  96. <i
  97. v-if="station.type === 'official'"
  98. class="badge material-icons"
  99. title="Official Station"
  100. >
  101. check_circle
  102. </i>
  103. </div>
  104. <p class="description">
  105. {{ station.description }}
  106. </p>
  107. <p class="hostedBy">
  108. Hosted by
  109. <span class="host">
  110. <span
  111. v-if="station.type === 'official'"
  112. title="Musare"
  113. >Musare</span
  114. >
  115. <user-id-to-username
  116. v-else
  117. :userId="station.owner"
  118. :link="true"
  119. />
  120. </span>
  121. </p>
  122. <div class="bottomIcons">
  123. <i
  124. v-if="station.privacy === 'unlisted'"
  125. class="unlistedIcon material-icons"
  126. title="Unlisted Station"
  127. >link</i
  128. >
  129. <i
  130. v-if="station.privacy === 'private'"
  131. class="privateIcon material-icons"
  132. title="Private Station"
  133. >lock</i
  134. >
  135. <i
  136. v-if="
  137. station.type === 'community' &&
  138. isOwner(station)
  139. "
  140. class="homeIcon material-icons"
  141. title="This is your station."
  142. >home</i
  143. >
  144. </div>
  145. </div>
  146. </div>
  147. <div class="bottomBar">
  148. <i
  149. v-if="station.currentSong.title"
  150. class="material-icons"
  151. >music_note</i
  152. >
  153. <i v-else class="material-icons">music_off</i>
  154. <span
  155. v-if="station.currentSong.title"
  156. class="songTitle"
  157. :title="
  158. 'Now Playing: ' + station.currentSong.title
  159. "
  160. >{{ station.currentSong.title }}</span
  161. >
  162. <span v-else class="songTitle"
  163. >No Songs Playing</span
  164. >
  165. <div
  166. class="right"
  167. :title="
  168. 'There are currently ' +
  169. station.userCount +
  170. ' users listening'
  171. "
  172. >
  173. <i class="material-icons">people</i>
  174. <span class="currentUsers">{{
  175. station.userCount
  176. }}</span>
  177. </div>
  178. </div>
  179. </router-link>
  180. </div>
  181. </div>
  182. <main-footer />
  183. </div>
  184. <create-community-station v-if="modals.createCommunityStation" />
  185. </div>
  186. </template>
  187. <script>
  188. import { mapState, mapActions } from "vuex";
  189. import Toast from "toasters";
  190. import MainHeader from "../MainHeader.vue";
  191. import MainFooter from "../MainFooter.vue";
  192. import CreateCommunityStation from "../Modals/CreateCommunityStation.vue";
  193. import UserIdToUsername from "../UserIdToUsername.vue";
  194. import io from "../../io";
  195. export default {
  196. data() {
  197. return {
  198. recaptcha: {
  199. key: ""
  200. },
  201. stations: [],
  202. favoriteStations: [],
  203. searchQuery: ""
  204. };
  205. },
  206. computed: {
  207. filteredStations() {
  208. return this.stations.filter(
  209. station =>
  210. JSON.stringify(Object.values(station)).indexOf(
  211. this.searchQuery
  212. ) !== -1
  213. );
  214. },
  215. ...mapState({
  216. modals: state => state.modals.modals.home,
  217. loggedIn: state => state.user.auth.loggedIn,
  218. userId: state => state.user.auth.userId
  219. })
  220. },
  221. mounted() {
  222. io.getSocket(socket => {
  223. this.socket = socket;
  224. if (this.socket.connected) this.init();
  225. io.onConnect(() => {
  226. this.init();
  227. });
  228. this.socket.on("event:stations.created", res => {
  229. const station = res;
  230. if (!station.currentSong)
  231. station.currentSong = {
  232. thumbnail: "/assets/notes-transparent.png"
  233. };
  234. if (station.currentSong && !station.currentSong.thumbnail)
  235. station.currentSong.ytThumbnail = `https://img.youtube.com/vi/${station.currentSong.songId}/mqdefault.jpg`;
  236. this.stations.push(station);
  237. });
  238. this.socket.on(
  239. "event:userCount.updated",
  240. (stationId, userCount) => {
  241. this.stations.forEach(s => {
  242. const station = s;
  243. if (station._id === stationId) {
  244. station.userCount = userCount;
  245. }
  246. });
  247. }
  248. );
  249. this.socket.on("event:station.nextSong", (stationId, song) => {
  250. let newSong = song;
  251. this.stations.forEach(s => {
  252. const station = s;
  253. if (station._id === stationId) {
  254. if (!newSong)
  255. newSong = {
  256. thumbnail: "/assets/notes-transparent.png"
  257. };
  258. if (newSong && !newSong.thumbnail)
  259. newSong.ytThumbnail = `https://img.youtube.com/vi/${newSong.songId}/mqdefault.jpg`;
  260. station.currentSong = newSong;
  261. }
  262. });
  263. });
  264. this.socket.on("event:user.favoritedStation", stationId => {
  265. this.favoriteStations.push(stationId);
  266. });
  267. this.socket.on("event:user.unfavoritedStation", stationId => {
  268. const station = this.favoriteStations.indexOf(stationId);
  269. this.favoriteStations.splice(station, 1);
  270. });
  271. });
  272. },
  273. methods: {
  274. init() {
  275. this.socket.emit("stations.index", data => {
  276. this.stations = [];
  277. if (data.status === "success")
  278. data.stations.forEach(s => {
  279. const station = s;
  280. if (!station.currentSong)
  281. station.currentSong = {
  282. thumbnail: "/assets/notes-transparent.png"
  283. };
  284. if (
  285. station.currentSong &&
  286. !station.currentSong.thumbnail
  287. )
  288. station.currentSong.ytThumbnail = `https://img.youtube.com/vi/${station.currentSong.songId}/mqdefault.jpg`;
  289. this.stations.push(station);
  290. });
  291. });
  292. this.socket.emit("users.getFavoriteStations", data => {
  293. if (data.status === "success")
  294. this.favoriteStations = data.favoriteStations;
  295. });
  296. this.socket.emit("apis.joinRoom", "home", () => {});
  297. },
  298. isOwner(station) {
  299. return station.owner === this.userId;
  300. },
  301. isFavorite(station) {
  302. return this.favoriteStations.indexOf(station._id) !== -1;
  303. },
  304. favoriteStation(event, station) {
  305. event.preventDefault();
  306. this.socket.emit("stations.favoriteStation", station._id, res => {
  307. if (res.status === "success") {
  308. new Toast({
  309. content: "Successfully favorited station.",
  310. timeout: 4000
  311. });
  312. } else new Toast({ content: res.message, timeout: 8000 });
  313. });
  314. },
  315. unfavoriteStation(event, station) {
  316. event.preventDefault();
  317. this.socket.emit("stations.unfavoriteStation", station._id, res => {
  318. if (res.status === "success") {
  319. new Toast({
  320. content: "Successfully unfavorited station.",
  321. timeout: 4000
  322. });
  323. } else new Toast({ content: res.message, timeout: 8000 });
  324. });
  325. },
  326. ...mapActions("modals", ["openModal"])
  327. },
  328. components: {
  329. MainHeader,
  330. MainFooter,
  331. CreateCommunityStation,
  332. UserIdToUsername
  333. }
  334. };
  335. </script>
  336. <style lang="scss">
  337. @import "scss/variables/colors.scss";
  338. * {
  339. box-sizing: border-box;
  340. }
  341. html {
  342. width: 100%;
  343. height: 100%;
  344. color: $dark-grey-2;
  345. body {
  346. width: 100%;
  347. height: 100%;
  348. margin: 0;
  349. padding: 0;
  350. }
  351. }
  352. .stationsTitle {
  353. width: 100%;
  354. height: 64px;
  355. line-height: 48px;
  356. text-align: center;
  357. font-size: 48px;
  358. margin-bottom: 25px;
  359. }
  360. .community-button {
  361. cursor: pointer;
  362. transition: 0.25s ease color;
  363. font-size: 30px;
  364. color: $dark-grey;
  365. &:hover {
  366. color: $primary-color;
  367. }
  368. }
  369. .stations {
  370. display: flex;
  371. flex: 1;
  372. flex-wrap: wrap;
  373. justify-content: center;
  374. margin-left: 50px;
  375. margin-right: 50px;
  376. }
  377. @media screen and (max-width: 575px) {
  378. .stations {
  379. margin-left: 10px;
  380. margin-right: 10px;
  381. }
  382. }
  383. .stationCard {
  384. display: inline-flex;
  385. flex-direction: column;
  386. width: 300px;
  387. height: 475px;
  388. background: $white;
  389. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.1);
  390. color: $dark-grey;
  391. margin: 10px;
  392. transition: all ease-in-out 0.2s;
  393. cursor: pointer;
  394. overflow: hidden;
  395. .albumArt {
  396. display: flex;
  397. position: relative;
  398. height: 300px;
  399. width: 300px;
  400. box-shadow: 1px 0px 3px rgba(7, 136, 191, 0.3);
  401. overflow: hidden;
  402. img {
  403. width: auto;
  404. height: 100%;
  405. }
  406. .ytThumbnailBg {
  407. background: url("/assets/notes-transparent.png") no-repeat center
  408. center;
  409. background-size: cover;
  410. height: 100%;
  411. width: 100%;
  412. position: absolute;
  413. top: 0;
  414. filter: blur(5px);
  415. }
  416. .ytThumbnail {
  417. height: auto;
  418. width: 100%;
  419. top: 0;
  420. margin-top: auto;
  421. margin-bottom: auto;
  422. z-index: 1;
  423. }
  424. }
  425. .topContent {
  426. width: 100%;
  427. height: 100%;
  428. .info {
  429. padding: 15px 12px 12px 15px;
  430. position: relative;
  431. width: 100%;
  432. max-width: 300px;
  433. height: 145px;
  434. .displayName {
  435. color: $black;
  436. margin: 0;
  437. font-size: 20px;
  438. font-weight: 500;
  439. margin-bottom: 5px;
  440. width: 100%;
  441. display: flex;
  442. -webkit-line-clamp: 1;
  443. line-height: 30px;
  444. max-height: 30px;
  445. .favorite {
  446. position: relative;
  447. padding-right: 5px;
  448. color: $yellow;
  449. top: -1px;
  450. font-size: 28px;
  451. }
  452. h5 {
  453. font-size: 20px;
  454. font-weight: 500;
  455. margin: 0;
  456. line-height: 30px;
  457. text-overflow: ellipsis;
  458. word-wrap: break-word;
  459. overflow: hidden;
  460. max-width: calc(100% - 80px);
  461. -webkit-box-orient: vertical;
  462. white-space: nowrap;
  463. }
  464. .badge {
  465. position: relative;
  466. padding-left: 5px;
  467. color: $primary-color;
  468. top: 5px;
  469. font-size: 18px;
  470. }
  471. }
  472. .description {
  473. width: calc(100% - 30px);
  474. margin: 0;
  475. font-size: 14px;
  476. font-weight: 400;
  477. word-wrap: break-word;
  478. overflow: hidden;
  479. text-overflow: ellipsis;
  480. display: -webkit-box;
  481. -webkit-box-orient: vertical;
  482. -webkit-line-clamp: 3;
  483. line-height: 20px;
  484. max-height: 60px;
  485. }
  486. .hostedBy {
  487. font-weight: 400;
  488. font-size: 12px;
  489. position: absolute;
  490. bottom: 12px;
  491. color: $black;
  492. .host {
  493. font-weight: 400;
  494. color: $primary-color;
  495. }
  496. }
  497. .bottomIcons {
  498. position: absolute;
  499. bottom: 12px;
  500. right: 12px;
  501. .material-icons {
  502. font-size: 22px;
  503. }
  504. .material-icons:first-child {
  505. margin-left: 5px;
  506. }
  507. .unlistedIcon {
  508. color: $light-orange;
  509. }
  510. .privateIcon {
  511. color: $dark-pink;
  512. }
  513. .homeIcon {
  514. color: $light-purple;
  515. }
  516. }
  517. }
  518. }
  519. .bottomBar {
  520. display: inline-flex;
  521. background: $primary-color;
  522. box-shadow: inset 0px 2px 4px rgba(darken($primary-color, 7), 0.7);
  523. width: 100%;
  524. height: 30px;
  525. line-height: 30px;
  526. color: $white;
  527. font-weight: 400;
  528. font-size: 12px;
  529. i.material-icons {
  530. vertical-align: middle;
  531. margin-left: 12px;
  532. font-size: 22px;
  533. line-height: 30px;
  534. }
  535. .songTitle {
  536. vertical-align: middle;
  537. margin-left: 5px;
  538. line-height: 30px;
  539. flex: 2 1 0;
  540. overflow: hidden;
  541. text-overflow: ellipsis;
  542. white-space: nowrap;
  543. }
  544. .right {
  545. float: right;
  546. margin-right: 12px;
  547. .currentUsers {
  548. vertical-align: middle;
  549. margin-left: 5px;
  550. font-size: 14px;
  551. }
  552. }
  553. }
  554. &.blueTheme {
  555. .topContent .info {
  556. .hostedBy .host,
  557. .hostedBy .host a,
  558. .displayName .badge,
  559. .bottomIcons .homeIcon {
  560. color: $musareBlue;
  561. }
  562. }
  563. .bottomBar {
  564. background: $musareBlue;
  565. box-shadow: inset 0px 2px 4px rgba(darken($musareBlue, 7), 0.7);
  566. }
  567. }
  568. &.purpleTheme {
  569. .topContent .info {
  570. .hostedBy .host,
  571. .hostedBy .host a,
  572. .displayName .badge,
  573. .bottomIcons .homeIcon {
  574. color: $light-purple;
  575. }
  576. }
  577. .bottomBar {
  578. background: $light-purple;
  579. box-shadow: inset 0px 2px 4px rgba(darken($light-purple, 7), 0.7);
  580. }
  581. }
  582. &.tealTheme {
  583. .topContent .info {
  584. .hostedBy .host,
  585. .hostedBy .host a,
  586. .displayName .badge,
  587. .bottomIcons .homeIcon {
  588. color: $teal;
  589. }
  590. }
  591. .bottomBar {
  592. background: $teal;
  593. box-shadow: inset 0px 2px 4px rgba(darken($teal, 7), 0.7);
  594. }
  595. }
  596. &.darkTheme {
  597. background: $dark-grey;
  598. color: $light-grey;
  599. .albumArt {
  600. box-shadow: 1px 0px 3px rgba($dark-grey-3, 0.3);
  601. }
  602. .topContent .info {
  603. .hostedBy .host,
  604. .hostedBy .host a,
  605. .displayName,
  606. .displayName .badge,
  607. .bottomIcons .homeIcon {
  608. color: $light-grey;
  609. }
  610. .hostedBy {
  611. color: $light-grey-2;
  612. }
  613. }
  614. .bottomBar {
  615. background: $dark-grey-2;
  616. box-shadow: inset 0px 2px 4px rgba(darken($dark-grey, 7), 0.7);
  617. }
  618. }
  619. }
  620. .stationCard:hover {
  621. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.3), 0 0 10px rgba(10, 10, 10, 0.3);
  622. transition: all ease-in-out 0.2s;
  623. }
  624. @media screen and (max-width: 575px) {
  625. .stationCard {
  626. height: 485px;
  627. .bottomBar {
  628. height: 40px;
  629. line-height: 40px;
  630. i.material-icons,
  631. .songTitle {
  632. line-height: 40px;
  633. }
  634. }
  635. }
  636. }
  637. </style>