Home.vue 12 KB

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