Playlists.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <div class="station-playlists">
  3. <div class="tabs-container">
  4. <div class="tab-selection">
  5. <button
  6. class="button is-default"
  7. :class="{ selected: tab === 'current' }"
  8. @click="showTab('current')"
  9. >
  10. Current
  11. </button>
  12. <button
  13. class="button is-default"
  14. :class="{ selected: tab === 'search' }"
  15. @click="showTab('search')"
  16. >
  17. Search
  18. </button>
  19. <button
  20. v-if="station.type === 'community'"
  21. class="button is-default"
  22. :class="{ selected: tab === 'my-playlists' }"
  23. @click="showTab('my-playlists')"
  24. >
  25. My Playlists
  26. </button>
  27. </div>
  28. <div class="tab" v-show="tab === 'current'">
  29. <div v-if="includedPlaylists.length > 0">
  30. <playlist-item
  31. :playlist="playlist"
  32. v-for="(playlist, index) in includedPlaylists"
  33. :key="'key-' + index"
  34. >
  35. <div class="icons-group" slot="actions">
  36. <confirm
  37. v-if="isOwnerOrAdmin()"
  38. @confirm="deselectPlaylist(playlist._id)"
  39. >
  40. <i
  41. class="material-icons stop-icon"
  42. content="Stop playing songs from this playlist"
  43. v-tippy
  44. >
  45. stop
  46. </i>
  47. </confirm>
  48. <i
  49. v-if="playlist.createdBy === myUserId"
  50. @click="showPlaylist(playlist._id)"
  51. class="material-icons edit-icon"
  52. content="Edit Playlist"
  53. v-tippy
  54. >edit</i
  55. >
  56. <i
  57. v-if="
  58. playlist.createdBy !== myUserId &&
  59. (playlist.privacy === 'public' ||
  60. isAdmin())
  61. "
  62. @click="showPlaylist(playlist._id)"
  63. class="material-icons edit-icon"
  64. content="View Playlist"
  65. v-tippy
  66. >visibility</i
  67. >
  68. </div>
  69. </playlist-item>
  70. </div>
  71. <p v-else class="nothing-here-text scrollable-list">
  72. No playlists currently selected.
  73. </p>
  74. </div>
  75. <div class="tab" v-show="tab === 'search'">
  76. <label class="label"> Search for a public playlist </label>
  77. <div class="control is-grouped input-with-button">
  78. <p class="control is-expanded">
  79. <input
  80. class="input"
  81. type="text"
  82. placeholder="Enter your playlist query here..."
  83. />
  84. </p>
  85. <p class="control">
  86. <a class="button is-info" href="#"
  87. ><i class="material-icons icon-with-button"
  88. >search</i
  89. >Search</a
  90. >
  91. </p>
  92. </div>
  93. Searching genre and public user playlists has yet to be added.
  94. </div>
  95. <div
  96. v-if="station.type === 'community'"
  97. class="tab"
  98. v-show="tab === 'my-playlists'"
  99. >
  100. <button
  101. class="button is-primary"
  102. id="create-new-playlist-button"
  103. @click="
  104. openModal({
  105. sector: 'station',
  106. modal: 'createPlaylist'
  107. })
  108. "
  109. >
  110. Create new playlist
  111. </button>
  112. <draggable
  113. class="menu-list scrollable-list"
  114. v-if="playlists.length > 0"
  115. v-model="playlists"
  116. v-bind="dragOptions"
  117. @start="drag = true"
  118. @end="drag = false"
  119. @change="savePlaylistOrder"
  120. >
  121. <transition-group
  122. type="transition"
  123. :name="!drag ? 'draggable-list-transition' : null"
  124. >
  125. <playlist-item
  126. class="item-draggable"
  127. v-for="playlist in playlists"
  128. :key="playlist._id"
  129. :playlist="playlist"
  130. >
  131. <div slot="actions">
  132. <i
  133. v-if="
  134. station.type === 'community' &&
  135. (isOwnerOrAdmin() ||
  136. station.partyMode) &&
  137. !isSelected(playlist._id)
  138. "
  139. @click="selectPlaylist(playlist._id)"
  140. class="material-icons play-icon"
  141. :content="
  142. station.partyMode
  143. ? 'Request songs from this playlist'
  144. : 'Play songs from this playlist'
  145. "
  146. v-tippy
  147. >play_arrow</i
  148. >
  149. <confirm
  150. v-if="
  151. station.type === 'community' &&
  152. (isOwnerOrAdmin() ||
  153. station.partyMode) &&
  154. isSelected(playlist._id)
  155. "
  156. @confirm="deselectPlaylist(playlist._id)"
  157. >
  158. <i
  159. class="material-icons stop-icon"
  160. :content="
  161. station.partyMode
  162. ? 'Stop requesting songs from this playlist'
  163. : 'Stop playing songs from this playlist'
  164. "
  165. v-tippy
  166. >stop</i
  167. >
  168. </confirm>
  169. <i
  170. @click="showPlaylist(playlist._id)"
  171. class="material-icons edit-icon"
  172. content="Edit Playlist"
  173. v-tippy
  174. >edit</i
  175. >
  176. </div>
  177. </playlist-item>
  178. </transition-group>
  179. </draggable>
  180. <p v-else class="nothing-here-text scrollable-list">
  181. You don't have any playlists!
  182. </p>
  183. </div>
  184. </div>
  185. </div>
  186. </template>
  187. <script>
  188. import { mapActions, mapState, mapGetters } from "vuex";
  189. import Toast from "toasters";
  190. import draggable from "vuedraggable";
  191. import PlaylistItem from "@/components/PlaylistItem.vue";
  192. import Confirm from "@/components/Confirm.vue";
  193. import SortablePlaylists from "@/mixins/SortablePlaylists.vue";
  194. export default {
  195. components: {
  196. draggable,
  197. PlaylistItem,
  198. Confirm
  199. // CreatePlaylist: () => import("@/components/modals/CreatePlaylist.vue")
  200. },
  201. mixins: [SortablePlaylists],
  202. data() {
  203. return {
  204. tab: "current"
  205. };
  206. },
  207. computed: {
  208. playlists: {
  209. get() {
  210. return this.$store.state.user.playlists.playlists;
  211. },
  212. set(playlists) {
  213. this.$store.commit("user/playlists/setPlaylists", playlists);
  214. }
  215. },
  216. ...mapState({
  217. loggedIn: state => state.user.auth.loggedIn,
  218. role: state => state.user.auth.role,
  219. myUserId: state => state.user.auth.userId,
  220. userId: state => state.user.auth.userId
  221. }),
  222. ...mapState("modals/manageStation", {
  223. station: state => state.station,
  224. originalStation: state => state.originalStation,
  225. includedPlaylists: state => state.includedPlaylists,
  226. excludedPlaylists: state => state.excludedPlaylists
  227. }),
  228. ...mapGetters({
  229. socket: "websockets/getSocket"
  230. })
  231. },
  232. mounted() {
  233. this.socket.dispatch("playlists.indexMyPlaylists", true, res => {
  234. if (res.status === "success") this.playlists = res.data.playlists;
  235. this.orderOfPlaylists = this.calculatePlaylistOrder(); // order in regards to the database
  236. });
  237. this.socket.on("event:playlist.create", res => {
  238. this.playlists.push(res.data.playlist);
  239. });
  240. this.socket.on("event:playlist.delete", res => {
  241. this.playlists.forEach((playlist, index) => {
  242. if (playlist._id === res.data.playlistId) {
  243. this.playlists.splice(index, 1);
  244. }
  245. });
  246. });
  247. this.socket.on("event:playlist.addSong", res => {
  248. this.playlists.forEach((playlist, index) => {
  249. if (playlist._id === res.data.playlistId) {
  250. this.playlists[index].songs.push(res.data.song);
  251. }
  252. });
  253. });
  254. this.socket.on("event:playlist.removeSong", res => {
  255. this.playlists.forEach((playlist, index) => {
  256. if (playlist._id === res.data.playlistId) {
  257. this.playlists[index].songs.forEach((song, index2) => {
  258. if (song.youtubeId === res.data.youtubeId) {
  259. this.playlists[index].songs.splice(index2, 1);
  260. }
  261. });
  262. }
  263. });
  264. });
  265. this.socket.on("event:playlist.updateDisplayName", res => {
  266. this.playlists.forEach((playlist, index) => {
  267. if (playlist._id === res.data.playlistId) {
  268. this.playlists[index].displayName = res.data.displayName;
  269. }
  270. });
  271. });
  272. this.socket.on("event:playlist.updatePrivacy", res => {
  273. this.playlists.forEach((playlist, index) => {
  274. if (playlist._id === res.data.playlist._id) {
  275. this.playlists[index].privacy = res.data.playlist.privacy;
  276. }
  277. });
  278. });
  279. this.socket.on(
  280. "event:user.orderOfPlaylists.changed",
  281. orderOfPlaylists => {
  282. const sortedPlaylists = [];
  283. this.playlists.forEach(playlist => {
  284. sortedPlaylists[
  285. orderOfPlaylists.indexOf(playlist._id)
  286. ] = playlist;
  287. });
  288. this.playlists = sortedPlaylists;
  289. this.orderOfPlaylists = this.calculatePlaylistOrder();
  290. }
  291. );
  292. this.socket.dispatch(
  293. `stations.getStationIncludedPlaylistsById`,
  294. this.station._id,
  295. res => {
  296. if (res.status === "success") {
  297. this.station.includedPlaylists = res.data.playlists;
  298. this.originalStation.includedPlaylists = res.data.playlists;
  299. }
  300. }
  301. );
  302. this.socket.dispatch(
  303. `stations.getStationExcludedPlaylistsById`,
  304. this.station._id,
  305. res => {
  306. if (res.status === "success") {
  307. this.station.excludedPlaylists = res.data.playlists;
  308. this.originalStation.excludedPlaylists = res.data.playlists;
  309. }
  310. }
  311. );
  312. },
  313. methods: {
  314. showTab(tab) {
  315. this.tab = tab;
  316. },
  317. isOwner() {
  318. return this.loggedIn && this.userId === this.station.owner;
  319. },
  320. isAdmin() {
  321. return this.loggedIn && this.role === "admin";
  322. },
  323. isOwnerOrAdmin() {
  324. return this.isOwner() || this.isAdmin();
  325. },
  326. showPlaylist(playlistId) {
  327. this.editPlaylist(playlistId);
  328. this.openModal({ sector: "station", modal: "editPlaylist" });
  329. },
  330. selectPlaylist(id) {
  331. if (this.station.type === "community" && this.station.partyMode) {
  332. new Toast(
  333. "Error: Party mode playlist selection not added yet."
  334. );
  335. } else {
  336. this.socket.dispatch(
  337. "stations.includePlaylist",
  338. this.station._id,
  339. id,
  340. res => {
  341. new Toast(res.message);
  342. }
  343. );
  344. }
  345. },
  346. deselectPlaylist(id) {
  347. if (this.station.type === "community" && this.station.partyMode) {
  348. new Toast(
  349. "Error: Party mode playlist selection not added yet."
  350. );
  351. } else {
  352. this.socket.dispatch(
  353. "stations.removeIncludedPlaylist",
  354. this.station._id,
  355. id,
  356. res => {
  357. new Toast(res.message);
  358. }
  359. );
  360. }
  361. },
  362. isSelected(id) {
  363. if (this.station.type === "community" && this.station.partyMode) {
  364. // Party mode playlist selection not added yet.
  365. return false;
  366. }
  367. // TODO Also change this once it changes for a station
  368. let selected = false;
  369. this.includedPlaylists.forEach(playlist => {
  370. if (playlist._id === id) selected = true;
  371. });
  372. return selected;
  373. },
  374. ...mapActions("station", ["updatePrivatePlaylistQueueSelected"]),
  375. ...mapActions("modalVisibility", ["openModal"]),
  376. ...mapActions("user/playlists", ["editPlaylist", "setPlaylists"])
  377. }
  378. };
  379. </script>
  380. <style lang="scss" scoped>
  381. .station-playlists {
  382. .tabs-container {
  383. .tab-selection {
  384. display: flex;
  385. .button {
  386. border-radius: 0;
  387. border: 0;
  388. text-transform: uppercase;
  389. font-size: 14px;
  390. color: var(--dark-grey-3);
  391. background-color: var(--light-grey-2);
  392. flex-grow: 1;
  393. height: 32px;
  394. &:not(:first-of-type) {
  395. margin-left: 5px;
  396. }
  397. }
  398. .selected {
  399. background-color: var(--dark-grey-3) !important;
  400. color: var(--white) !important;
  401. }
  402. }
  403. .tab {
  404. padding: 15px 0;
  405. border-radius: 0;
  406. .playlist-item:not(:last-of-type),
  407. .item.item-draggable:not(:last-of-type) {
  408. margin-bottom: 10px;
  409. }
  410. }
  411. }
  412. }
  413. .draggable-list-transition-move {
  414. transition: transform 0.5s;
  415. }
  416. .draggable-list-ghost {
  417. opacity: 0.5;
  418. filter: brightness(95%);
  419. }
  420. </style>