index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  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 stations"
  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.currentSong.title"
  134. class="material-icons"
  135. >music_note</i
  136. >
  137. <i v-else class="material-icons">music_off</i>
  138. <span
  139. v-if="station.currentSong.title"
  140. class="songTitle"
  141. :title="'Now Playing: ' + station.currentSong.title"
  142. >{{ station.currentSong.title }}</span
  143. >
  144. <span v-else class="songTitle">No Songs Playing</span>
  145. </div>
  146. </router-link>
  147. <h4 v-if="stations.length === 0">
  148. There are no stations to display
  149. </h4>
  150. </div>
  151. <main-footer />
  152. </div>
  153. <create-community-station v-if="modals.createCommunityStation" />
  154. </div>
  155. </template>
  156. <script>
  157. import { mapState, mapActions } from "vuex";
  158. import Toast from "toasters";
  159. import MainHeader from "../../components/layout/MainHeader.vue";
  160. import MainFooter from "../../components/layout/MainFooter.vue";
  161. import CreateCommunityStation from "./CreateCommunityStation.vue";
  162. import UserIdToUsername from "../../components/common/UserIdToUsername.vue";
  163. import io from "../../io";
  164. export default {
  165. components: {
  166. MainHeader,
  167. MainFooter,
  168. CreateCommunityStation,
  169. UserIdToUsername
  170. },
  171. data() {
  172. return {
  173. recaptcha: {
  174. key: ""
  175. },
  176. stations: [],
  177. favoriteStations: [],
  178. searchQuery: ""
  179. };
  180. },
  181. computed: {
  182. filteredStations() {
  183. return this.stations.filter(
  184. station =>
  185. JSON.stringify(Object.values(station)).indexOf(
  186. this.searchQuery
  187. ) !== -1
  188. );
  189. },
  190. ...mapState({
  191. loggedIn: state => state.user.auth.loggedIn,
  192. userId: state => state.user.auth.userId,
  193. modals: state => state.modals.modals.home
  194. })
  195. },
  196. mounted() {
  197. io.getSocket(socket => {
  198. this.socket = socket;
  199. if (this.socket.connected) this.init();
  200. io.onConnect(() => {
  201. this.init();
  202. });
  203. this.socket.on("event:stations.created", res => {
  204. const station = res;
  205. if (!station.currentSong)
  206. station.currentSong = {
  207. thumbnail: "/assets/notes-transparent.png"
  208. };
  209. if (station.currentSong && !station.currentSong.thumbnail)
  210. station.currentSong.ytThumbnail = `https://img.youtube.com/vi/${station.currentSong.songId}/mqdefault.jpg`;
  211. this.stations.push(station);
  212. });
  213. this.socket.on(
  214. "event:userCount.updated",
  215. (stationId, userCount) => {
  216. this.stations.forEach(s => {
  217. const station = s;
  218. if (station._id === stationId) {
  219. station.userCount = userCount;
  220. }
  221. });
  222. }
  223. );
  224. this.socket.on("event:station.nextSong", (stationId, song) => {
  225. let newSong = song;
  226. this.stations.forEach(s => {
  227. const station = s;
  228. if (station._id === stationId) {
  229. if (!newSong)
  230. newSong = {
  231. thumbnail: "/assets/notes-transparent.png"
  232. };
  233. if (newSong && !newSong.thumbnail)
  234. newSong.ytThumbnail = `https://img.youtube.com/vi/${newSong.songId}/mqdefault.jpg`;
  235. station.currentSong = newSong;
  236. }
  237. });
  238. });
  239. this.socket.on("event:user.favoritedStation", stationId => {
  240. this.favoriteStations.push(stationId);
  241. });
  242. this.socket.on("event:user.unfavoritedStation", stationId => {
  243. const index = this.favoriteStations.indexOf(stationId);
  244. this.favoriteStations.splice(index, 1);
  245. });
  246. });
  247. },
  248. methods: {
  249. init() {
  250. this.socket.emit("stations.index", data => {
  251. this.stations = [];
  252. if (data.status === "success")
  253. data.stations.forEach(s => {
  254. const station = s;
  255. if (!station.currentSong)
  256. station.currentSong = {
  257. thumbnail: "/assets/notes-transparent.png"
  258. };
  259. if (
  260. station.currentSong &&
  261. !station.currentSong.thumbnail
  262. )
  263. station.currentSong.ytThumbnail = `https://img.youtube.com/vi/${station.currentSong.songId}/mqdefault.jpg`;
  264. this.stations.push(station);
  265. });
  266. });
  267. this.socket.emit("users.getFavoriteStations", data => {
  268. if (data.status === "success")
  269. this.favoriteStations = data.favoriteStations;
  270. });
  271. this.socket.emit("apis.joinRoom", "home", () => {});
  272. },
  273. isOwner(station) {
  274. return station.owner === this.userId;
  275. },
  276. isFavorite(station) {
  277. return this.favoriteStations.indexOf(station._id) !== -1;
  278. },
  279. favoriteStation(event, station) {
  280. event.preventDefault();
  281. this.socket.emit("stations.favoriteStation", station._id, res => {
  282. if (res.status === "success") {
  283. new Toast({
  284. content: "Successfully favorited station.",
  285. timeout: 4000
  286. });
  287. } else new Toast({ content: res.message, timeout: 8000 });
  288. });
  289. },
  290. unfavoriteStation(event, station) {
  291. event.preventDefault();
  292. this.socket.emit("stations.unfavoriteStation", station._id, res => {
  293. if (res.status === "success") {
  294. new Toast({
  295. content: "Successfully unfavorited station.",
  296. timeout: 4000
  297. });
  298. } else new Toast({ content: res.message, timeout: 8000 });
  299. });
  300. },
  301. ...mapActions("modals", ["openModal"])
  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: rgba(0, 0, 0, 0.87);
  314. body {
  315. width: 100%;
  316. height: 100%;
  317. margin: 0;
  318. padding: 0;
  319. }
  320. }
  321. .night-mode {
  322. .card,
  323. .card-content,
  324. .card-content div {
  325. background-color: $night-mode-secondary;
  326. }
  327. .card-content .icons i,
  328. .group-title i {
  329. color: #ddd;
  330. }
  331. .card-image .image {
  332. background-color: #333;
  333. }
  334. .card-content .under-content .hostedBy {
  335. color: #ddd;
  336. }
  337. }
  338. @media only screen and (min-width: 1200px) {
  339. html {
  340. font-size: 15px;
  341. }
  342. }
  343. @media only screen and (min-width: 992px) {
  344. html {
  345. font-size: 14.5px;
  346. }
  347. }
  348. @media only screen and (min-width: 0) {
  349. html {
  350. font-size: 14px;
  351. }
  352. }
  353. .under-content {
  354. height: 25px;
  355. position: relative;
  356. line-height: 1;
  357. font-size: 24px;
  358. display: flex;
  359. align-items: center;
  360. text-align: left;
  361. margin-top: 10px;
  362. p {
  363. font-size: 15px;
  364. line-height: 15px;
  365. display: inline;
  366. }
  367. i {
  368. font-size: 20px;
  369. }
  370. * {
  371. z-index: 10;
  372. position: relative;
  373. }
  374. .icons {
  375. position: absolute;
  376. right: 0;
  377. .material-icons {
  378. font-size: 22px;
  379. }
  380. .material-icons:first-child {
  381. margin-left: 5px;
  382. }
  383. .unlistedIcon {
  384. color: $light-orange;
  385. }
  386. .privateIcon {
  387. color: $dark-pink;
  388. }
  389. .homeIcon {
  390. color: $light-purple;
  391. }
  392. }
  393. .hostedBy {
  394. font-weight: 400;
  395. font-size: 12px;
  396. color: $black;
  397. .host {
  398. font-weight: 400;
  399. color: $primary-color;
  400. }
  401. }
  402. }
  403. .app {
  404. display: flex;
  405. flex-direction: column;
  406. }
  407. .users-count {
  408. font-size: 20px;
  409. position: relative;
  410. top: -4px;
  411. }
  412. .group {
  413. min-height: 64px;
  414. flex: 1 0 auto;
  415. }
  416. .station-card {
  417. display: inline-flex;
  418. flex-direction: column;
  419. overflow: hidden;
  420. margin: 10px;
  421. cursor: pointer;
  422. height: 480px;
  423. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.1);
  424. transition: all ease-in-out 0.2s;
  425. .card-content {
  426. padding: 10px 15px;
  427. .media {
  428. display: flex;
  429. align-items: center;
  430. margin-bottom: 5px;
  431. .displayName {
  432. display: flex;
  433. align-items: center;
  434. width: 80%;
  435. overflow: hidden;
  436. text-overflow: ellipsis;
  437. display: flex;
  438. line-height: 30px;
  439. max-height: 30px;
  440. .favorite {
  441. position: relative;
  442. padding-right: 5px;
  443. color: $yellow;
  444. top: -1px;
  445. font-size: 28px;
  446. }
  447. h5 {
  448. font-size: 20px;
  449. font-weight: 400;
  450. margin: 0;
  451. display: inline;
  452. margin-right: 6px;
  453. line-height: 30px;
  454. text-overflow: ellipsis;
  455. overflow: hidden;
  456. white-space: nowrap;
  457. }
  458. i {
  459. font-size: 22px;
  460. }
  461. .blue-icon {
  462. color: $musare-blue;
  463. }
  464. }
  465. }
  466. .content {
  467. word-wrap: break-word;
  468. overflow: hidden;
  469. text-overflow: ellipsis;
  470. display: -webkit-box;
  471. -webkit-box-orient: vertical;
  472. -webkit-line-clamp: 3;
  473. line-height: 20px;
  474. height: 60px;
  475. text-align: left;
  476. word-wrap: break-word;
  477. margin-bottom: 0;
  478. }
  479. }
  480. .card-image {
  481. .image {
  482. box-shadow: 1px 0px 3px rgba(7, 136, 191, 0.3);
  483. .ytThumbnailBg {
  484. background: url("/assets/notes-transparent.png") no-repeat
  485. center center;
  486. background-size: cover;
  487. height: 100%;
  488. width: 100%;
  489. position: absolute;
  490. top: 0;
  491. filter: blur(3px);
  492. }
  493. img {
  494. height: auto;
  495. width: 100%;
  496. top: 0;
  497. margin-top: auto;
  498. margin-bottom: auto;
  499. z-index: 1;
  500. }
  501. }
  502. }
  503. .bottomBar {
  504. position: relative;
  505. display: flex;
  506. align-items: center;
  507. background: $primary-color;
  508. box-shadow: inset 0px 2px 4px rgba(darken($primary-color, 7), 0.7);
  509. width: 100%;
  510. height: 30px;
  511. line-height: 30px;
  512. color: $white;
  513. font-weight: 400;
  514. font-size: 12px;
  515. padding: 0 5px;
  516. i.material-icons {
  517. vertical-align: middle;
  518. margin-left: 5px;
  519. font-size: 18px;
  520. }
  521. .songTitle {
  522. text-align: left;
  523. vertical-align: middle;
  524. margin-left: 5px;
  525. line-height: 30px;
  526. flex: 2 1 0;
  527. overflow: hidden;
  528. text-overflow: ellipsis;
  529. white-space: nowrap;
  530. }
  531. }
  532. }
  533. .station-card:hover {
  534. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.3), 0 0 10px rgba(10, 10, 10, 0.3);
  535. transition: all ease-in-out 0.2s;
  536. }
  537. /*.isPrivate {
  538. background-color: #F8BBD0;
  539. }
  540. .isMine {
  541. background-color: #29B6F6;
  542. }*/
  543. .community-button {
  544. cursor: pointer;
  545. transition: 0.25s ease color;
  546. font-size: 30px;
  547. color: #4a4a4a;
  548. }
  549. .community-button:hover {
  550. color: #03a9f4;
  551. }
  552. .station-privacy {
  553. text-transform: capitalize;
  554. }
  555. .label {
  556. display: flex;
  557. }
  558. .g-recaptcha {
  559. display: flex;
  560. justify-content: center;
  561. margin-top: 20px;
  562. }
  563. .group {
  564. text-align: center;
  565. width: 100%;
  566. margin: 40px 0 0 0;
  567. padding-bottom: 240px;
  568. .group-title {
  569. display: flex;
  570. align-items: center;
  571. justify-content: center;
  572. h1 {
  573. display: inline-block;
  574. }
  575. a {
  576. display: flex;
  577. margin-left: 8px;
  578. }
  579. }
  580. }
  581. </style>