Home.vue 8.1 KB

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