Home.vue 10 KB

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