Home.vue 6.8 KB

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