2022-04-07 08:03:25 +05:30
|
|
|
<template>
|
2023-08-22 12:50:40 +05:30
|
|
|
<ModalComponent @close="$emit('close')">
|
2023-08-13 23:01:57 +05:30
|
|
|
<span v-t="'actions.select_playlist'" class="inline-block w-max text-2xl" />
|
|
|
|
<select v-model="selectedPlaylist" class="select mt-3 w-full">
|
2023-07-27 17:16:05 +05:30
|
|
|
<option v-for="playlist in playlists" :key="playlist.id" :value="playlist.id" v-text="playlist.name" />
|
2022-08-28 23:10:35 +05:30
|
|
|
</select>
|
2023-08-13 23:01:57 +05:30
|
|
|
<div class="mt-3 w-full flex justify-between">
|
2023-07-27 17:16:05 +05:30
|
|
|
<button ref="addButton" v-t="'actions.create_playlist'" class="btn" @click="onCreatePlaylist" />
|
2022-08-28 23:10:35 +05:30
|
|
|
<button
|
|
|
|
ref="addButton"
|
|
|
|
v-t="'actions.add_to_playlist'"
|
2023-07-27 17:16:05 +05:30
|
|
|
class="btn"
|
|
|
|
@click="handleClick(selectedPlaylist)"
|
2022-08-28 23:10:35 +05:30
|
|
|
/>
|
|
|
|
</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: {
|
2023-06-15 21:02:32 +05:30
|
|
|
videoInfo: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
2022-04-07 08:03:25 +05:30
|
|
|
videoId: {
|
2023-06-16 02:11:26 +05:30
|
|
|
type: String,
|
2022-04-07 08:03:25 +05:30
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
2023-07-27 17:16:05 +05:30
|
|
|
emits: ["close"],
|
2022-04-07 08:03:25 +05:30
|
|
|
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
|
|
|
|
2023-06-15 21:02:32 +05:30
|
|
|
this.addVideosToPlaylist(playlistId, [this.videoId], [this.videoInfo]).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() {
|
2023-06-15 21:02:32 +05:30
|
|
|
this.getPlaylists().then(json => {
|
2022-04-07 08:03:25 +05:30
|
|
|
this.playlists = json;
|
|
|
|
});
|
|
|
|
},
|
2023-07-05 16:34:50 +05:30
|
|
|
onCreatePlaylist() {
|
|
|
|
const name = prompt(this.$t("actions.create_playlist"));
|
|
|
|
if (!name) return;
|
|
|
|
this.createPlaylist(name).then(json => {
|
|
|
|
if (json.error) alert(json.error);
|
|
|
|
else this.fetchPlaylists();
|
|
|
|
});
|
|
|
|
},
|
2022-04-07 08:03:25 +05:30
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|