123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- <template>
- <div id="my-playlists">
- <ul class="menu-list scrollable-list" v-if="playlists.length > 0">
- <li v-for="(playlist, index) in playlists" :key="index">
- <playlist-item :playlist="playlist">
- <div class="icons-group" slot="actions">
- <button
- v-if="
- station.type === 'community' &&
- isNotSelected(playlist._id) &&
- !station.partyMode
- "
- class="button is-primary"
- @click="selectPlaylist(playlist._id)"
- >
- <i class="material-icons">play_arrow</i>
- </button>
- <button
- v-if="
- station.type === 'community' &&
- !isNotSelected(playlist._id) &&
- !station.partyMode
- "
- class="button is-danger"
- @click="deselectPlaylist()"
- >
- <i class="material-icons">stop</i>
- </button>
- <button
- class="button is-primary"
- @click="edit(playlist._id)"
- >
- <i class="material-icons">edit</i>
- </button>
- </div>
- </playlist-item>
- </li>
- </ul>
- <p v-else class="nothing-here-text scrollable-list">
- No Playlists found
- </p>
- <a
- class="button create-playlist tab-actionable-button"
- href="#"
- @click="openModal({ sector: 'station', modal: 'createPlaylist' })"
- >Create Playlist</a
- >
- </div>
- </template>
- <script>
- import { mapState, mapActions } from "vuex";
- import Toast from "toasters";
- import PlaylistItem from "../../../../components/ui/PlaylistItem.vue";
- import io from "../../../../io";
- export default {
- components: { PlaylistItem },
- data() {
- return {
- playlists: []
- };
- },
- computed: {
- ...mapState("modals", {
- modals: state => state.modals.station
- }),
- ...mapState({
- station: state => state.station.station
- })
- },
- mounted() {
- io.getSocket(socket => {
- this.socket = socket;
- /** Get playlists for user */
- this.socket.emit("playlists.indexForUser", true, res => {
- if (res.status === "success") this.playlists = res.data;
- });
- this.socket.on("event:playlist.create", playlist => {
- this.playlists.push(playlist);
- });
- this.socket.on("event:playlist.delete", playlistId => {
- this.playlists.forEach((playlist, index) => {
- if (playlist._id === playlistId) {
- this.playlists.splice(index, 1);
- }
- });
- });
- this.socket.on("event:playlist.addSong", data => {
- this.playlists.forEach((playlist, index) => {
- if (playlist._id === data.playlistId) {
- this.playlists[index].songs.push(data.song);
- }
- });
- });
- this.socket.on("event:playlist.removeSong", data => {
- this.playlists.forEach((playlist, index) => {
- if (playlist._id === data.playlistId) {
- this.playlists[index].songs.forEach((song, index2) => {
- if (song.songId === data.songId) {
- this.playlists[index].songs.splice(index2, 1);
- }
- });
- }
- });
- });
- this.socket.on("event:playlist.updateDisplayName", data => {
- this.playlists.forEach((playlist, index) => {
- if (playlist._id === data.playlistId) {
- this.playlists[index].displayName = data.displayName;
- }
- });
- });
- this.socket.on("event:playlist.updatePrivacy", data => {
- this.playlists.forEach((playlist, index) => {
- if (playlist._id === data.playlistId) {
- this.playlists[index].privacy = data.privacy;
- }
- });
- });
- });
- },
- methods: {
- edit(id) {
- this.editPlaylist(id);
- this.openModal({ sector: "station", modal: "editPlaylist" });
- },
- selectPlaylist(id) {
- this.socket.emit(
- "stations.selectPrivatePlaylist",
- this.station._id,
- id,
- res => {
- if (res.status === "failure")
- return new Toast({
- content: res.message,
- timeout: 8000
- });
- return new Toast({ content: res.message, timeout: 4000 });
- }
- );
- },
- deselectPlaylist() {
- this.socket.emit(
- "stations.deselectPrivatePlaylist",
- this.station._id,
- res => {
- if (res.status === "failure")
- return new Toast({
- content: res.message,
- timeout: 8000
- });
- return new Toast({ content: res.message, timeout: 4000 });
- }
- );
- },
- isNotSelected(id) {
- // TODO Also change this once it changes for a station
- if (this.station && this.station.privatePlaylist === id)
- return false;
- return true;
- },
- ...mapActions("modals", ["openModal"]),
- ...mapActions("user/playlists", ["editPlaylist"])
- }
- };
- </script>
- <style lang="scss" scoped>
- @import "../../../../styles/global.scss";
- #my-playlists {
- background-color: #fff;
- margin-bottom: 20px;
- border-radius: 0 0 5px 5px;
- max-height: 100%;
- .nothing-here-text {
- margin-bottom: 10px;
- }
- .icons-group {
- display: flex;
- align-items: center;
- button:not(:first-of-type) {
- margin-left: 5px;
- }
- }
- }
- .night-mode {
- #my-playlists {
- background-color: $night-mode-bg-secondary !important;
- border: 0 !important;
- }
- }
- .menu-list li {
- align-items: center;
- &:not(:last-of-type) {
- margin-bottom: 10px;
- }
- }
- .create-playlist {
- width: 100%;
- height: 40px;
- border-radius: 5px;
- background-color: rgba(3, 169, 244, 1);
- color: $white !important;
- border: 0;
- &:active,
- &:focus {
- border: 0;
- }
- &:focus {
- background-color: $primary-color;
- }
- }
- </style>
|