Home.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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. .app {
  349. display: flex;
  350. flex-direction: column;
  351. }
  352. .users-count {
  353. font-size: 20px;
  354. position: relative;
  355. top: -4px;
  356. }
  357. .group {
  358. min-height: 64px;
  359. flex: 1 0 auto;
  360. }
  361. .station-card {
  362. display: inline-flex;
  363. flex-direction: column;
  364. overflow: hidden;
  365. margin: 10px;
  366. cursor: pointer;
  367. height: 485px;
  368. transition: all ease-in-out 0.2s;
  369. .card-content {
  370. padding: 10px 15px;
  371. .media {
  372. display: flex;
  373. align-items: center;
  374. .displayName {
  375. display: flex;
  376. align-items: center;
  377. word-wrap: break-word;
  378. width: 80%;
  379. word-wrap: break-word;
  380. overflow: hidden;
  381. text-overflow: ellipsis;
  382. display: flex;
  383. line-height: 30px;
  384. max-height: 30px;
  385. h5 {
  386. font-weight: 400;
  387. margin: 0;
  388. display: inline;
  389. margin-right: 6px;
  390. line-height: 30px;
  391. }
  392. i {
  393. font-size: 22px;
  394. }
  395. .blue-icon {
  396. color: $musareBlue;
  397. }
  398. }
  399. }
  400. .content {
  401. word-wrap: break-word;
  402. overflow: hidden;
  403. text-overflow: ellipsis;
  404. display: -webkit-box;
  405. -webkit-box-orient: vertical;
  406. -webkit-line-clamp: 3;
  407. line-height: 20px;
  408. height: 60px;
  409. text-align: left;
  410. word-wrap: break-word;
  411. margin-bottom: 0;
  412. }
  413. }
  414. .card-image {
  415. .image {
  416. .ytThumbnailBg {
  417. background: url("/assets/notes-transparent.png") no-repeat
  418. center center;
  419. background-size: cover;
  420. height: 100%;
  421. width: 100%;
  422. position: absolute;
  423. top: 0;
  424. filter: blur(3px);
  425. }
  426. img {
  427. height: auto;
  428. width: 100%;
  429. top: 0;
  430. margin-top: auto;
  431. margin-bottom: auto;
  432. z-index: 1;
  433. }
  434. }
  435. }
  436. .bottomBar {
  437. position: relative;
  438. display: flex;
  439. align-items: center;
  440. background: $primary-color;
  441. width: 100%;
  442. height: 30px;
  443. line-height: 30px;
  444. color: $white;
  445. font-weight: 400;
  446. font-size: 12px;
  447. i.material-icons {
  448. vertical-align: middle;
  449. margin-left: 5px;
  450. font-size: 18px;
  451. }
  452. .songTitle {
  453. text-align: left;
  454. vertical-align: middle;
  455. margin-left: 5px;
  456. line-height: 30px;
  457. flex: 2 1 0;
  458. overflow: hidden;
  459. text-overflow: ellipsis;
  460. white-space: nowrap;
  461. }
  462. }
  463. }
  464. .station-card:hover {
  465. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.3), 0 0 10px rgba(10, 10, 10, 0.3);
  466. transition: all ease-in-out 0.2s;
  467. }
  468. /*.isPrivate {
  469. background-color: #F8BBD0;
  470. }
  471. .isMine {
  472. background-color: #29B6F6;
  473. }*/
  474. .community-button {
  475. cursor: pointer;
  476. transition: 0.25s ease color;
  477. font-size: 30px;
  478. color: #4a4a4a;
  479. }
  480. .community-button:hover {
  481. color: #03a9f4;
  482. }
  483. .station-privacy {
  484. text-transform: capitalize;
  485. }
  486. .label {
  487. display: flex;
  488. }
  489. .g-recaptcha {
  490. display: flex;
  491. justify-content: center;
  492. margin-top: 20px;
  493. }
  494. .group {
  495. text-align: center;
  496. width: 100%;
  497. margin: 64px 0 0 0;
  498. padding-bottom: 240px;
  499. .group-title {
  500. float: left;
  501. clear: none;
  502. width: 100%;
  503. height: 64px;
  504. line-height: 48px;
  505. text-align: center;
  506. font-size: 48px;
  507. margin-bottom: 25px;
  508. }
  509. }
  510. </style>