Home.vue 11 KB

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