Home.vue 11 KB

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