Home.vue 11 KB

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