Home.vue 6.4 KB

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