Home.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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. .night-mode {
  289. .card,
  290. .card-content,
  291. .card-content div {
  292. background-color: $night-mode-secondary;
  293. }
  294. .card-content .icons i {
  295. color: #ddd;
  296. }
  297. .card-image .image {
  298. background-color: #333;
  299. }
  300. }
  301. @media only screen and (min-width: 1200px) {
  302. html {
  303. font-size: 15px;
  304. }
  305. }
  306. @media only screen and (min-width: 992px) {
  307. html {
  308. font-size: 14.5px;
  309. }
  310. }
  311. @media only screen and (min-width: 0) {
  312. html {
  313. font-size: 14px;
  314. }
  315. }
  316. .under-content {
  317. height: 25px;
  318. position: relative;
  319. line-height: 1;
  320. font-size: 24px;
  321. display: flex;
  322. align-items: center;
  323. text-align: left;
  324. margin-top: 10px;
  325. p {
  326. font-size: 15px;
  327. line-height: 15px;
  328. display: inline;
  329. }
  330. i {
  331. font-size: 20px;
  332. }
  333. * {
  334. z-index: 10;
  335. position: relative;
  336. }
  337. .icons {
  338. position: absolute;
  339. right: 0;
  340. .dark-grey-icon {
  341. color: $dark-grey-2;
  342. }
  343. }
  344. }
  345. .users-count {
  346. font-size: 20px;
  347. position: relative;
  348. top: -4px;
  349. }
  350. .group {
  351. min-height: 64px;
  352. }
  353. .station-card {
  354. display: inline-flex;
  355. flex-direction: column;
  356. overflow: hidden;
  357. margin: 10px;
  358. cursor: pointer;
  359. height: 485px;
  360. transition: all ease-in-out 0.2s;
  361. .card-content {
  362. padding: 10px 15px;
  363. .media {
  364. display: flex;
  365. align-items: center;
  366. .displayName {
  367. display: flex;
  368. align-items: center;
  369. word-wrap: break-word;
  370. width: 80%;
  371. word-wrap: break-word;
  372. overflow: hidden;
  373. text-overflow: ellipsis;
  374. display: flex;
  375. line-height: 30px;
  376. max-height: 30px;
  377. h5 {
  378. font-weight: 400;
  379. margin: 0;
  380. display: inline;
  381. margin-right: 6px;
  382. line-height: 30px;
  383. }
  384. i {
  385. font-size: 22px;
  386. }
  387. .blue-icon {
  388. color: $musareBlue;
  389. }
  390. }
  391. }
  392. .content {
  393. word-wrap: break-word;
  394. overflow: hidden;
  395. text-overflow: ellipsis;
  396. display: -webkit-box;
  397. -webkit-box-orient: vertical;
  398. -webkit-line-clamp: 3;
  399. line-height: 20px;
  400. height: 60px;
  401. text-align: left;
  402. word-wrap: break-word;
  403. margin-bottom: 0;
  404. }
  405. }
  406. .card-image {
  407. .image {
  408. .ytThumbnailBg {
  409. background: url("/assets/notes-transparent.png") no-repeat
  410. center center;
  411. background-size: cover;
  412. height: 100%;
  413. width: 100%;
  414. position: absolute;
  415. top: 0;
  416. filter: blur(3px);
  417. }
  418. img {
  419. height: auto;
  420. width: 100%;
  421. top: 0;
  422. margin-top: auto;
  423. margin-bottom: auto;
  424. z-index: 1;
  425. }
  426. }
  427. }
  428. .bottomBar {
  429. position: relative;
  430. display: flex;
  431. align-items: center;
  432. background: $primary-color;
  433. width: 100%;
  434. height: 30px;
  435. line-height: 30px;
  436. color: $white;
  437. font-weight: 400;
  438. font-size: 12px;
  439. i.material-icons {
  440. vertical-align: middle;
  441. margin-left: 5px;
  442. font-size: 18px;
  443. }
  444. .songTitle {
  445. text-align: left;
  446. vertical-align: middle;
  447. margin-left: 5px;
  448. line-height: 30px;
  449. flex: 2 1 0;
  450. overflow: hidden;
  451. text-overflow: ellipsis;
  452. white-space: nowrap;
  453. }
  454. }
  455. }
  456. .station-card:hover {
  457. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.3), 0 0 10px rgba(10, 10, 10, 0.3);
  458. transition: all ease-in-out 0.2s;
  459. }
  460. /*.isPrivate {
  461. background-color: #F8BBD0;
  462. }
  463. .isMine {
  464. background-color: #29B6F6;
  465. }*/
  466. .community-button {
  467. cursor: pointer;
  468. transition: 0.25s ease color;
  469. font-size: 30px;
  470. color: #4a4a4a;
  471. }
  472. .community-button:hover {
  473. color: #03a9f4;
  474. }
  475. .station-privacy {
  476. text-transform: capitalize;
  477. }
  478. .label {
  479. display: flex;
  480. }
  481. .g-recaptcha {
  482. display: flex;
  483. justify-content: center;
  484. margin-top: 20px;
  485. }
  486. .group {
  487. text-align: center;
  488. width: 100%;
  489. margin: 64px 0 0 0;
  490. padding-bottom: 240px;
  491. .group-title {
  492. float: left;
  493. clear: none;
  494. width: 100%;
  495. height: 64px;
  496. line-height: 48px;
  497. text-align: center;
  498. font-size: 48px;
  499. margin-bottom: 25px;
  500. }
  501. }
  502. </style>