Home.vue 11 KB

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