index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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 && !station.isFavorited"
  67. @click.prevent="favoriteStation(station)"
  68. class="favorite material-icons"
  69. >star_border</i
  70. >
  71. <i
  72. v-if="loggedIn && station.isFavorited"
  73. @click.prevent="unfavoriteStation(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. searchQuery: ""
  184. };
  185. },
  186. computed: {
  187. ...mapState({
  188. loggedIn: state => state.user.auth.loggedIn,
  189. userId: state => state.user.auth.userId,
  190. modals: state => state.modals.modals.home
  191. }),
  192. filteredStations() {
  193. const privacyOrder = ["public", "unlisted", "private"];
  194. return this.stations
  195. .filter(
  196. station =>
  197. JSON.stringify(Object.values(station)).indexOf(
  198. this.searchQuery
  199. ) !== -1
  200. )
  201. .sort(
  202. (a, b) =>
  203. b.isFavorited - a.isFavorited ||
  204. this.isOwner(b) - this.isOwner(a) ||
  205. this.isPlaying(b) - this.isPlaying(a) ||
  206. a.paused - b.paused ||
  207. privacyOrder.indexOf(a.privacy) -
  208. privacyOrder.indexOf(b.privacy) ||
  209. b.userCount - a.userCount
  210. );
  211. }
  212. },
  213. mounted() {
  214. io.getSocket(socket => {
  215. this.socket = socket;
  216. if (this.socket.connected) this.init();
  217. io.onConnect(() => {
  218. this.init();
  219. });
  220. this.socket.on("event:stations.created", res => {
  221. const station = res;
  222. if (
  223. this.stations.find(_station => _station._id === station._id)
  224. ) {
  225. this.stations.forEach(s => {
  226. const _station = s;
  227. if (_station._id === station._id) {
  228. _station.privacy = station.privacy;
  229. }
  230. });
  231. } else {
  232. if (!station.currentSong)
  233. station.currentSong = {
  234. thumbnail: "/assets/notes-transparent.png"
  235. };
  236. if (station.currentSong && !station.currentSong.thumbnail)
  237. station.currentSong.ytThumbnail = `https://img.youtube.com/vi/${station.currentSong.songId}/mqdefault.jpg`;
  238. this.stations.push(station);
  239. }
  240. });
  241. this.socket.on("event:station.removed", response => {
  242. const { stationId } = response;
  243. const station = this.stations.find(
  244. station => station._id === stationId
  245. );
  246. if (station) {
  247. const stationIndex = this.stations.indexOf(station);
  248. this.stations.splice(stationIndex, 1);
  249. }
  250. });
  251. this.socket.on(
  252. "event:userCount.updated",
  253. (stationId, userCount) => {
  254. this.stations.forEach(s => {
  255. const station = s;
  256. if (station._id === stationId) {
  257. station.userCount = userCount;
  258. }
  259. });
  260. }
  261. );
  262. this.socket.on("event:station.updatePrivacy", response => {
  263. const { stationId, privacy } = response;
  264. this.stations.forEach(s => {
  265. const station = s;
  266. if (station._id === stationId) {
  267. station.privacy = privacy;
  268. }
  269. });
  270. });
  271. this.socket.on("event:station.updateName", response => {
  272. const { stationId, name } = response;
  273. this.stations.forEach(s => {
  274. const station = s;
  275. if (station._id === stationId) {
  276. station.name = name;
  277. }
  278. });
  279. });
  280. this.socket.on("event:station.updateDisplayName", response => {
  281. const { stationId, displayName } = response;
  282. this.stations.forEach(s => {
  283. const station = s;
  284. if (station._id === stationId) {
  285. station.displayName = displayName;
  286. }
  287. });
  288. });
  289. this.socket.on("event:station.updateDescription", response => {
  290. const { stationId, description } = response;
  291. this.stations.forEach(s => {
  292. const station = s;
  293. if (station._id === stationId) {
  294. station.description = description;
  295. }
  296. });
  297. });
  298. this.socket.on("event:station.nextSong", (stationId, song) => {
  299. let newSong = song;
  300. this.stations.forEach(s => {
  301. const station = s;
  302. if (station._id === stationId) {
  303. if (!newSong)
  304. newSong = {
  305. thumbnail: "/assets/notes-transparent.png"
  306. };
  307. if (newSong && !newSong.thumbnail)
  308. newSong.ytThumbnail = `https://img.youtube.com/vi/${newSong.songId}/mqdefault.jpg`;
  309. station.currentSong = newSong;
  310. }
  311. });
  312. });
  313. this.socket.on("event:station.pause", response => {
  314. const { stationId } = response;
  315. this.stations.forEach(s => {
  316. const station = s;
  317. if (station._id === stationId) {
  318. station.paused = true;
  319. }
  320. });
  321. });
  322. this.socket.on("event:station.resume", response => {
  323. const { stationId } = response;
  324. this.stations.forEach(s => {
  325. const station = s;
  326. if (station._id === stationId) {
  327. station.paused = false;
  328. }
  329. });
  330. });
  331. this.socket.on("event:user.favoritedStation", stationId => {
  332. this.stations.forEach(s => {
  333. const station = s;
  334. if (station._id === stationId) {
  335. station.isFavorited = true;
  336. }
  337. });
  338. });
  339. this.socket.on("event:user.unfavoritedStation", stationId => {
  340. this.stations.forEach(s => {
  341. const station = s;
  342. if (station._id === stationId) {
  343. station.isFavorited = false;
  344. }
  345. });
  346. });
  347. });
  348. },
  349. methods: {
  350. init() {
  351. this.socket.emit("stations.index", data => {
  352. this.stations = [];
  353. if (data.status === "success")
  354. data.stations.forEach(s => {
  355. const station = s;
  356. if (!station.currentSong)
  357. station.currentSong = {
  358. thumbnail: "/assets/notes-transparent.png"
  359. };
  360. if (
  361. station.currentSong &&
  362. !station.currentSong.thumbnail
  363. )
  364. station.currentSong.ytThumbnail = `https://img.youtube.com/vi/${station.currentSong.songId}/mqdefault.jpg`;
  365. this.stations.push(station);
  366. });
  367. });
  368. this.socket.emit("apis.joinRoom", "home", () => {});
  369. },
  370. isOwner(station) {
  371. return station.owner === this.userId;
  372. },
  373. isPlaying(station) {
  374. return typeof station.currentSong.title !== "undefined";
  375. },
  376. favoriteStation(station) {
  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(station) {
  387. this.socket.emit("stations.unfavoriteStation", station._id, res => {
  388. if (res.status === "success") {
  389. new Toast({
  390. content: "Successfully unfavorited station.",
  391. timeout: 4000
  392. });
  393. } else new Toast({ content: res.message, timeout: 8000 });
  394. });
  395. },
  396. ...mapActions("modals", ["openModal"]),
  397. ...mapActions("station", ["updateIfStationIsFavorited"])
  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>