123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <template>
- <modal title="Import Playlist">
- <template #body>
- <div class="vertical-padding">
- <p class="section-description">
- Import a playlist by using a link from YouTube
- </p>
- <div class="control is-grouped">
- <p class="control is-expanded">
- <input
- class="input"
- type="text"
- placeholder="YouTube Playlist URL"
- v-model="youtubeSearch.playlist.query"
- @keyup.enter="importPlaylist()"
- />
- </p>
- <p id="playlist-import-type" class="control select">
- <select
- v-model="
- youtubeSearch.playlist.isImportingOnlyMusic
- "
- >
- <option :value="false">Import all</option>
- <option :value="true">Import only music</option>
- </select>
- </p>
- <p class="control">
- <button
- class="button is-info"
- @click.prevent="importPlaylist()"
- >
- <i class="material-icons icon-with-button"
- >publish</i
- >Import
- </button>
- </p>
- </div>
- </div>
- </template>
- <template #footer>
- <p class="is-expanded checkbox-control">
- <label class="switch">
- <input
- type="checkbox"
- id="edit-imported-songs"
- v-model="localEditSongs"
- />
- <span class="slider round"></span>
- </label>
- <label for="edit-imported-songs">
- <p>Edit Songs</p>
- </label>
- </p>
- </template>
- </modal>
- </template>
- <script>
- import { mapActions, mapState, mapGetters } from "vuex";
- import Toast from "toasters";
- import SearchYoutube from "@/mixins/SearchYoutube.vue";
- export default {
- mixins: [SearchYoutube],
- computed: {
- localEditSongs: {
- get() {
- return this.$store.state.modals.importPlaylist
- .editImportedSongs;
- },
- set(editImportedSongs) {
- this.$store.commit(
- "modals/importPlaylist/updateEditImportedSongs",
- editImportedSongs
- );
- }
- },
- ...mapState({
- loggedIn: state => state.user.auth.loggedIn,
- station: state => state.station.station
- }),
- ...mapGetters({
- socket: "websockets/getSocket"
- })
- },
- methods: {
- importPlaylist() {
- let isImportingPlaylist = true;
- // import query is blank
- if (!this.youtubeSearch.playlist.query)
- return new Toast("Please enter a YouTube playlist URL.");
- const regex = /[\\?&]list=([^&#]*)/;
- const splitQuery = regex.exec(this.youtubeSearch.playlist.query);
- if (!splitQuery) {
- return new Toast({
- content: "Please enter a valid YouTube playlist URL.",
- timeout: 4000
- });
- }
- // don't give starting import message instantly in case of instant error
- setTimeout(() => {
- if (isImportingPlaylist) {
- new Toast(
- "Starting to import your playlist. This can take some time to do."
- );
- }
- }, 750);
- return this.socket.dispatch(
- "songs.requestSet",
- this.youtubeSearch.playlist.query,
- this.youtubeSearch.playlist.isImportingOnlyMusic,
- true,
- res => {
- isImportingPlaylist = false;
- if (
- this.localEditSongs &&
- res.status === "success" &&
- res.songs &&
- res.songs.length > 0
- ) {
- this.editSongs(
- res.songs.map(song => ({
- ...song,
- songId: song._id
- }))
- );
- this.openModal("editSongs");
- }
- this.closeModal("importPlaylist");
- return new Toast({
- content: res.message,
- timeout: 20000
- });
- }
- );
- },
- ...mapActions("modals/editSongs", ["editSongs"]),
- ...mapActions("modalVisibility", ["openModal", "closeModal"])
- }
- };
- </script>
|