Home.vue 11 KB

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