Home.vue 7.0 KB

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