Home.vue 13 KB

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