2022-04-07 08:03:25 +05:30
|
|
|
<template>
|
2022-08-28 23:10:35 +05:30
|
|
|
<ModalComponent>
|
2022-09-09 02:26:24 +05:30
|
|
|
<span class="text-2xl w-max inline-block" v-t="'actions.select_playlist'" />
|
2022-08-28 23:10:35 +05:30
|
|
|
<select class="select w-full mt-3" v-model="selectedPlaylist">
|
|
|
|
<option v-for="playlist in playlists" :value="playlist.id" :key="playlist.id" v-text="playlist.name" />
|
|
|
|
</select>
|
|
|
|
<div class="flex justify-end mt-3">
|
|
|
|
<button
|
|
|
|
class="btn"
|
|
|
|
@click="handleClick(selectedPlaylist)"
|
|
|
|
ref="addButton"
|
|
|
|
v-t="'actions.add_to_playlist'"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</ModalComponent>
|
2022-04-07 08:03:25 +05:30
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-08-28 23:10:35 +05:30
|
|
|
import ModalComponent from "./ModalComponent.vue";
|
|
|
|
|
2022-04-07 08:03:25 +05:30
|
|
|
export default {
|
2022-08-28 23:10:35 +05:30
|
|
|
components: {
|
|
|
|
ModalComponent,
|
|
|
|
},
|
2022-04-07 08:03:25 +05:30
|
|
|
props: {
|
|
|
|
videoId: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
playlists: [],
|
|
|
|
selectedPlaylist: null,
|
2022-04-09 13:15:25 +05:30
|
|
|
processing: false,
|
2022-04-07 08:03:25 +05:30
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.fetchPlaylists();
|
2022-07-21 09:34:57 +05:30
|
|
|
this.selectedPlaylist = this.getPreferenceString("selectedPlaylist" + this.hashCode(this.authApiUrl()));
|
2022-04-09 13:15:25 +05:30
|
|
|
window.addEventListener("keydown", this.handleKeyDown);
|
|
|
|
window.blur();
|
|
|
|
},
|
|
|
|
unmounted() {
|
|
|
|
window.removeEventListener("keydown", this.handleKeyDown);
|
2022-04-07 08:03:25 +05:30
|
|
|
},
|
|
|
|
methods: {
|
2022-04-09 13:15:25 +05:30
|
|
|
handleKeyDown(event) {
|
2022-08-28 23:10:35 +05:30
|
|
|
if (event.code === "Enter") {
|
2022-04-09 13:15:25 +05:30
|
|
|
this.handleClick(this.selectedPlaylist);
|
2022-08-28 23:10:35 +05:30
|
|
|
event.preventDefault();
|
|
|
|
}
|
2022-04-09 13:15:25 +05:30
|
|
|
},
|
2022-04-07 08:03:25 +05:30
|
|
|
handleClick(playlistId) {
|
|
|
|
if (!playlistId) {
|
|
|
|
alert(this.$t("actions.please_select_playlist"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-09 13:15:25 +05:30
|
|
|
if (this.processing) return;
|
|
|
|
|
2022-04-07 08:03:25 +05:30
|
|
|
this.$refs.addButton.disabled = true;
|
2022-04-09 13:15:25 +05:30
|
|
|
this.processing = true;
|
2022-04-07 08:03:25 +05:30
|
|
|
|
2022-07-21 09:34:57 +05:30
|
|
|
this.fetchJson(this.authApiUrl() + "/user/playlists/add", null, {
|
2022-04-07 08:03:25 +05:30
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
playlistId: playlistId,
|
|
|
|
videoId: this.videoId,
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
}).then(json => {
|
2022-07-21 09:34:57 +05:30
|
|
|
this.setPreference("selectedPlaylist" + this.hashCode(this.authApiUrl()), playlistId);
|
2022-04-07 08:03:25 +05:30
|
|
|
this.$emit("close");
|
|
|
|
if (json.error) alert(json.error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
async fetchPlaylists() {
|
2022-07-21 09:34:57 +05:30
|
|
|
this.fetchJson(this.authApiUrl() + "/user/playlists", null, {
|
2022-04-07 08:03:25 +05:30
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
},
|
|
|
|
}).then(json => {
|
|
|
|
this.playlists = json;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|