Home.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <div class="app" :class="{'nightMode': nightMode}">
  3. <main-header></main-header>
  4. <div class="group">
  5. <div class="group-title">Official Stations</div>
  6. <div class="card station-card" v-for="station in stations.official" v-link="{ path: '/' + station.name }" @click="this.$dispatch('joinStation', station._id)" :class="{'isPrivate': station.privacy === 'private'}">
  7. <div class="card-image">
  8. <figure class="image is-square">
  9. <img :src="station.currentSong.thumbnail" onerror="this.src='/assets/notes-transparent.png'" />
  10. </figure>
  11. </div>
  12. <div class="card-content">
  13. <div class="media">
  14. <div class="media-left displayName">
  15. <h5>{{ station.displayName }}</h5>
  16. </div>
  17. </div>
  18. <div class="content">
  19. {{ station.description }}
  20. </div>
  21. <div class="under-content">
  22. <i class='material-icons' title="How many users there are in the station.">people</i>
  23. <span class="users-count" title="How many users there are in the station.">&nbsp;{{station.userCount}}</span>
  24. </div>
  25. </div>
  26. <a @click="this.$dispatch('joinStation', station._id)" href='#' class='absolute-a' v-link="{ path: '/' + station.name }"></a>
  27. </div>
  28. </div>
  29. <div class="group">
  30. <div class="group-title">
  31. Community Stations&nbsp;
  32. <a @click='modals.createCommunityStation = !modals.createCommunityStation' v-if="$parent.loggedIn" href='#'>
  33. <i class="material-icons community-button">add_circle_outline</i></a>
  34. </div>
  35. <div class="card station-card" v-for="station in stations.community" v-link="{ path: '/community/' + station.name }" @click="this.$dispatch('joinStation', station._id)" :class="{'isPrivate': station.privacy === 'private','isMine': isOwner(station)}">
  36. <div class="card-image">
  37. <figure class="image is-square">
  38. <img :src="station.currentSong.thumbnail" onerror="this.src='/assets/notes-transparent.png'" />
  39. </figure>
  40. </div>
  41. <div class="card-content">
  42. <div class="media">
  43. <div class="media-left displayName">
  44. <h5>{{ station.displayName }}</h5>
  45. </div>
  46. </div>
  47. <div class="content">
  48. {{ station.description }}
  49. </div>
  50. <div class="under-content">
  51. <i class='material-icons' title="How many users there are in the station.">people</i>
  52. <span class="users-count" title="How many users there are in the station.">&nbsp;{{station.userCount}}</span>
  53. </div>
  54. </div>
  55. <a @click="this.$dispatch('joinStation', station._id)" href='#' class='absolute-a' v-link="{ path: '/community/' + station.name }"></a>
  56. </div>
  57. </div>
  58. <main-footer></main-footer>
  59. </div>
  60. <create-community-station v-if='modals.createCommunityStation'></create-community-station>
  61. </template>
  62. <script>
  63. import MainHeader from '../MainHeader.vue';
  64. import MainFooter from '../MainFooter.vue';
  65. import CreateCommunityStation from '../Modals/CreateCommunityStation.vue';
  66. import auth from '../../auth';
  67. import io from '../../io';
  68. export default {
  69. data() {
  70. return {
  71. recaptcha: {
  72. key: ''
  73. },
  74. stations: {
  75. official: [],
  76. community: []
  77. },
  78. modals: {
  79. createCommunityStation: false
  80. },
  81. nightMode: false
  82. }
  83. },
  84. ready() {
  85. let _this = this;
  86. auth.getStatus((authenticated, role, username, userId) => {
  87. io.getSocket((socket) => {
  88. _this.socket = socket;
  89. if (_this.socket.connected) _this.init();
  90. io.onConnect(() => {
  91. _this.init();
  92. });
  93. _this.socket.on('event:stations.created', station => {
  94. if (!station.currentSong) station.currentSong = { thumbnail: '/assets/notes-transparent.png' };
  95. if (station.currentSong && !station.currentSong.thumbnail) station.currentSong.thumbnail = "/assets/notes-transparent.png";
  96. _this.stations[station.type].push(station);
  97. });
  98. _this.socket.on('event:userCount.updated', (stationId, userCount) => {
  99. _this.stations.official.forEach((station) => {
  100. if (station._id === stationId) {
  101. station.userCount = userCount;
  102. }
  103. });
  104. _this.stations.community.forEach((station) => {
  105. if (station._id === stationId) {
  106. station.userCount = userCount;
  107. }
  108. });
  109. });
  110. _this.socket.on('event:station.nextSong', (stationId, newSong) => {
  111. _this.stations.official.forEach((station) => {
  112. if (station._id === stationId) {
  113. if (!newSong) newSong = { thumbnail: '/assets/notes-transparent.png' };
  114. if (newSong && !newSong.thumbnail) newSong.thumbnail = "/assets/notes-transparent.png";
  115. station.currentSong = newSong;
  116. }
  117. });
  118. _this.stations.community.forEach((station) => {
  119. if (station._id === stationId) {
  120. if (!newSong) newSong = { thumbnail: '/assets/notes-transparent.png' };
  121. if (newSong && !newSong.thumbnail) newSong.thumbnail = "/assets/notes-transparent.png";
  122. station.currentSong = newSong;
  123. }
  124. });
  125. });
  126. });
  127. });
  128. },
  129. methods: {
  130. toggleModal: function (type) {
  131. this.$dispatch('toggleModal', type);
  132. },
  133. init: function() {
  134. let _this = this;
  135. auth.getStatus((authenticated, role, username, userId) => {
  136. _this.socket.emit('stations.index', data => {
  137. _this.stations.community = [];
  138. _this.stations.official = [];
  139. if (data.status === "success") data.stations.forEach(station => {
  140. if (!station.currentSong) station.currentSong = { thumbnail: '/assets/notes-transparent.png' };
  141. if (station.currentSong && !station.currentSong.thumbnail) station.currentSong.thumbnail = "/assets/notes-transparent.png";
  142. if (station.privacy !== 'public') station.class = { 'station-red': true }
  143. else if (station.type === 'community' && station.owner === userId) station.class = { 'station-blue': true }
  144. if (station.type == 'official') _this.stations.official.push(station);
  145. else _this.stations.community.push(station);
  146. });
  147. });
  148. _this.socket.emit("apis.joinRoom", 'home', () => {
  149. });
  150. });
  151. },
  152. isOwner: function(station) {
  153. let _this = this;
  154. return station.owner === _this.$parent.userId && station.privacy === 'public';
  155. }
  156. },
  157. components: { MainHeader, MainFooter, CreateCommunityStation }
  158. }
  159. </script>
  160. <style lang='scss'>
  161. @import 'theme.scss';
  162. * { box-sizing: border-box; }
  163. html {
  164. width: 100%;
  165. height: 100%;
  166. color: rgba(0, 0, 0, 0.87);
  167. body {
  168. width: 100%;
  169. height: 100%;
  170. margin: 0;
  171. padding: 0;
  172. }
  173. }
  174. @media only screen and (min-width: 1200px) {
  175. html { font-size: 15px; }
  176. }
  177. @media only screen and (min-width: 992px) {
  178. html { font-size: 14.5px; }
  179. }
  180. @media only screen and (min-width: 0) {
  181. html { font-size: 14px; }
  182. }
  183. .under-content {
  184. text-align: left;
  185. height: 25px;
  186. bottom: 0;
  187. position: absolute;
  188. margin-bottom: 10px;
  189. * {
  190. z-index: 10;
  191. position: relative;
  192. }
  193. }
  194. .users-count {
  195. font-size: 20px;
  196. position: relative;
  197. top: -4px;
  198. }
  199. .right {
  200. float: right;
  201. }
  202. .group { min-height: 64px; }
  203. .station-card {
  204. margin: 10px;
  205. cursor: pointer;
  206. height: 475px;
  207. .card-content {
  208. max-height: 159px;
  209. .content {
  210. word-wrap: break-word;
  211. overflow: hidden;
  212. text-overflow: ellipsis;
  213. display: -webkit-box;
  214. -webkit-box-orient: vertical;
  215. -webkit-line-clamp: 3;
  216. line-height: 20px;
  217. max-height: 60px;
  218. }
  219. }
  220. }
  221. .station-card:hover {
  222. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.3), 0 0 10px rgba(10, 10, 10, 0.3);
  223. }
  224. .isPrivate {
  225. background-color: #F8BBD0;
  226. }
  227. .isMine {
  228. background-color: #29B6F6;
  229. }
  230. .community-button {
  231. cursor: pointer;
  232. transition: .25s ease color;
  233. font-size: 30px;
  234. color: #4a4a4a;
  235. }
  236. .community-button:hover { color: #03a9f4; }
  237. .station-privacy { text-transform: capitalize; }
  238. .label { display: flex; }
  239. .g-recaptcha {
  240. display: flex;
  241. justify-content: center;
  242. margin-top: 20px;
  243. }
  244. .group {
  245. text-align: center;
  246. width: 100%;
  247. margin: 64px 0 0 0;
  248. .group-title {
  249. float: left;
  250. clear: none;
  251. width: 100%;
  252. height: 64px;
  253. line-height: 48px;
  254. text-align: center;
  255. font-size: 48px;
  256. margin-bottom: 25px;
  257. }
  258. }
  259. .group .card {
  260. display: inline-flex;
  261. flex-direction: column;
  262. overflow: hidden;
  263. .content {
  264. text-align: left;
  265. word-wrap: break-word;
  266. }
  267. .media {
  268. display: flex;
  269. align-items: center;
  270. .station-status { line-height: 13px; }
  271. h5 { margin: 0; }
  272. }
  273. }
  274. .displayName {
  275. word-wrap: break-word;
  276. width: 80%;
  277. }
  278. .nightMode {
  279. background-color: rgb(51, 51, 51);
  280. color: #e6e6e6;
  281. .community-button {
  282. cursor: pointer;
  283. transition: .25s ease color;
  284. font-size: 30px;
  285. color: #e6e6e6;
  286. }
  287. .community-button:hover { color: #03a9f4; }
  288. .station-card {
  289. margin: 10px;
  290. cursor: pointer;
  291. height: 475px;
  292. background-color: rgb(51, 51, 51);
  293. color: #e6e6e6;
  294. .card-content {
  295. max-height: 159px;
  296. color: #e6e6e6;
  297. .content {
  298. word-wrap: break-word;
  299. overflow: hidden;
  300. text-overflow: ellipsis;
  301. display: -webkit-box;
  302. -webkit-box-orient: vertical;
  303. -webkit-line-clamp: 3;
  304. line-height: 20px;
  305. max-height: 60px;
  306. color: #e6e6e6;
  307. }
  308. }
  309. }
  310. .station-card:hover {
  311. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.3), 0 0 10px rgba(10, 10, 10, 0.3);
  312. }
  313. .isPrivate {
  314. background-color: #d01657;
  315. }
  316. .isMine {
  317. background-color: #0777ab;
  318. }
  319. }
  320. </style>