index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. <template>
  2. <div>
  3. <metadata title="Home" />
  4. <div class="app">
  5. <main-header />
  6. <div class="group">
  7. <div class="group-title">
  8. <div>
  9. <h1>Stations</h1>
  10. </div>
  11. <a
  12. v-if="loggedIn"
  13. href="#"
  14. @click="
  15. openModal({
  16. sector: 'home',
  17. modal: 'createCommunityStation'
  18. })
  19. "
  20. ><i class="material-icons community-button"
  21. >add_circle_outline</i
  22. >
  23. </a>
  24. </div>
  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="card station-card"
  33. :class="{
  34. isPrivate: station.privacy === 'private',
  35. isMine: isOwner(station)
  36. }"
  37. >
  38. <div class="card-image">
  39. <figure class="image is-square">
  40. <div
  41. v-if="station.currentSong.ytThumbnail"
  42. class="ytThumbnailBg"
  43. :style="{
  44. 'background-image':
  45. 'url(' +
  46. station.currentSong.ytThumbnail +
  47. ')'
  48. }"
  49. ></div>
  50. <img
  51. v-if="station.currentSong.ytThumbnail"
  52. :src="station.currentSong.ytThumbnail"
  53. onerror="this.src='/assets/notes-transparent.png'"
  54. />
  55. <img
  56. v-else
  57. :src="station.currentSong.thumbnail"
  58. onerror="this.src='/assets/notes-transparent.png'"
  59. />
  60. </figure>
  61. </div>
  62. <div class="card-content">
  63. <div class="media">
  64. <div class="media-left displayName">
  65. <i
  66. v-if="loggedIn && !isFavorite(station)"
  67. @click="favoriteStation($event, station)"
  68. class="favorite material-icons"
  69. >star_border</i
  70. >
  71. <i
  72. v-if="loggedIn && isFavorite(station)"
  73. @click="unfavoriteStation($event, station)"
  74. class="favorite material-icons"
  75. >star</i
  76. >
  77. <h5>{{ station.displayName }}</h5>
  78. <i
  79. v-if="station.type === 'official'"
  80. class="material-icons blue-icon"
  81. title="Verified station"
  82. >
  83. check_circle
  84. </i>
  85. </div>
  86. </div>
  87. <div class="content">
  88. {{ station.description }}
  89. </div>
  90. <div class="under-content">
  91. <p class="hostedBy">
  92. Hosted by
  93. <span class="host">
  94. <span
  95. v-if="station.type === 'official'"
  96. title="Musare"
  97. >Musare</span
  98. >
  99. <user-id-to-username
  100. v-else
  101. :user-id="station.owner"
  102. :link="true"
  103. />
  104. </span>
  105. </p>
  106. <div class="icons">
  107. <i
  108. v-if="
  109. station.type === 'community' &&
  110. isOwner(station)
  111. "
  112. class="homeIcon material-icons"
  113. title="This is your station."
  114. >home</i
  115. >
  116. <i
  117. v-if="station.privacy === 'private'"
  118. class="privateIcon material-icons"
  119. title="This station is not visible to other users."
  120. >lock</i
  121. >
  122. <i
  123. v-if="station.privacy === 'unlisted'"
  124. class="unlistedIcon material-icons"
  125. title="Unlisted Station"
  126. >link</i
  127. >
  128. </div>
  129. </div>
  130. </div>
  131. <div class="bottomBar">
  132. <i
  133. v-if="station.paused && station.currentSong.title"
  134. class="material-icons"
  135. title="Station Paused"
  136. >pause</i
  137. >
  138. <i
  139. v-else-if="station.currentSong.title"
  140. class="material-icons"
  141. >music_note</i
  142. >
  143. <i v-else class="material-icons">music_off</i>
  144. <span
  145. v-if="station.currentSong.title"
  146. class="songTitle"
  147. :title="'Now Playing: ' + station.currentSong.title"
  148. >{{ station.currentSong.title }}</span
  149. >
  150. <span v-else class="songTitle">No Songs Playing</span>
  151. </div>
  152. </router-link>
  153. <h4 v-if="stations.length === 0">
  154. There are no stations to display
  155. </h4>
  156. </div>
  157. <main-footer />
  158. </div>
  159. <create-community-station v-if="modals.createCommunityStation" />
  160. </div>
  161. </template>
  162. <script>
  163. import { mapState, mapActions } from "vuex";
  164. import Toast from "toasters";
  165. import MainHeader from "../../components/layout/MainHeader.vue";
  166. import MainFooter from "../../components/layout/MainFooter.vue";
  167. import CreateCommunityStation from "./CreateCommunityStation.vue";
  168. import UserIdToUsername from "../../components/common/UserIdToUsername.vue";
  169. import io from "../../io";
  170. export default {
  171. components: {
  172. MainHeader,
  173. MainFooter,
  174. CreateCommunityStation,
  175. UserIdToUsername
  176. },
  177. data() {
  178. return {
  179. recaptcha: {
  180. key: ""
  181. },
  182. stations: [],
  183. favoriteStations: [],
  184. searchQuery: ""
  185. };
  186. },
  187. computed: {
  188. ...mapState({
  189. loggedIn: state => state.user.auth.loggedIn,
  190. userId: state => state.user.auth.userId,
  191. modals: state => state.modals.modals.home
  192. }),
  193. filteredStations() {
  194. const privacyOrder = ["public", "unlisted", "private"];
  195. return this.stations
  196. .filter(
  197. station =>
  198. JSON.stringify(Object.values(station)).indexOf(
  199. this.searchQuery
  200. ) !== -1
  201. )
  202. .sort(
  203. (a, b) =>
  204. this.isFavorite(b) - this.isFavorite(a) ||
  205. this.isOwner(b) - this.isOwner(a) ||
  206. this.isPlaying(b) - this.isPlaying(a) ||
  207. a.paused - b.paused ||
  208. privacyOrder.indexOf(a.privacy) -
  209. privacyOrder.indexOf(b.privacy) ||
  210. b.userCount - a.userCount
  211. );
  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 (
  224. this.stations.find(_station => _station._id === station._id)
  225. ) {
  226. this.stations.forEach(s => {
  227. const _station = s;
  228. if (_station._id === station._id) {
  229. _station.privacy = station.privacy;
  230. }
  231. });
  232. } else {
  233. if (!station.currentSong)
  234. station.currentSong = {
  235. thumbnail: "/assets/notes-transparent.png"
  236. };
  237. if (station.currentSong && !station.currentSong.thumbnail)
  238. station.currentSong.ytThumbnail = `https://img.youtube.com/vi/${station.currentSong.songId}/mqdefault.jpg`;
  239. this.stations.push(station);
  240. }
  241. });
  242. this.socket.on("event:station.removed", response => {
  243. const { stationId } = response;
  244. const station = this.stations.find(
  245. station => station._id === stationId
  246. );
  247. if (station) {
  248. const stationIndex = this.stations.indexOf(station);
  249. this.stations.splice(stationIndex, 1);
  250. }
  251. });
  252. this.socket.on(
  253. "event:userCount.updated",
  254. (stationId, userCount) => {
  255. this.stations.forEach(s => {
  256. const station = s;
  257. if (station._id === stationId) {
  258. station.userCount = userCount;
  259. }
  260. });
  261. }
  262. );
  263. this.socket.on("event:station.updatePrivacy", response => {
  264. const { stationId, privacy } = response;
  265. this.stations.forEach(s => {
  266. const station = s;
  267. if (station._id === stationId) {
  268. station.privacy = privacy;
  269. }
  270. });
  271. });
  272. this.socket.on("event:station.updateName", response => {
  273. const { stationId, name } = response;
  274. this.stations.forEach(s => {
  275. const station = s;
  276. if (station._id === stationId) {
  277. station.name = name;
  278. }
  279. });
  280. });
  281. this.socket.on("event:station.updateDisplayName", response => {
  282. const { stationId, displayName } = response;
  283. this.stations.forEach(s => {
  284. const station = s;
  285. if (station._id === stationId) {
  286. station.displayName = displayName;
  287. }
  288. });
  289. });
  290. this.socket.on("event:station.updateDescription", response => {
  291. const { stationId, description } = response;
  292. this.stations.forEach(s => {
  293. const station = s;
  294. if (station._id === stationId) {
  295. station.description = description;
  296. }
  297. });
  298. });
  299. this.socket.on("event:station.nextSong", (stationId, song) => {
  300. let newSong = song;
  301. this.stations.forEach(s => {
  302. const station = s;
  303. if (station._id === stationId) {
  304. if (!newSong)
  305. newSong = {
  306. thumbnail: "/assets/notes-transparent.png"
  307. };
  308. if (newSong && !newSong.thumbnail)
  309. newSong.ytThumbnail = `https://img.youtube.com/vi/${newSong.songId}/mqdefault.jpg`;
  310. station.currentSong = newSong;
  311. }
  312. });
  313. });
  314. this.socket.on("event:station.pause", response => {
  315. const { stationId } = response;
  316. this.stations.forEach(s => {
  317. const station = s;
  318. if (station._id === stationId) {
  319. station.paused = true;
  320. }
  321. });
  322. });
  323. this.socket.on("event:station.resume", response => {
  324. const { stationId } = response;
  325. this.stations.forEach(s => {
  326. const station = s;
  327. if (station._id === stationId) {
  328. station.paused = false;
  329. }
  330. });
  331. });
  332. this.socket.on("event:user.favoritedStation", stationId => {
  333. this.favoriteStations.push(stationId);
  334. });
  335. this.socket.on("event:user.unfavoritedStation", stationId => {
  336. const index = this.favoriteStations.indexOf(stationId);
  337. this.favoriteStations.splice(index, 1);
  338. });
  339. });
  340. },
  341. methods: {
  342. init() {
  343. this.socket.emit("stations.index", data => {
  344. this.stations = [];
  345. if (data.status === "success")
  346. data.stations.forEach(s => {
  347. const station = s;
  348. if (!station.currentSong)
  349. station.currentSong = {
  350. thumbnail: "/assets/notes-transparent.png"
  351. };
  352. if (
  353. station.currentSong &&
  354. !station.currentSong.thumbnail
  355. )
  356. station.currentSong.ytThumbnail = `https://img.youtube.com/vi/${station.currentSong.songId}/mqdefault.jpg`;
  357. this.stations.push(station);
  358. });
  359. });
  360. this.socket.emit("users.getFavoriteStations", data => {
  361. if (data.status === "success")
  362. this.favoriteStations = data.favoriteStations;
  363. });
  364. this.socket.emit("apis.joinRoom", "home", () => {});
  365. },
  366. isOwner(station) {
  367. return station.owner === this.userId;
  368. },
  369. isFavorite(station) {
  370. return this.favoriteStations.indexOf(station._id) !== -1;
  371. },
  372. isPlaying(station) {
  373. return typeof station.currentSong.title !== "undefined";
  374. },
  375. favoriteStation(event, station) {
  376. event.preventDefault();
  377. this.socket.emit("stations.favoriteStation", station._id, res => {
  378. if (res.status === "success") {
  379. new Toast({
  380. content: "Successfully favorited station.",
  381. timeout: 4000
  382. });
  383. } else new Toast({ content: res.message, timeout: 8000 });
  384. });
  385. },
  386. unfavoriteStation(event, station) {
  387. event.preventDefault();
  388. this.socket.emit("stations.unfavoriteStation", station._id, res => {
  389. if (res.status === "success") {
  390. new Toast({
  391. content: "Successfully unfavorited station.",
  392. timeout: 4000
  393. });
  394. } else new Toast({ content: res.message, timeout: 8000 });
  395. });
  396. },
  397. ...mapActions("modals", ["openModal"])
  398. }
  399. };
  400. </script>
  401. <style lang="scss">
  402. @import "../../styles/global.scss";
  403. * {
  404. box-sizing: border-box;
  405. }
  406. html {
  407. width: 100%;
  408. height: 100%;
  409. color: rgba(0, 0, 0, 0.87);
  410. body {
  411. width: 100%;
  412. height: 100%;
  413. margin: 0;
  414. padding: 0;
  415. }
  416. }
  417. .night-mode {
  418. .card,
  419. .card-content,
  420. .card-content div {
  421. background-color: $night-mode-bg-secondary;
  422. }
  423. .card-content .icons i,
  424. .group-title i {
  425. color: $night-mode-text;
  426. }
  427. .card-image .image {
  428. background-color: #333;
  429. }
  430. .card-content .under-content .hostedBy {
  431. color: $night-mode-text;
  432. }
  433. }
  434. @media only screen and (min-width: 1200px) {
  435. html {
  436. font-size: 15px;
  437. }
  438. }
  439. @media only screen and (min-width: 992px) {
  440. html {
  441. font-size: 14.5px;
  442. }
  443. }
  444. @media only screen and (min-width: 0) {
  445. html {
  446. font-size: 14px;
  447. }
  448. }
  449. .under-content {
  450. height: 25px;
  451. position: relative;
  452. line-height: 1;
  453. font-size: 24px;
  454. display: flex;
  455. align-items: center;
  456. text-align: left;
  457. margin-top: 10px;
  458. p {
  459. font-size: 15px;
  460. line-height: 15px;
  461. display: inline;
  462. }
  463. i {
  464. font-size: 20px;
  465. }
  466. * {
  467. z-index: 10;
  468. position: relative;
  469. }
  470. .icons {
  471. position: absolute;
  472. right: 0;
  473. .material-icons {
  474. font-size: 22px;
  475. }
  476. .material-icons:first-child {
  477. margin-left: 5px;
  478. }
  479. .unlistedIcon {
  480. color: $light-orange;
  481. }
  482. .privateIcon {
  483. color: $dark-pink;
  484. }
  485. .homeIcon {
  486. color: $light-purple;
  487. }
  488. }
  489. .hostedBy {
  490. font-weight: 400;
  491. font-size: 12px;
  492. color: $black;
  493. .host {
  494. font-weight: 400;
  495. color: $primary-color;
  496. }
  497. }
  498. }
  499. .app {
  500. display: flex;
  501. flex-direction: column;
  502. }
  503. .users-count {
  504. font-size: 20px;
  505. position: relative;
  506. top: -4px;
  507. }
  508. .group {
  509. min-height: 64px;
  510. flex: 1 0 auto;
  511. }
  512. .station-card {
  513. display: inline-flex;
  514. flex-direction: column;
  515. overflow: hidden;
  516. margin: 10px;
  517. cursor: pointer;
  518. height: 480px;
  519. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.1);
  520. transition: all ease-in-out 0.2s;
  521. .card-content {
  522. padding: 10px 15px;
  523. .media {
  524. display: flex;
  525. align-items: center;
  526. margin-bottom: 5px;
  527. .displayName {
  528. display: flex;
  529. align-items: center;
  530. width: 80%;
  531. overflow: hidden;
  532. text-overflow: ellipsis;
  533. display: flex;
  534. line-height: 30px;
  535. max-height: 30px;
  536. .favorite {
  537. position: relative;
  538. padding-right: 5px;
  539. color: $yellow;
  540. top: -1px;
  541. font-size: 28px;
  542. }
  543. h5 {
  544. font-size: 20px;
  545. font-weight: 400;
  546. margin: 0;
  547. display: inline;
  548. margin-right: 6px;
  549. line-height: 30px;
  550. text-overflow: ellipsis;
  551. overflow: hidden;
  552. white-space: nowrap;
  553. }
  554. i {
  555. font-size: 22px;
  556. }
  557. .blue-icon {
  558. color: $musare-blue;
  559. }
  560. }
  561. }
  562. .content {
  563. word-wrap: break-word;
  564. overflow: hidden;
  565. text-overflow: ellipsis;
  566. display: -webkit-box;
  567. -webkit-box-orient: vertical;
  568. -webkit-line-clamp: 3;
  569. line-height: 20px;
  570. height: 60px;
  571. text-align: left;
  572. word-wrap: break-word;
  573. margin-bottom: 0;
  574. }
  575. }
  576. .card-image {
  577. .image {
  578. box-shadow: 1px 0px 3px rgba(7, 136, 191, 0.3);
  579. .ytThumbnailBg {
  580. background: url("/assets/notes-transparent.png") no-repeat
  581. center center;
  582. background-size: cover;
  583. height: 100%;
  584. width: 100%;
  585. position: absolute;
  586. top: 0;
  587. filter: blur(1px);
  588. }
  589. img {
  590. height: auto;
  591. width: 100%;
  592. top: 0;
  593. margin-top: auto;
  594. margin-bottom: auto;
  595. z-index: 1;
  596. }
  597. }
  598. }
  599. .bottomBar {
  600. position: relative;
  601. display: flex;
  602. align-items: center;
  603. background: $primary-color;
  604. box-shadow: inset 0px 2px 4px rgba(darken($primary-color, 7), 0.7);
  605. width: 100%;
  606. height: 30px;
  607. line-height: 30px;
  608. color: $white;
  609. font-weight: 400;
  610. font-size: 12px;
  611. padding: 0 5px;
  612. i.material-icons {
  613. vertical-align: middle;
  614. margin-left: 5px;
  615. font-size: 18px;
  616. }
  617. .songTitle {
  618. text-align: left;
  619. vertical-align: middle;
  620. margin-left: 5px;
  621. line-height: 30px;
  622. flex: 2 1 0;
  623. overflow: hidden;
  624. text-overflow: ellipsis;
  625. white-space: nowrap;
  626. }
  627. }
  628. }
  629. .station-card:hover {
  630. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.3), 0 0 10px rgba(10, 10, 10, 0.3);
  631. transition: all ease-in-out 0.2s;
  632. }
  633. /*.isPrivate {
  634. background-color: #F8BBD0;
  635. }
  636. .isMine {
  637. background-color: #29B6F6;
  638. }*/
  639. .community-button {
  640. cursor: pointer;
  641. transition: 0.25s ease color;
  642. font-size: 30px;
  643. color: #4a4a4a;
  644. }
  645. .community-button:hover {
  646. color: #03a9f4;
  647. }
  648. .station-privacy {
  649. text-transform: capitalize;
  650. }
  651. .label {
  652. display: flex;
  653. }
  654. .g-recaptcha {
  655. display: flex;
  656. justify-content: center;
  657. margin-top: 20px;
  658. }
  659. .group {
  660. text-align: center;
  661. width: 100%;
  662. margin: 40px 0 0 0;
  663. padding-bottom: 240px;
  664. .group-title {
  665. display: flex;
  666. align-items: center;
  667. justify-content: center;
  668. margin: 25px 0;
  669. h1 {
  670. display: inline-block;
  671. margin: 0;
  672. }
  673. a {
  674. display: flex;
  675. margin-left: 8px;
  676. }
  677. }
  678. }
  679. </style>