Home.vue 13 KB

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