Home.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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. <user-id-to-username
  104. :userId="station.owner"
  105. :link="true"
  106. />
  107. </span>
  108. </span>
  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 UserIdToUsername from "../UserIdToUsername.vue";
  144. import auth from "../../auth";
  145. import io from "../../io";
  146. export default {
  147. data() {
  148. return {
  149. recaptcha: {
  150. key: ""
  151. },
  152. stations: {
  153. official: [],
  154. community: []
  155. },
  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: {
  274. MainHeader,
  275. MainFooter,
  276. CreateCommunityStation,
  277. UserIdToUsername
  278. }
  279. };
  280. </script>
  281. <style lang="scss">
  282. * {
  283. box-sizing: border-box;
  284. }
  285. html {
  286. width: 100%;
  287. height: 100%;
  288. color: rgba(0, 0, 0, 0.87);
  289. body {
  290. width: 100%;
  291. height: 100%;
  292. margin: 0;
  293. padding: 0;
  294. }
  295. }
  296. @media only screen and (min-width: 1200px) {
  297. html {
  298. font-size: 15px;
  299. }
  300. }
  301. @media only screen and (min-width: 992px) {
  302. html {
  303. font-size: 14.5px;
  304. }
  305. }
  306. @media only screen and (min-width: 0) {
  307. html {
  308. font-size: 14px;
  309. }
  310. }
  311. .under-content {
  312. width: calc(100% - 40px);
  313. left: 20px;
  314. right: 20px;
  315. bottom: 10px;
  316. text-align: left;
  317. height: 25px;
  318. position: absolute;
  319. margin-bottom: 10px;
  320. line-height: 1;
  321. font-size: 24px;
  322. vertical-align: middle;
  323. * {
  324. z-index: 10;
  325. position: relative;
  326. }
  327. .official {
  328. font-size: 18px;
  329. color: #03a9f4;
  330. position: relative;
  331. top: -5px;
  332. .badge {
  333. position: relative;
  334. padding-right: 2px;
  335. color: #38d227;
  336. top: +5px;
  337. }
  338. }
  339. .hostedby {
  340. font-size: 15px;
  341. .host {
  342. font-size: 18px;
  343. color: #03a9f4;
  344. }
  345. }
  346. .right-icon {
  347. float: right;
  348. }
  349. }
  350. .users-count {
  351. font-size: 20px;
  352. position: relative;
  353. top: -4px;
  354. }
  355. .right {
  356. float: right;
  357. }
  358. .group {
  359. min-height: 64px;
  360. }
  361. .station-card {
  362. margin: 10px;
  363. cursor: pointer;
  364. height: 475px;
  365. transition: all ease-in-out 0.2s;
  366. .card-content {
  367. max-height: 159px;
  368. .content {
  369. word-wrap: break-word;
  370. overflow: hidden;
  371. text-overflow: ellipsis;
  372. display: -webkit-box;
  373. -webkit-box-orient: vertical;
  374. -webkit-line-clamp: 3;
  375. line-height: 20px;
  376. max-height: 60px;
  377. }
  378. }
  379. }
  380. .station-card:hover {
  381. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.3), 0 0 10px rgba(10, 10, 10, 0.3);
  382. transition: all ease-in-out 0.2s;
  383. }
  384. /*.isPrivate {
  385. background-color: #F8BBD0;
  386. }
  387. .isMine {
  388. background-color: #29B6F6;
  389. }*/
  390. .community-button {
  391. cursor: pointer;
  392. transition: 0.25s ease color;
  393. font-size: 30px;
  394. color: #4a4a4a;
  395. }
  396. .community-button:hover {
  397. color: #03a9f4;
  398. }
  399. .station-privacy {
  400. text-transform: capitalize;
  401. }
  402. .label {
  403. display: flex;
  404. }
  405. .g-recaptcha {
  406. display: flex;
  407. justify-content: center;
  408. margin-top: 20px;
  409. }
  410. .group {
  411. text-align: center;
  412. width: 100%;
  413. margin: 64px 0 0 0;
  414. .group-title {
  415. float: left;
  416. clear: none;
  417. width: 100%;
  418. height: 64px;
  419. line-height: 48px;
  420. text-align: center;
  421. font-size: 48px;
  422. margin-bottom: 25px;
  423. }
  424. }
  425. .group .card {
  426. display: inline-flex;
  427. flex-direction: column;
  428. overflow: hidden;
  429. .content {
  430. text-align: left;
  431. word-wrap: break-word;
  432. }
  433. .media {
  434. display: flex;
  435. align-items: center;
  436. .station-status {
  437. line-height: 13px;
  438. }
  439. h5 {
  440. margin: 0;
  441. }
  442. }
  443. }
  444. .displayName {
  445. word-wrap: break-word;
  446. width: 80%;
  447. word-wrap: break-word;
  448. overflow: hidden;
  449. text-overflow: ellipsis;
  450. display: -webkit-box;
  451. -webkit-box-orient: vertical;
  452. -webkit-line-clamp: 1;
  453. line-height: 30px;
  454. max-height: 30px;
  455. }
  456. .nightMode {
  457. background-color: rgb(51, 51, 51);
  458. color: #e6e6e6;
  459. .community-button {
  460. cursor: pointer;
  461. transition: 0.25s ease color;
  462. font-size: 30px;
  463. color: #e6e6e6;
  464. }
  465. .community-button:hover {
  466. color: #03a9f4;
  467. }
  468. .station-card {
  469. margin: 10px;
  470. cursor: pointer;
  471. height: 475px;
  472. background-color: rgb(51, 51, 51);
  473. color: #e6e6e6;
  474. .card-content {
  475. max-height: 159px;
  476. color: #e6e6e6;
  477. .content {
  478. word-wrap: break-word;
  479. overflow: hidden;
  480. text-overflow: ellipsis;
  481. display: -webkit-box;
  482. -webkit-box-orient: vertical;
  483. -webkit-line-clamp: 3;
  484. line-height: 20px;
  485. max-height: 60px;
  486. color: #e6e6e6;
  487. }
  488. }
  489. }
  490. .station-card:hover {
  491. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.3),
  492. 0 0 10px rgba(10, 10, 10, 0.3);
  493. }
  494. .isPrivate {
  495. background-color: #d01657;
  496. }
  497. .isMine {
  498. background-color: #0777ab;
  499. }
  500. }
  501. </style>