Home.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. <template>
  2. <div>
  3. <div class="app" :class="{ nightMode: nightMode }">
  4. <main-header />
  5. <div class="group">
  6. <div class="group-title">
  7. Official Stations
  8. </div>
  9. <router-link
  10. v-for="(station, index) in stations.official"
  11. :key="index"
  12. class="card station-card"
  13. :to="{ name: 'official', params: { id: station.name } }"
  14. :class="{ isPrivate: station.privacy === 'private' }"
  15. >
  16. <div class="card-image">
  17. <figure class="image is-square">
  18. <img
  19. :src="station.currentSong.thumbnail"
  20. onerror="this.src='/assets/notes-transparent.png'"
  21. />
  22. </figure>
  23. </div>
  24. <div class="card-content">
  25. <div class="media">
  26. <div class="media-left displayName">
  27. <h5>{{ station.displayName }}</h5>
  28. </div>
  29. </div>
  30. <div class="content">
  31. {{ station.description }}
  32. </div>
  33. <div class="under-content">
  34. <span class="official"
  35. ><i class="badge material-icons"
  36. >verified_user</i
  37. >Official</span
  38. >
  39. <i
  40. v-if="station.privacy !== 'public'"
  41. class="material-icons right-icon"
  42. title="This station is not visible to other users."
  43. >lock</i
  44. >
  45. </div>
  46. </div>
  47. <router-link
  48. href="#"
  49. class="absolute-a"
  50. :to="{ name: 'official', params: { id: station.name } }"
  51. />
  52. </router-link>
  53. </div>
  54. <div class="group">
  55. <div class="group-title">
  56. Community Stations&nbsp;
  57. <a
  58. v-if="$parent.loggedIn"
  59. href="#"
  60. @click="
  61. toggleModal({
  62. sector: 'home',
  63. modal: 'createCommunityStation'
  64. })
  65. "
  66. >
  67. <i class="material-icons community-button"
  68. >add_circle_outline</i
  69. >
  70. </a>
  71. </div>
  72. <router-link
  73. v-for="(station, index) in stations.community"
  74. :key="index"
  75. :to="{ name: 'community', params: { id: station.name } }"
  76. class="card station-card"
  77. :class="{
  78. isPrivate: station.privacy === 'private',
  79. isMine: isOwner(station)
  80. }"
  81. >
  82. <div class="card-image">
  83. <figure class="image is-square">
  84. <img
  85. :src="station.currentSong.thumbnail"
  86. onerror="this.src='/assets/notes-transparent.png'"
  87. />
  88. </figure>
  89. </div>
  90. <div class="card-content">
  91. <div class="media">
  92. <div class="media-left displayName">
  93. <h5>{{ station.displayName }}</h5>
  94. </div>
  95. </div>
  96. <div class="content">
  97. {{ station.description }}
  98. </div>
  99. <div class="under-content">
  100. <span class="hostedby"
  101. >Hosted by
  102. <span class="host"
  103. >{{
  104. $parent.getUsernameFromId(station.owner)
  105. }}
  106. {{ userIdMap["Z" + station.owner] }}</span
  107. ></span
  108. >
  109. <i
  110. v-if="station.privacy !== 'public'"
  111. class="material-icons right-icon"
  112. title="This station is not visible to other users."
  113. >lock</i
  114. >
  115. <i
  116. v-if="isOwner(station)"
  117. class="material-icons right-icon"
  118. title="This is your station."
  119. >home</i
  120. >
  121. </div>
  122. </div>
  123. <router-link
  124. href="#"
  125. class="absolute-a"
  126. :to="{
  127. name: 'community',
  128. params: { id: station.name }
  129. }"
  130. />
  131. </router-link>
  132. </div>
  133. <main-footer />
  134. </div>
  135. <create-community-station v-if="modals.createCommunityStation" />
  136. </div>
  137. </template>
  138. <script>
  139. import { mapState, mapActions } from "vuex";
  140. import MainHeader from "../MainHeader.vue";
  141. import MainFooter from "../MainFooter.vue";
  142. import CreateCommunityStation from "../Modals/CreateCommunityStation.vue";
  143. import auth from "../../auth";
  144. import io from "../../io";
  145. export default {
  146. data() {
  147. return {
  148. recaptcha: {
  149. key: ""
  150. },
  151. stations: {
  152. official: [],
  153. community: []
  154. },
  155. userIdMap: this.$parent.userIdMap,
  156. nightMode: false
  157. };
  158. },
  159. computed: mapState("modals", {
  160. modals: state => state.modals.home
  161. }),
  162. mounted() {
  163. let _this = this;
  164. auth.getStatus(() => {
  165. io.getSocket(socket => {
  166. _this.socket = socket;
  167. if (_this.socket.connected) _this.init();
  168. io.onConnect(() => {
  169. _this.init();
  170. });
  171. _this.socket.on("event:stations.created", station => {
  172. if (!station.currentSong)
  173. station.currentSong = {
  174. thumbnail: "/assets/notes-transparent.png"
  175. };
  176. if (station.currentSong && !station.currentSong.thumbnail)
  177. station.currentSong.thumbnail =
  178. "/assets/notes-transparent.png";
  179. _this.stations[station.type].push(station);
  180. });
  181. _this.socket.on(
  182. "event:userCount.updated",
  183. (stationId, userCount) => {
  184. _this.stations.official.forEach(station => {
  185. if (station._id === stationId) {
  186. station.userCount = userCount;
  187. }
  188. });
  189. _this.stations.community.forEach(station => {
  190. if (station._id === stationId) {
  191. station.userCount = userCount;
  192. }
  193. });
  194. }
  195. );
  196. _this.socket.on(
  197. "event:station.nextSong",
  198. (stationId, newSong) => {
  199. _this.stations.official.forEach(station => {
  200. if (station._id === stationId) {
  201. if (!newSong)
  202. newSong = {
  203. thumbnail:
  204. "/assets/notes-transparent.png"
  205. };
  206. if (newSong && !newSong.thumbnail)
  207. newSong.thumbnail =
  208. "/assets/notes-transparent.png";
  209. station.currentSong = newSong;
  210. }
  211. });
  212. _this.stations.community.forEach(station => {
  213. if (station._id === stationId) {
  214. if (!newSong)
  215. newSong = {
  216. thumbnail:
  217. "/assets/notes-transparent.png"
  218. };
  219. if (newSong && !newSong.thumbnail)
  220. newSong.thumbnail =
  221. "/assets/notes-transparent.png";
  222. station.currentSong = newSong;
  223. }
  224. });
  225. }
  226. );
  227. });
  228. });
  229. },
  230. methods: {
  231. init: function() {
  232. let _this = this;
  233. auth.getStatus((authenticated, role, username, userId) => {
  234. _this.socket.emit("stations.index", data => {
  235. _this.stations.community = [];
  236. _this.stations.official = [];
  237. if (data.status === "success")
  238. data.stations.forEach(station => {
  239. if (!station.currentSong)
  240. station.currentSong = {
  241. thumbnail: "/assets/notes-transparent.png"
  242. };
  243. if (
  244. station.currentSong &&
  245. !station.currentSong.thumbnail
  246. )
  247. station.currentSong.thumbnail =
  248. "/assets/notes-transparent.png";
  249. if (station.privacy !== "public")
  250. station.class = { "station-red": true };
  251. else if (
  252. station.type === "community" &&
  253. station.owner === userId
  254. )
  255. station.class = { "station-blue": true };
  256. if (station.type == "official")
  257. _this.stations.official.push(station);
  258. else _this.stations.community.push(station);
  259. });
  260. });
  261. _this.socket.emit("apis.joinRoom", "home", () => {});
  262. });
  263. },
  264. isOwner: function(station) {
  265. let _this = this;
  266. return (
  267. station.owner === _this.$parent.userId &&
  268. station.privacy === "public"
  269. );
  270. },
  271. ...mapActions("modals", ["toggleModal"])
  272. },
  273. components: { MainHeader, MainFooter, CreateCommunityStation }
  274. };
  275. </script>
  276. <style lang="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. @media only screen and (min-width: 1200px) {
  292. html {
  293. font-size: 15px;
  294. }
  295. }
  296. @media only screen and (min-width: 992px) {
  297. html {
  298. font-size: 14.5px;
  299. }
  300. }
  301. @media only screen and (min-width: 0) {
  302. html {
  303. font-size: 14px;
  304. }
  305. }
  306. .under-content {
  307. width: calc(100% - 40px);
  308. left: 20px;
  309. right: 20px;
  310. bottom: 10px;
  311. text-align: left;
  312. height: 25px;
  313. position: absolute;
  314. margin-bottom: 10px;
  315. line-height: 1;
  316. font-size: 24px;
  317. vertical-align: middle;
  318. * {
  319. z-index: 10;
  320. position: relative;
  321. }
  322. .official {
  323. font-size: 18px;
  324. color: #03a9f4;
  325. position: relative;
  326. top: -5px;
  327. .badge {
  328. position: relative;
  329. padding-right: 2px;
  330. color: #38d227;
  331. top: +5px;
  332. }
  333. }
  334. .hostedby {
  335. font-size: 15px;
  336. .host {
  337. font-size: 18px;
  338. color: #03a9f4;
  339. }
  340. }
  341. .right-icon {
  342. float: right;
  343. }
  344. }
  345. .users-count {
  346. font-size: 20px;
  347. position: relative;
  348. top: -4px;
  349. }
  350. .right {
  351. float: right;
  352. }
  353. .group {
  354. min-height: 64px;
  355. }
  356. .station-card {
  357. margin: 10px;
  358. cursor: pointer;
  359. height: 475px;
  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: #4a4a4a;
  390. }
  391. .community-button:hover {
  392. color: #03a9f4;
  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. margin: 64px 0 0 0;
  409. .group-title {
  410. float: left;
  411. clear: none;
  412. width: 100%;
  413. height: 64px;
  414. line-height: 48px;
  415. text-align: center;
  416. font-size: 48px;
  417. margin-bottom: 25px;
  418. }
  419. }
  420. .group .card {
  421. display: inline-flex;
  422. flex-direction: column;
  423. overflow: hidden;
  424. .content {
  425. text-align: left;
  426. word-wrap: break-word;
  427. }
  428. .media {
  429. display: flex;
  430. align-items: center;
  431. .station-status {
  432. line-height: 13px;
  433. }
  434. h5 {
  435. margin: 0;
  436. }
  437. }
  438. }
  439. .displayName {
  440. word-wrap: break-word;
  441. width: 80%;
  442. word-wrap: break-word;
  443. overflow: hidden;
  444. text-overflow: ellipsis;
  445. display: -webkit-box;
  446. -webkit-box-orient: vertical;
  447. -webkit-line-clamp: 1;
  448. line-height: 30px;
  449. max-height: 30px;
  450. }
  451. .nightMode {
  452. background-color: rgb(51, 51, 51);
  453. color: #e6e6e6;
  454. .community-button {
  455. cursor: pointer;
  456. transition: 0.25s ease color;
  457. font-size: 30px;
  458. color: #e6e6e6;
  459. }
  460. .community-button:hover {
  461. color: #03a9f4;
  462. }
  463. .station-card {
  464. margin: 10px;
  465. cursor: pointer;
  466. height: 475px;
  467. background-color: rgb(51, 51, 51);
  468. color: #e6e6e6;
  469. .card-content {
  470. max-height: 159px;
  471. color: #e6e6e6;
  472. .content {
  473. word-wrap: break-word;
  474. overflow: hidden;
  475. text-overflow: ellipsis;
  476. display: -webkit-box;
  477. -webkit-box-orient: vertical;
  478. -webkit-line-clamp: 3;
  479. line-height: 20px;
  480. max-height: 60px;
  481. color: #e6e6e6;
  482. }
  483. }
  484. }
  485. .station-card:hover {
  486. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.3),
  487. 0 0 10px rgba(10, 10, 10, 0.3);
  488. }
  489. .isPrivate {
  490. background-color: #d01657;
  491. }
  492. .isMine {
  493. background-color: #0777ab;
  494. }
  495. }
  496. </style>