Home.vue 12 KB

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