Home.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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. this.favoriteStations.$remove(stationId);
  204. });
  205. });
  206. },
  207. methods: {
  208. init() {
  209. this.socket.emit("stations.index", data => {
  210. this.stations = [];
  211. if (data.status === "success")
  212. data.stations.forEach(s => {
  213. const station = s;
  214. if (!station.currentSong)
  215. station.currentSong = {
  216. thumbnail: "/assets/notes-transparent.png"
  217. };
  218. if (
  219. station.currentSong &&
  220. !station.currentSong.thumbnail
  221. )
  222. station.currentSong.ytThumbnail = `https://img.youtube.com/vi/${station.currentSong.songId}/mqdefault.jpg`;
  223. this.stations.push(station);
  224. });
  225. });
  226. this.socket.emit("users.getFavoriteStations", data => {
  227. if (data.status === "success")
  228. this.favoriteStations = data.favoriteStations;
  229. });
  230. this.socket.emit("apis.joinRoom", "home", () => {});
  231. },
  232. isOwner(station) {
  233. return station.owner === this.userId;
  234. },
  235. isFavorite(station) {
  236. return this.favoriteStations.indexOf(station._id) !== -1;
  237. },
  238. favoriteStation(event, station) {
  239. event.preventDefault();
  240. this.socket.emit("stations.favoriteStation", station._id, res => {
  241. if (res.status === "success") {
  242. new Toast({
  243. content: "Successfully favorited station.",
  244. timeout: 4000
  245. });
  246. } else new Toast({ content: res.message, timeout: 8000 });
  247. });
  248. },
  249. unfavoriteStation(event, station) {
  250. event.preventDefault();
  251. this.socket.emit("stations.unfavoriteStation", station._id, res => {
  252. if (res.status === "success") {
  253. new Toast({
  254. content: "Successfully unfavorited station.",
  255. timeout: 4000
  256. });
  257. } else new Toast({ content: res.message, timeout: 8000 });
  258. });
  259. },
  260. ...mapActions("modals", ["openModal"])
  261. },
  262. components: {
  263. MainHeader,
  264. MainFooter,
  265. CreateCommunityStation,
  266. UserIdToUsername
  267. }
  268. };
  269. </script>
  270. <style lang="scss">
  271. @import "styles/global.scss";
  272. * {
  273. box-sizing: border-box;
  274. }
  275. html {
  276. width: 100%;
  277. height: 100%;
  278. color: rgba(0, 0, 0, 0.87);
  279. body {
  280. width: 100%;
  281. height: 100%;
  282. margin: 0;
  283. padding: 0;
  284. }
  285. }
  286. @media only screen and (min-width: 1200px) {
  287. html {
  288. font-size: 15px;
  289. }
  290. }
  291. @media only screen and (min-width: 992px) {
  292. html {
  293. font-size: 14.5px;
  294. }
  295. }
  296. @media only screen and (min-width: 0) {
  297. html {
  298. font-size: 14px;
  299. }
  300. }
  301. .under-content {
  302. width: calc(100% - 40px);
  303. left: 20px;
  304. right: 20px;
  305. bottom: 10px;
  306. text-align: left;
  307. height: 25px;
  308. position: absolute;
  309. margin-bottom: 10px;
  310. line-height: 1;
  311. font-size: 24px;
  312. vertical-align: middle;
  313. p {
  314. font-size: 15px;
  315. line-height: 15px;
  316. display: inline;
  317. }
  318. * {
  319. z-index: 10;
  320. position: relative;
  321. }
  322. .right-icon {
  323. float: right;
  324. }
  325. .purple-icon {
  326. color: $light-purple;
  327. }
  328. .red-icon {
  329. color: $dark-pink;
  330. }
  331. }
  332. .users-count {
  333. font-size: 20px;
  334. position: relative;
  335. top: -4px;
  336. }
  337. .right {
  338. float: right;
  339. }
  340. .group {
  341. min-height: 64px;
  342. }
  343. .station-card {
  344. margin: 10px;
  345. cursor: pointer;
  346. height: 475px;
  347. transition: all ease-in-out 0.2s;
  348. .card-content {
  349. max-height: 159px;
  350. .content {
  351. word-wrap: break-word;
  352. overflow: hidden;
  353. text-overflow: ellipsis;
  354. display: -webkit-box;
  355. -webkit-box-orient: vertical;
  356. -webkit-line-clamp: 3;
  357. line-height: 20px;
  358. max-height: 60px;
  359. }
  360. }
  361. .card-image {
  362. .image {
  363. .ytThumbnailBg {
  364. background: url("/assets/notes-transparent.png") no-repeat
  365. center center;
  366. background-size: cover;
  367. height: 100%;
  368. width: 100%;
  369. position: absolute;
  370. top: 0;
  371. filter: blur(5px);
  372. }
  373. img {
  374. height: auto;
  375. width: 100%;
  376. top: 0;
  377. margin-top: auto;
  378. margin-bottom: auto;
  379. z-index: 1;
  380. }
  381. }
  382. }
  383. }
  384. .station-card:hover {
  385. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.3), 0 0 10px rgba(10, 10, 10, 0.3);
  386. transition: all ease-in-out 0.2s;
  387. }
  388. /*.isPrivate {
  389. background-color: #F8BBD0;
  390. }
  391. .isMine {
  392. background-color: #29B6F6;
  393. }*/
  394. .community-button {
  395. cursor: pointer;
  396. transition: 0.25s ease color;
  397. font-size: 30px;
  398. color: #4a4a4a;
  399. }
  400. .community-button:hover {
  401. color: #03a9f4;
  402. }
  403. .station-privacy {
  404. text-transform: capitalize;
  405. }
  406. .label {
  407. display: flex;
  408. }
  409. .g-recaptcha {
  410. display: flex;
  411. justify-content: center;
  412. margin-top: 20px;
  413. }
  414. .group {
  415. text-align: center;
  416. width: 100%;
  417. margin: 64px 0 0 0;
  418. padding-bottom: 240px;
  419. .group-title {
  420. float: left;
  421. clear: none;
  422. width: 100%;
  423. height: 64px;
  424. line-height: 48px;
  425. text-align: center;
  426. font-size: 48px;
  427. margin-bottom: 25px;
  428. }
  429. }
  430. .group .card {
  431. display: inline-flex;
  432. flex-direction: column;
  433. overflow: hidden;
  434. .content {
  435. text-align: left;
  436. word-wrap: break-word;
  437. }
  438. .media {
  439. display: flex;
  440. align-items: center;
  441. .station-status {
  442. line-height: 13px;
  443. }
  444. i {
  445. font-size: 26px;
  446. }
  447. .yellow-icon {
  448. color: $yellow;
  449. margin-right: 6px;
  450. font-size: 28px;
  451. }
  452. .green-icon {
  453. color: $lime;
  454. }
  455. h5 {
  456. margin: 0;
  457. display: inline;
  458. margin-right: 6px;
  459. line-height: 30px;
  460. }
  461. }
  462. }
  463. .displayName {
  464. word-wrap: break-word;
  465. width: 80%;
  466. word-wrap: break-word;
  467. overflow: hidden;
  468. text-overflow: ellipsis;
  469. display: flex;
  470. line-height: 30px;
  471. max-height: 30px;
  472. //position: relative;
  473. }
  474. </style>