123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- <template>
- <div id="my-playlists">
- <draggable
- class="menu-list scrollable-list"
- v-if="playlists.length > 0"
- v-model="playlists"
- v-bind="dragOptions"
- @start="drag = true"
- @end="drag = false"
- @change="savePlaylistOrder"
- >
- <transition-group
- type="transition"
- :name="!drag ? 'draggable-list-transition' : null"
- >
- <playlist-item
- :playlist="playlist"
- v-for="playlist in playlists"
- :key="`key-${playlist._id}`"
- class="item-draggable"
- >
- <div class="icons-group" slot="actions">
- <i
- v-if="isExcluded(playlist._id)"
- class="material-icons stop-icon"
- content="This playlist is blacklisted in this station"
- v-tippy
- >play_disabled</i
- >
- <i
- v-if="
- station.type === 'community' &&
- (isOwnerOrAdmin() || station.partyMode) &&
- !isSelected(playlist._id) &&
- !isExcluded(playlist._id)
- "
- @click="selectPlaylist(playlist)"
- class="material-icons play-icon"
- :content="
- station.partyMode
- ? 'Request songs from this playlist'
- : 'Play songs from this playlist'
- "
- v-tippy
- >play_arrow</i
- >
- <confirm
- v-if="
- station.type === 'community' &&
- (isOwnerOrAdmin() || station.partyMode) &&
- isSelected(playlist._id)
- "
- @confirm="deselectPlaylist(playlist._id)"
- >
- <i
- class="material-icons stop-icon"
- :content="
- station.partyMode
- ? 'Stop requesting songs from this playlist'
- : 'Stop playing songs from this playlist'
- "
- v-tippy
- >stop</i
- >
- </confirm>
- <confirm
- v-if="isOwnerOrAdmin() && !isExcluded(playlist._id)"
- @confirm="blacklistPlaylist(playlist._id)"
- >
- <i
- class="material-icons stop-icon"
- content="Blacklist Playlist"
- v-tippy
- >block</i
- >
- </confirm>
- <i
- @click="edit(playlist._id)"
- class="material-icons edit-icon"
- content="Edit Playlist"
- v-tippy
- >edit</i
- >
- </div>
- </playlist-item>
- </transition-group>
- </draggable>
- <p v-else class="nothing-here-text scrollable-list">
- No Playlists found
- </p>
- <a
- class="button create-playlist tab-actionable-button"
- href="#"
- @click="openModal('createPlaylist')"
- >
- <i class="material-icons icon-with-button">create</i>
- <span class="optional-desktop-only-text"> Create Playlist </span>
- </a>
- </div>
- </template>
- <script>
- import { mapState, mapActions, mapGetters } from "vuex";
- import Toast from "toasters";
- import PlaylistItem from "@/components/PlaylistItem.vue";
- import SortablePlaylists from "@/mixins/SortablePlaylists.vue";
- import Confirm from "@/components/Confirm.vue";
- export default {
- components: { PlaylistItem, Confirm },
- mixins: [SortablePlaylists],
- computed: {
- currentPlaylists() {
- if (this.station.type === "community" && this.station.partyMode)
- return this.partyPlaylists;
- return this.includedPlaylists;
- },
- ...mapState({
- role: state => state.user.auth.role,
- userId: state => state.user.auth.userId,
- loggedIn: state => state.user.auth.loggedIn
- }),
- ...mapState("station", {
- partyPlaylists: state => state.partyPlaylists,
- includedPlaylists: state => state.includedPlaylists,
- excludedPlaylists: state => state.excludedPlaylists,
- songsList: state => state.songsList
- }),
- ...mapGetters({
- socket: "websockets/getSocket"
- })
- },
- mounted() {
- /** Get playlists for user */
- this.socket.dispatch("playlists.indexMyPlaylists", true, res => {
- if (res.status === "success") this.setPlaylists(res.data.playlists);
- this.orderOfPlaylists = this.calculatePlaylistOrder(); // order in regards to the database
- });
- this.socket.on("event:station.includedPlaylist", res => {
- const { playlist } = res.data;
- this.includedPlaylists.push(playlist);
- });
- this.socket.on("event:station.excludedPlaylist", res => {
- const { playlist } = res.data;
- this.excludedPlaylists.push(playlist);
- });
- this.socket.on("event:station.removedIncludedPlaylist", res => {
- const { playlistId } = res.data;
- const playlistIndex = this.includedPlaylists
- .map(playlist => playlist._id)
- .indexOf(playlistId);
- if (playlistIndex >= 0)
- this.includedPlaylists.splice(playlistIndex, 1);
- });
- this.socket.on("event:station.removedExcludedPlaylist", res => {
- const { playlistId } = res.data;
- const playlistIndex = this.excludedPlaylists
- .map(playlist => playlist._id)
- .indexOf(playlistId);
- if (playlistIndex >= 0)
- this.excludedPlaylists.splice(playlistIndex, 1);
- });
- },
- methods: {
- isOwner() {
- return this.loggedIn && this.userId === this.station.owner;
- },
- isAdmin() {
- return this.loggedIn && this.role === "admin";
- },
- isOwnerOrAdmin() {
- return this.isOwner() || this.isAdmin();
- },
- edit(id) {
- this.editPlaylist(id);
- this.openModal("editPlaylist");
- },
- selectPlaylist(playlist) {
- if (this.station.type === "community" && this.station.partyMode) {
- if (!this.isSelected(playlist.id)) {
- this.partyPlaylists.push(playlist);
- this.addPartyPlaylistSongToQueue();
- new Toast(
- "Successfully selected playlist to auto request songs."
- );
- } else {
- new Toast("Error: Playlist already selected.");
- }
- } else {
- this.socket.dispatch(
- "stations.includePlaylist",
- this.station._id,
- playlist._id,
- res => {
- new Toast(res.message);
- }
- );
- }
- },
- deselectPlaylist(id) {
- return new Promise(resolve => {
- if (
- this.station.type === "community" &&
- this.station.partyMode
- ) {
- let selected = false;
- this.currentPlaylists.forEach((playlist, index) => {
- if (playlist._id === id) {
- selected = true;
- this.partyPlaylists.splice(index, 1);
- }
- });
- if (selected) {
- new Toast("Successfully deselected playlist.");
- resolve();
- } else {
- new Toast("Playlist not selected.");
- resolve();
- }
- } else {
- this.socket.dispatch(
- "stations.removeIncludedPlaylist",
- this.station._id,
- id,
- res => {
- new Toast(res.message);
- resolve();
- }
- );
- }
- });
- },
- isSelected(id) {
- let selected = false;
- this.currentPlaylists.forEach(playlist => {
- if (playlist._id === id) selected = true;
- });
- return selected;
- },
- isExcluded(id) {
- let selected = false;
- this.excludedPlaylists.forEach(playlist => {
- if (playlist._id === id) selected = true;
- });
- return selected;
- },
- async blacklistPlaylist(id) {
- if (this.isSelected(id)) await this.deselectPlaylist(id);
- this.socket.dispatch(
- "stations.excludePlaylist",
- this.station._id,
- id,
- res => {
- new Toast(res.message);
- }
- );
- },
- addPartyPlaylistSongToQueue() {
- let isInQueue = false;
- if (
- this.station.type === "community" &&
- this.station.partyMode === true
- ) {
- this.songsList.forEach(queueSong => {
- if (queueSong.requestedBy === this.userId) isInQueue = true;
- });
- if (!isInQueue && this.partyPlaylists) {
- const selectedPlaylist = this.partyPlaylists[
- Math.floor(Math.random() * this.partyPlaylists.length)
- ];
- if (
- selectedPlaylist._id &&
- selectedPlaylist.songs.length > 0
- ) {
- const selectedSong =
- selectedPlaylist.songs[
- Math.floor(
- Math.random() *
- selectedPlaylist.songs.length
- )
- ];
- if (selectedSong.youtubeId) {
- this.socket.dispatch(
- "stations.addToQueue",
- this.station._id,
- selectedSong.youtubeId,
- data => {
- if (data.status !== "success")
- new Toast("Error auto queueing song");
- }
- );
- }
- }
- }
- }
- },
- ...mapActions("station", ["updatePartyPlaylists"]),
- ...mapActions("modalVisibility", ["openModal"]),
- ...mapActions("user/playlists", ["editPlaylist", "setPlaylists"])
- }
- };
- </script>
- <style lang="scss" scoped>
- #my-playlists {
- background-color: var(--white);
- margin-bottom: 20px;
- border-radius: 0 0 5px 5px;
- max-height: 100%;
- }
- .night-mode {
- #my-playlists {
- background-color: var(--dark-grey-3) !important;
- border: 0 !important;
- }
- .draggable-list-ghost {
- filter: brightness(95%);
- }
- }
- .nothing-here-text {
- margin-bottom: 10px;
- }
- .icons-group {
- display: flex;
- align-items: center;
- .edit-icon {
- color: var(--primary-color);
- }
- }
- .menu-list .playlist-item:not(:last-of-type) {
- margin-bottom: 10px;
- }
- .create-playlist {
- width: 100%;
- height: 40px;
- border-radius: 5px;
- border: 0;
- &:active,
- &:focus {
- border: 0;
- }
- }
- .draggable-list-transition-move {
- transition: transform 0.5s;
- }
- .draggable-list-ghost {
- opacity: 0.5;
- filter: brightness(95%);
- }
- </style>
|