Home.vue 11 KB

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