123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <template>
- <modal title="Add Song To Queue">
- <div slot="body">
- <aside
- class="menu"
- v-if="$parent.$parent.loggedIn && $parent.type === 'community'"
- >
- <ul class="menu-list">
- <li v-for="(playlist, index) in playlists" :key="index">
- <a
- href="#"
- target="_blank"
- v-on:click="$parent.editPlaylist(playlist._id)"
- >{{ playlist.displayName }}</a
- >
- <div class="controls">
- <a
- href="#"
- v-on:click="selectPlaylist(playlist._id)"
- v-if="!isPlaylistSelected(playlist._id)"
- >
- <i class="material-icons">panorama_fish_eye</i>
- </a>
- <a
- href="#"
- v-on:click="unSelectPlaylist()"
- v-if="isPlaylistSelected(playlist._id)"
- >
- <i class="material-icons">lens</i>
- </a>
- </div>
- </li>
- </ul>
- <br />
- </aside>
- <div class="control is-grouped">
- <p class="control is-expanded">
- <input
- class="input"
- type="text"
- placeholder="YouTube Query"
- v-model="querySearch"
- autofocus
- @keyup.enter="submitQuery()"
- />
- </p>
- <p class="control">
- <a
- class="button is-info"
- v-on:click="submitQuery()"
- href="#"
- >Search</a
- >
- </p>
- </div>
- <div class="control is-grouped" v-if="$parent.type === 'official'">
- <p class="control is-expanded">
- <input
- class="input"
- type="text"
- placeholder="YouTube Playlist URL"
- v-model="importQuery"
- @keyup.enter="importPlaylist()"
- />
- </p>
- <p class="control">
- <a
- class="button is-info"
- v-on:click="importPlaylist()"
- href="#"
- >Import</a
- >
- </p>
- </div>
- <table class="table" v-if="queryResults.length > 0">
- <tbody>
- <tr v-for="(result, index) in queryResults" :key="index">
- <td>
- <img :src="result.thumbnail" />
- </td>
- <td>{{ result.title }}</td>
- <td>
- <a
- class="button is-success"
- v-on:click="addSongToQueue(result.id)"
- href="#"
- >Add</a
- >
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- </modal>
- </template>
- <script>
- import { Toast } from "vue-roaster";
- import Modal from "./Modal.vue";
- import io from "../../io";
- export default {
- data() {
- return {
- querySearch: "",
- queryResults: [],
- playlists: [],
- privatePlaylistQueueSelected: null,
- importQuery: ""
- };
- },
- methods: {
- isPlaylistSelected(playlistId) {
- return this.privatePlaylistQueueSelected === playlistId;
- },
- selectPlaylist(playlistId) {
- const _this = this;
- if (_this.$parent.type === "community") {
- _this.privatePlaylistQueueSelected = playlistId;
- _this.$parent.privatePlaylistQueueSelected = playlistId;
- _this.$parent.addFirstPrivatePlaylistSongToQueue();
- }
- },
- unSelectPlaylist() {
- const _this = this;
- if (_this.$parent.type === "community") {
- _this.privatePlaylistQueueSelected = null;
- _this.$parent.privatePlaylistQueueSelected = null;
- }
- },
- addSongToQueue(songId) {
- const _this = this;
- if (_this.$parent.type === "community") {
- _this.socket.emit(
- "stations.addToQueue",
- _this.$parent.station._id,
- songId,
- data => {
- if (data.status !== "success")
- Toast.methods.addToast(
- `Error: ${data.message}`,
- 8000
- );
- else Toast.methods.addToast(`${data.message}`, 4000);
- }
- );
- } else {
- _this.socket.emit("queueSongs.add", songId, data => {
- if (data.status !== "success")
- Toast.methods.addToast(`Error: ${data.message}`, 8000);
- else Toast.methods.addToast(`${data.message}`, 4000);
- });
- }
- },
- importPlaylist() {
- const _this = this;
- Toast.methods.addToast(
- "Starting to import your playlist. This can take some time to do.",
- 4000
- );
- this.socket.emit(
- "queueSongs.addSetToQueue",
- _this.importQuery,
- res => {
- Toast.methods.addToast(res.message, 4000);
- }
- );
- },
- submitQuery() {
- const _this = this;
- let query = _this.querySearch;
- if (query.indexOf("&index=") !== -1) {
- query = query.split("&index=");
- query.pop();
- query = query.join("");
- }
- if (query.indexOf("&list=") !== -1) {
- query = query.split("&list=");
- query.pop();
- query = query.join("");
- }
- _this.socket.emit("apis.searchYoutube", query, res => {
- // check for error
- const { data } = res;
- _this.queryResults = [];
- for (let i = 0; i < data.items.length; i += 1) {
- _this.queryResults.push({
- id: data.items[i].id.videoId,
- url: `https://www.youtube.com/watch?v=${this.id}`,
- title: data.items[i].snippet.title,
- thumbnail: data.items[i].snippet.thumbnails.default.url
- });
- }
- });
- }
- },
- mounted() {
- const _this = this;
- io.getSocket(socket => {
- _this.socket = socket;
- _this.socket.emit("playlists.indexForUser", res => {
- if (res.status === "success") _this.playlists = res.data;
- });
- _this.privatePlaylistQueueSelected =
- _this.$parent.privatePlaylistQueueSelected;
- });
- },
- components: { Modal }
- };
- </script>
- <style lang="scss" scoped>
- tr td {
- vertical-align: middle;
- img {
- width: 55px;
- }
- }
- .table {
- margin-bottom: 0;
- }
- </style>
|