Home.vue 9.0 KB

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