Home.vue 12 KB

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