123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435 |
- <template>
- <modal title="Add Song To Queue">
- <div slot="body">
- <div class="vertical-padding">
- <!-- Choosing a song from youtube -->
- <h4 class="modal-section-title">Choose a song</h4>
- <p class="modal-section-description">
- Choose a song by searching or using a link from YouTube.
- </p>
- <br />
- <div class="control is-grouped input-with-button">
- <p class="control is-expanded">
- <input
- class="input"
- type="text"
- placeholder="Enter your YouTube query here..."
- v-model="querySearch"
- autofocus
- @keyup.enter="submitQuery()"
- />
- </p>
- <p class="control">
- <a
- class="button is-info"
- v-on:click="submitQuery()"
- href="#"
- ><i class="material-icons icon-with-button"
- >search</i
- >Search</a
- >
- </p>
- </div>
- <!-- Choosing a song from youtube - query results -->
- <table
- class="table"
- style="margin-top: 20px;"
- v-if="queryResults.length > 0"
- >
- <tbody>
- <tr
- v-for="(result, index) in queryResults"
- :key="index"
- >
- <td class="song-thumbnail">
- <div
- :style="
- `background-image: url('${result.thumbnail}'`
- "
- ></div>
- </td>
- <td><strong v-html="result.title"></strong></td>
- <td class="song-actions">
- <a
- class="button is-success"
- v-on:click="addSongToQueue(result.id)"
- href="#"
- ><i class="material-icons icon-with-button"
- >add</i
- >Add to queue
- </a>
- </td>
- </tr>
- </tbody>
- </table>
- <!-- Import a playlist from youtube -->
- <hr style="margin: 30px 0;" />
- <h4 class="modal-section-title">
- Import a playlist
- </h4>
- <p class="modal-section-description">
- Import a playlist by using a link from YouTube.
- </p>
- <br />
- <div
- class="control is-grouped input-with-button"
- v-if="station.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="#"
- ><i class="material-icons icon-with-button"
- >publish</i
- >Import</a
- >
- </p>
- </div>
- <!-- Choose a playlist from your account -->
- <div
- v-if="
- loggedIn &&
- station.type === 'community' &&
- playlists.length > 0
- "
- >
- <hr style="margin: 30px 0;" />
- <aside id="playlist-to-queue-selection">
- <h4 class="modal-section-title">Choose a playlist</h4>
- <p class="modal-section-description">
- Choose one of your playlists to add to the queue.
- </p>
- <br />
- <div id="playlists">
- <div
- class="playlist"
- v-for="(playlist, index) in playlists"
- :key="index"
- >
- <playlist-item :playlist="playlist">
- <div slot="actions">
- <a
- class="button is-danger"
- v-on:click="
- addSongToQueue(result.id)
- "
- href="#"
- @click="
- togglePlaylistSelection(
- playlist._id
- )
- "
- v-if="
- isPlaylistSelected(playlist._id)
- "
- >
- <i
- class="material-icons icon-with-button"
- >stop</i
- >
- Stop playing
- </a>
- <a
- class="button is-success"
- v-on:click="
- addSongToQueue(result.id)
- "
- href="#"
- @click="
- togglePlaylistSelection(
- playlist._id
- )
- "
- v-else
- ><i
- class="material-icons icon-with-button"
- >play_arrow</i
- >Play in queue
- </a>
- </div>
- </playlist-item>
- </div>
- </div>
- </aside>
- </div>
- </div>
- </div>
- </modal>
- </template>
- <script>
- import { mapState, mapActions } from "vuex";
- import Toast from "toasters";
- import PlaylistItem from "../PlaylistItem.vue";
- import Modal from "./Modal.vue";
- import io from "../../io";
- export default {
- data() {
- return {
- querySearch: "",
- queryResults: [],
- playlists: [],
- importQuery: ""
- };
- },
- computed: mapState({
- loggedIn: state => state.user.auth.loggedIn,
- station: state => state.station.station,
- privatePlaylistQueueSelected: state =>
- state.station.privatePlaylistQueueSelected
- }),
- methods: {
- isPlaylistSelected(playlistId) {
- return this.privatePlaylistQueueSelected === playlistId;
- },
- togglePlaylistSelection(playlistId) {
- if (this.station.type === "community") {
- if (this.isPlaylistSelected(playlistId)) {
- this.updatePrivatePlaylistQueueSelected(null);
- } else {
- this.updatePrivatePlaylistQueueSelected(playlistId);
- this.$parent.addFirstPrivatePlaylistSongToQueue();
- console.log(this.isPlaylistSelected(playlistId));
- }
- }
- },
- addSongToQueue(songId) {
- console.log(this.station.type);
- if (this.station.type === "community") {
- this.socket.emit(
- "stations.addToQueue",
- this.station._id,
- songId,
- data => {
- if (data.status !== "success")
- new Toast({
- content: `Error: ${data.message}`,
- timeout: 8000
- });
- else
- new Toast({
- content: `${data.message}`,
- timeout: 4000
- });
- }
- );
- } else {
- this.socket.emit("queueSongs.add", songId, data => {
- if (data.status !== "success")
- new Toast({
- content: `Error: ${data.message}`,
- timeout: 8000
- });
- else
- new Toast({
- content: `${data.message}`,
- timeout: 4000
- });
- });
- }
- },
- importPlaylist() {
- new Toast({
- content:
- "Starting to import your playlist. This can take some time to do.",
- timeout: 4000
- });
- this.socket.emit(
- "queueSongs.addSetToQueue",
- this.importQuery,
- res => {
- return new Toast({ content: res.message, timeout: 4000 });
- }
- );
- },
- submitQuery() {
- let query = this.querySearch;
- if (!this.querySearch)
- return new Toast({
- content: "Please input a search query or a YouTube link",
- timeout: 4000
- });
- 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("");
- }
- return this.socket.emit("apis.searchYoutube", query, res => {
- if (res.status === "failure")
- return new Toast({
- content: "Error searching on YouTube",
- timeout: 4000
- });
- const { data } = res;
- this.queryResults = [];
- console.log(res.data);
- 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
- });
- }
- return this.queryResults;
- });
- },
- ...mapActions("station", ["updatePrivatePlaylistQueueSelected"]),
- ...mapActions("user/playlists", ["editPlaylist"])
- },
- mounted() {
- io.getSocket(socket => {
- this.socket = socket;
- this.socket.emit("playlists.indexForUser", res => {
- if (res.status === "success") this.playlists = res.data;
- });
- });
- },
- components: { Modal, PlaylistItem }
- };
- </script>
- <style lang="scss" scoped>
- @import "styles/global.scss";
- tr td {
- vertical-align: middle;
- }
- .song-thumbnail {
- padding-left: 0;
- }
- .song-actions {
- padding-right: 0;
- .button {
- height: 36px;
- }
- }
- .song-thumbnail div {
- width: 96px;
- height: 54px;
- background-position: center;
- background-repeat: no-repeat;
- }
- .table {
- margin-bottom: 0;
- }
- .night-mode {
- .modal-section {
- color: #000;
- }
- div {
- color: #4d4d4d;
- }
- }
- .modal-section {
- margin-top: 20px;
- padding: 10px 20px;
- background-color: #f5f5f5;
- }
- .modal-section-title {
- font-size: 26px;
- margin: 0px;
- }
- .modal-section-description {
- margin-bottom: 5px;
- }
- #playlist-to-queue-selection {
- margin-top: 0;
- #playlists {
- font-size: 18px;
- .radio {
- display: flex;
- flex-direction: row;
- align-items: center;
- input {
- transform: scale(1.25);
- }
- }
- }
- }
- .input-with-button {
- .control {
- margin-right: 0px !important;
- }
- input {
- height: 36px;
- border-radius: 3px 0 3px 0;
- }
- .button {
- height: 36px;
- border-radius: 0 3px 3px 0;
- }
- }
- .vertical-padding {
- padding: 20px;
- }
- #playlists {
- .playlist {
- .button {
- width: 146px;
- }
- }
- }
- </style>
|