Home.vue 7.1 KB

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