SongsList.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <div class="sidebar" transition="slide">
  3. <div class="inner-wrapper">
  4. <div v-if="station.type === 'community'" class="sidebar-title">
  5. Queue
  6. </div>
  7. <div v-else class="sidebar-title">Playlist</div>
  8. <article v-if="!noSong" class="media">
  9. <figure v-if="currentSong.thumbnail" class="media-left">
  10. <p class="image is-64x64">
  11. <img
  12. :src="currentSong.thumbnail"
  13. onerror="this.src='/assets/notes-transparent.png'"
  14. />
  15. </p>
  16. </figure>
  17. <div class="media-content">
  18. <div class="content">
  19. <p>
  20. Current Song:
  21. <strong>{{ currentSong.title }}</strong>
  22. <br />
  23. <small>{{ currentSong.artists }}</small>
  24. </p>
  25. </div>
  26. </div>
  27. <div class="media-right">
  28. {{ utils.formatTime(currentSong.duration) }}
  29. </div>
  30. </article>
  31. <p v-if="noSong" class="has-text-centered">
  32. There is currently no song playing.
  33. </p>
  34. <hr v-if="noSong" />
  35. <article v-for="song in songsList" :key="song.songId" class="media">
  36. <div class="media-content">
  37. <div
  38. class="content"
  39. style="display: block; padding-top: 10px"
  40. >
  41. <strong class="songTitle">{{ song.title }}</strong>
  42. <small>{{ song.artists.join(", ") }}</small>
  43. <div
  44. v-if="
  45. station.type === 'community' &&
  46. station.partyMode === true
  47. "
  48. >
  49. <small>
  50. Requested by
  51. <b>
  52. <user-id-to-username
  53. :userId="song.requestedBy"
  54. :link="true"
  55. />
  56. </b>
  57. </small>
  58. <i
  59. v-if="isOwnerOnly() || isAdminOnly()"
  60. class="material-icons"
  61. style="vertical-align: middle"
  62. @click="removeFromQueue(song.songId)"
  63. >delete_forever</i
  64. >
  65. </div>
  66. </div>
  67. </div>
  68. <div class="media-right">
  69. {{ utils.formatTime(song.duration) }}
  70. </div>
  71. </article>
  72. <div
  73. v-if="
  74. station.type === 'community' &&
  75. loggedIn &&
  76. station.partyMode === true
  77. "
  78. >
  79. <button
  80. v-if="
  81. (station.locked && isOwnerOnly()) ||
  82. !station.locked ||
  83. (station.locked &&
  84. isAdminOnly() &&
  85. dismissedWarning)
  86. "
  87. class="button add-to-queue"
  88. @click="
  89. openModal({
  90. sector: 'station',
  91. modal: 'addSongToQueue'
  92. })
  93. "
  94. >
  95. Add Song to Queue
  96. </button>
  97. <button
  98. v-if="
  99. station.locked &&
  100. isAdminOnly() &&
  101. !isOwnerOnly() &&
  102. !dismissedWarning
  103. "
  104. class="button add-to-queue add-to-queue-warning"
  105. @click="dismissedWarning = true"
  106. >
  107. THIS STATION'S QUEUE IS LOCKED.
  108. </button>
  109. <button
  110. v-if="station.locked && !isAdminOnly() && !isOwnerOnly()"
  111. class="button add-to-queue add-to-queue-disabled"
  112. >
  113. THIS STATION'S QUEUE IS LOCKED.
  114. </button>
  115. </div>
  116. </div>
  117. </div>
  118. </template>
  119. <script>
  120. import { mapState, mapActions } from "vuex";
  121. import Toast from "toasters";
  122. import utils from "../../js/utils";
  123. import UserIdToUsername from "../UserIdToUsername.vue";
  124. export default {
  125. data() {
  126. return {
  127. utils,
  128. dismissedWarning: false
  129. };
  130. },
  131. computed: mapState({
  132. loggedIn: state => state.user.auth.loggedIn,
  133. userId: state => state.user.auth.userId,
  134. role: state => state.user.auth.role,
  135. station: state => state.station.station,
  136. currentSong: state => state.station.currentSong,
  137. songsList: state => state.station.songsList,
  138. noSong: state => state.station.noSong
  139. }),
  140. methods: {
  141. isOwnerOnly() {
  142. return this.loggedIn && this.userId === this.station.owner;
  143. },
  144. isAdminOnly() {
  145. return this.loggedIn && this.role === "admin";
  146. },
  147. removeFromQueue(songId) {
  148. window.socket.emit(
  149. "stations.removeFromQueue",
  150. this.station._id,
  151. songId,
  152. res => {
  153. if (res.status === "success") {
  154. new Toast({
  155. content:
  156. "Successfully removed song from the queue.",
  157. timeout: 4000
  158. });
  159. } else new Toast({ content: res.message, timeout: 8000 });
  160. }
  161. );
  162. },
  163. ...mapActions("modals", ["openModal"])
  164. },
  165. mounted() {
  166. /*
  167. io.getSocket((socket) => {
  168. this.socket = socket;
  169. }); */
  170. },
  171. components: { UserIdToUsername }
  172. };
  173. </script>
  174. <style lang="scss" scoped>
  175. @import "styles/global.scss";
  176. .night-mode {
  177. .sidebar {
  178. background-color: $night-mode-secondary;
  179. .sidebar-title {
  180. color: #fff;
  181. }
  182. * {
  183. color: #ddd;
  184. }
  185. }
  186. }
  187. .sidebar {
  188. position: fixed;
  189. z-index: 1;
  190. top: 0;
  191. right: 0;
  192. width: 300px;
  193. height: 100vh;
  194. background-color: $white;
  195. box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16),
  196. 0 2px 10px 0 rgba(0, 0, 0, 0.12);
  197. }
  198. .inner-wrapper {
  199. top: 60px;
  200. position: relative;
  201. overflow: auto;
  202. height: 100%;
  203. }
  204. .slide-transition {
  205. transition: transform 0.6s ease-in-out;
  206. transform: translateX(0);
  207. }
  208. .slide-enter,
  209. .slide-leave {
  210. transform: translateX(100%);
  211. }
  212. .sidebar-title {
  213. background-color: rgb(3, 169, 244);
  214. text-align: center;
  215. padding: 10px;
  216. color: $white;
  217. font-weight: 600;
  218. font-size: 20px;
  219. }
  220. .media {
  221. padding: 0 25px;
  222. }
  223. .media-content .content {
  224. min-height: 64px;
  225. display: flex;
  226. align-items: center;
  227. }
  228. .content p strong {
  229. word-break: break-word;
  230. }
  231. .content p small {
  232. word-break: break-word;
  233. }
  234. .add-to-queue {
  235. width: 100%;
  236. margin-top: 25px;
  237. height: 40px;
  238. border-radius: 0;
  239. background: rgb(3, 169, 244);
  240. color: $white !important;
  241. border: 0;
  242. &:active,
  243. &:focus {
  244. border: 0;
  245. }
  246. }
  247. .add-to-queue.add-to-queue-warning {
  248. background-color: red;
  249. }
  250. .add-to-queue.add-to-queue-disabled {
  251. background-color: gray;
  252. }
  253. .add-to-queue.add-to-queue-disabled:focus {
  254. background-color: gray;
  255. }
  256. .add-to-queue:focus {
  257. background: $primary-color;
  258. }
  259. .media-right {
  260. line-height: 64px;
  261. }
  262. .songTitle {
  263. word-wrap: break-word;
  264. overflow: hidden;
  265. text-overflow: ellipsis;
  266. display: -webkit-box;
  267. -webkit-box-orient: vertical;
  268. -webkit-line-clamp: 2;
  269. line-height: 20px;
  270. max-height: 40px;
  271. }
  272. </style>