index.vue 12 KB

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