Home.vue 10 KB

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