Home.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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. this.favoriteStations.$remove(stationId);
  256. });
  257. });
  258. },
  259. methods: {
  260. init() {
  261. this.socket.emit("stations.index", data => {
  262. this.stations = [];
  263. if (data.status === "success")
  264. data.stations.forEach(s => {
  265. const station = s;
  266. if (!station.currentSong)
  267. station.currentSong = {
  268. thumbnail: "/assets/notes-transparent.png"
  269. };
  270. if (
  271. station.currentSong &&
  272. !station.currentSong.thumbnail
  273. )
  274. station.currentSong.ytThumbnail = `https://img.youtube.com/vi/${station.currentSong.songId}/mqdefault.jpg`;
  275. this.stations.push(station);
  276. });
  277. });
  278. this.socket.emit("users.getFavoriteStations", data => {
  279. if (data.status === "success")
  280. this.favoriteStations = data.favoriteStations;
  281. });
  282. this.socket.emit("apis.joinRoom", "home", () => {});
  283. },
  284. isOwner(station) {
  285. return station.owner === this.userId;
  286. },
  287. isFavorite(station) {
  288. return this.favoriteStations.indexOf(station._id) !== -1;
  289. },
  290. favoriteStation(event, station) {
  291. event.preventDefault();
  292. this.socket.emit("stations.favoriteStation", station._id, res => {
  293. if (res.status === "success") {
  294. new Toast({
  295. content: "Successfully favorited station.",
  296. timeout: 4000
  297. });
  298. } else new Toast({ content: res.message, timeout: 8000 });
  299. });
  300. },
  301. unfavoriteStation(event, station) {
  302. event.preventDefault();
  303. this.socket.emit("stations.unfavoriteStation", station._id, res => {
  304. if (res.status === "success") {
  305. new Toast({
  306. content: "Successfully unfavorited station.",
  307. timeout: 4000
  308. });
  309. } else new Toast({ content: res.message, timeout: 8000 });
  310. });
  311. },
  312. ...mapActions("modals", ["openModal"])
  313. },
  314. components: {
  315. MainHeader,
  316. MainFooter,
  317. CreateCommunityStation,
  318. UserIdToUsername
  319. }
  320. };
  321. </script>
  322. <style lang="scss">
  323. @import "scss/variables/colors.scss";
  324. * {
  325. box-sizing: border-box;
  326. }
  327. html {
  328. width: 100%;
  329. height: 100%;
  330. color: $dark-grey-2;
  331. body {
  332. width: 100%;
  333. height: 100%;
  334. margin: 0;
  335. padding: 0;
  336. }
  337. }
  338. .stationsTitle {
  339. width: 100%;
  340. height: 64px;
  341. line-height: 48px;
  342. text-align: center;
  343. font-size: 48px;
  344. margin-bottom: 25px;
  345. }
  346. .community-button {
  347. cursor: pointer;
  348. transition: 0.25s ease color;
  349. font-size: 30px;
  350. color: $dark-grey;
  351. &:hover {
  352. color: $primary-color;
  353. }
  354. }
  355. .stations {
  356. display: flex;
  357. flex: 1;
  358. flex-wrap: wrap;
  359. justify-content: center;
  360. margin-left: 50px;
  361. margin-right: 50px;
  362. }
  363. @media screen and (max-width: 575px) {
  364. .stations {
  365. margin-left: 10px;
  366. margin-right: 10px;
  367. }
  368. }
  369. .stationCard {
  370. display: inline-flex;
  371. flex-direction: column;
  372. width: 300px;
  373. height: 475px;
  374. background: $white;
  375. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.1);
  376. color: $dark-grey;
  377. margin: 10px;
  378. transition: all ease-in-out 0.2s;
  379. cursor: pointer;
  380. overflow: hidden;
  381. .albumArt {
  382. display: flex;
  383. position: relative;
  384. height: 300px;
  385. width: 300px;
  386. box-shadow: 1px 0px 3px rgba(7, 136, 191, 0.3);
  387. overflow: hidden;
  388. img {
  389. width: auto;
  390. height: 100%;
  391. }
  392. .ytThumbnailBg {
  393. background: url("/assets/notes-transparent.png") no-repeat center
  394. center;
  395. background-size: cover;
  396. height: 100%;
  397. width: 100%;
  398. position: absolute;
  399. top: 0;
  400. filter: blur(5px);
  401. }
  402. .ytThumbnail {
  403. height: auto;
  404. width: 100%;
  405. top: 0;
  406. margin-top: auto;
  407. margin-bottom: auto;
  408. z-index: 1;
  409. }
  410. }
  411. .topContent {
  412. width: 100%;
  413. height: 100%;
  414. .info {
  415. padding: 15px 12px 12px 15px;
  416. position: relative;
  417. width: 100%;
  418. max-width: 300px;
  419. height: 145px;
  420. .displayName {
  421. color: $black;
  422. margin: 0;
  423. font-size: 20px;
  424. font-weight: 500;
  425. margin-bottom: 5px;
  426. width: 100%;
  427. display: flex;
  428. -webkit-line-clamp: 1;
  429. line-height: 30px;
  430. max-height: 30px;
  431. .favorite {
  432. position: relative;
  433. padding-right: 5px;
  434. color: $yellow;
  435. top: -1px;
  436. font-size: 28px;
  437. }
  438. h5 {
  439. font-size: 20px;
  440. font-weight: 500;
  441. margin: 0;
  442. line-height: 30px;
  443. text-overflow: ellipsis;
  444. word-wrap: break-word;
  445. overflow: hidden;
  446. max-width: calc(100% - 80px);
  447. -webkit-box-orient: vertical;
  448. white-space: nowrap;
  449. }
  450. .badge {
  451. position: relative;
  452. padding-left: 5px;
  453. color: $lime;
  454. top: 3px;
  455. font-size: 22px;
  456. }
  457. }
  458. .description {
  459. width: calc(100% - 30px);
  460. margin: 0;
  461. font-size: 14px;
  462. font-weight: 400;
  463. word-wrap: break-word;
  464. overflow: hidden;
  465. text-overflow: ellipsis;
  466. display: -webkit-box;
  467. -webkit-box-orient: vertical;
  468. -webkit-line-clamp: 3;
  469. line-height: 20px;
  470. max-height: 60px;
  471. }
  472. .hostedBy {
  473. font-weight: 400;
  474. font-size: 12px;
  475. position: absolute;
  476. bottom: 12px;
  477. color: $black;
  478. .host {
  479. font-weight: 400;
  480. color: $primary-color;
  481. }
  482. }
  483. .bottomIcons {
  484. position: absolute;
  485. bottom: 12px;
  486. right: 12px;
  487. .material-icons {
  488. font-size: 22px;
  489. }
  490. .material-icons:first-child {
  491. margin-left: 5px;
  492. }
  493. .privateIcon {
  494. color: $dark-pink;
  495. }
  496. .homeIcon {
  497. color: $light-purple;
  498. }
  499. }
  500. }
  501. }
  502. .bottomBar {
  503. display: inline-flex;
  504. background: $primary-color;
  505. box-shadow: inset 0px 2px 4px rgba(7, 136, 191, 0.6);
  506. width: 100%;
  507. height: 30px;
  508. line-height: 30px;
  509. color: $white;
  510. font-weight: 400;
  511. font-size: 12px;
  512. i.material-icons {
  513. vertical-align: middle;
  514. margin-left: 12px;
  515. font-size: 22px;
  516. line-height: 30px;
  517. }
  518. .songTitle {
  519. vertical-align: middle;
  520. margin-left: 5px;
  521. line-height: 30px;
  522. flex: 2 1 0;
  523. overflow: hidden;
  524. text-overflow: ellipsis;
  525. white-space: nowrap;
  526. }
  527. .right {
  528. float: right;
  529. margin-right: 12px;
  530. .currentUsers {
  531. vertical-align: middle;
  532. margin-left: 5px;
  533. font-size: 14px;
  534. }
  535. }
  536. }
  537. }
  538. .stationCard:hover {
  539. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.3), 0 0 10px rgba(10, 10, 10, 0.3);
  540. transition: all ease-in-out 0.2s;
  541. }
  542. @media screen and (max-width: 575px) {
  543. .stationCard {
  544. height: 485px;
  545. .bottomBar {
  546. height: 40px;
  547. line-height: 40px;
  548. i.material-icons,
  549. .songTitle {
  550. line-height: 40px;
  551. }
  552. }
  553. }
  554. }
  555. </style>