Home.vue 12 KB

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