Home.vue 13 KB

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