Merge pull request #119 from Swiftzerr/main

Added a confirm button so you dont accidently delete a playlist
This commit is contained in:
cryptofyre 2022-01-11 21:33:22 -06:00 committed by GitHub
commit a373cb196b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -66,10 +66,14 @@
@click="app.mk.shuffleMode = 1;play()"> @click="app.mk.shuffleMode = 1;play()">
Shuffle Shuffle
</button> </button>
<button class="wr-btn" style="min-width: 120px;" v-if="inLibrary!=null" <button class="wr-btn" style="min-width: 120px;" v-if="inLibrary!=null && confirm!=true"
@click="(!inLibrary) ? addToLibrary(data.attributes.playParams.id.toString()) : removeFromLibrary(data.attributes.playParams.id.toString())"> @click="confirmButton()">
{{ (!inLibrary) ? "Add to Library" : "Remove from Library" }} {{ (!inLibrary) ? "Add to Library" : "Remove from Library" }}
</button> </button>
<button class="wr-btn" style="min-width: 120px;" v-if="confirm==true"
@click="(!inLibrary) ? addToLibrary(data.attributes.playParams.id.toString()) : removeFromLibrary(data.attributes.playParams.id.toString()) ">
Confirm?
</button>
</div> </div>
</div> </div>
</div> </div>
@ -109,16 +113,19 @@
</div> </div>
</script> </script>
<script> <script>
Vue.component('cider-playlist', { Vue.component('cider-playlist', {
template: "#cider-playlist", template: "#cider-playlist",
props: ["data"], props: ["data"],
data: function () { data: function () {
return { return {
editorialNotesExpanded: false, editorialNotesExpanded: false,
drag: false, drag: false,
nameEditing: false, nameEditing: false,
inLibrary: null, inLibrary: null,
confirm: false,
app: this.$root, app: this.$root,
itemBadges: [], itemBadges: [],
badgesRequested: false badgesRequested: false
@ -161,6 +168,13 @@
} }
}) })
}, },
confirmButton() {
// Return button to normal state after 3 seconds
this.confirm = true
setTimeout(() => this.confirm = false, 3000);
},
getDescription(data) { getDescription(data) {
console.log(data.attributes) console.log(data.attributes)
if (data.attributes.editorialNotes) { if (data.attributes.editorialNotes) {
@ -212,6 +226,7 @@
addToLibrary(id) { addToLibrary(id) {
app.mk.addToLibrary(id) app.mk.addToLibrary(id)
this.inLibrary = true this.inLibrary = true
this.confirm = false
}, },
async removeFromLibrary(id) { async removeFromLibrary(id) {
var params = { "fields[somgs]": "inLibrary", "fields[albums]": "inLibrary", "relate": "library" } var params = { "fields[somgs]": "inLibrary", "fields[albums]": "inLibrary", "relate": "library" }
@ -224,6 +239,7 @@
var truekind = (!kind.endsWith("s")) ? (kind + "s") : kind; var truekind = (!kind.endsWith("s")) ? (kind + "s") : kind;
app.mk.api.library.remove({ [truekind]: id }) app.mk.api.library.remove({ [truekind]: id })
this.inLibrary = false this.inLibrary = false
this.confirm = false
}, },
editPlaylistName() { editPlaylistName() {
if (this.data.attributes.canEdit && this.data.type == "library-playlists") { if (this.data.attributes.canEdit && this.data.type == "library-playlists") {
@ -327,7 +343,7 @@
var kind = this.data.attributes.playParams.kind ?? this.data.type ?? ''; var kind = this.data.attributes.playParams.kind ?? this.data.type ?? '';
//console.log("1") //console.log("1")
var truekind = (!kind.endsWith("s")) ? (kind + "s") : kind; var truekind = (!kind.endsWith("s")) ? (kind + "s") : kind;
let query = (this.data ?? app.showingPlaylist).relationships.tracks.data.map(item => new MusicKit.MediaItem(item)); let query = (this.data ?? app.showingPlaylist).relationships.tracks.data.map(item => new MusicKit.MediaItem(item));
app.mk.stop().then(function () { app.mk.stop().then(function () {
app.mk.setQueue({[truekind]: [id]}).then(function () { app.mk.setQueue({[truekind]: [id]}).then(function () {