Home.vue 9.6 KB

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