Home.vue 8.0 KB

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