Home.vue 11 KB

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