Home.vue 12 KB

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