|
| 1 | +<!-- |
| 2 | + Global dialog to create a new playlist or save a queue as a playlist. |
| 3 | + Because this dialog can be called from various places throughout the app, |
| 4 | + we steer its visibility through the centralized eventbus. |
| 5 | +--> |
| 6 | +<template> |
| 7 | + <v-dialog |
| 8 | + v-model="showDialog" |
| 9 | + max-width="500" |
| 10 | + @update:model-value=" |
| 11 | + (v) => { |
| 12 | + store.dialogActive = v; |
| 13 | + } |
| 14 | + " |
| 15 | + > |
| 16 | + <v-card> |
| 17 | + <v-card-title> |
| 18 | + {{ $t(queueId ? "save_queue_as_playlist" : "new_playlist") }} |
| 19 | + </v-card-title> |
| 20 | + <v-card-text> |
| 21 | + <v-text-field |
| 22 | + ref="nameInput" |
| 23 | + v-model="playlistName" |
| 24 | + :label="$t('new_playlist_name')" |
| 25 | + @keyup.enter="doSave" |
| 26 | + /> |
| 27 | + </v-card-text> |
| 28 | + <v-card-actions> |
| 29 | + <v-spacer /> |
| 30 | + <v-btn variant="text" @click="showDialog = false"> |
| 31 | + {{ $t("close") }} |
| 32 | + </v-btn> |
| 33 | + <v-btn |
| 34 | + variant="text" |
| 35 | + color="primary" |
| 36 | + :disabled="!playlistName" |
| 37 | + @click="doSave" |
| 38 | + > |
| 39 | + {{ $t("settings.save") }} |
| 40 | + </v-btn> |
| 41 | + </v-card-actions> |
| 42 | + </v-card> |
| 43 | + </v-dialog> |
| 44 | +</template> |
| 45 | + |
| 46 | +<script setup lang="ts"> |
| 47 | +import { nextTick, onBeforeUnmount, onMounted, ref, watch } from "vue"; |
| 48 | +import { toast } from "vue-sonner"; |
| 49 | +
|
| 50 | +import api from "@/plugins/api"; |
| 51 | +import { type CreatePlaylistEvent, eventbus } from "@/plugins/eventbus"; |
| 52 | +import { $t } from "@/plugins/i18n"; |
| 53 | +import router from "@/plugins/router"; |
| 54 | +import { store } from "@/plugins/store"; |
| 55 | +
|
| 56 | +const showDialog = ref(false); |
| 57 | +const playlistName = ref(""); |
| 58 | +const queueId = ref(""); |
| 59 | +const providerId = ref(""); |
| 60 | +const nameInput = ref(); |
| 61 | +
|
| 62 | +watch(showDialog, (open) => { |
| 63 | + store.dialogActive = open; |
| 64 | + if (open) { |
| 65 | + nextTick(() => { |
| 66 | + nameInput.value?.focus(); |
| 67 | + }); |
| 68 | + } |
| 69 | +}); |
| 70 | +
|
| 71 | +onMounted(() => { |
| 72 | + eventbus.on("createPlaylist", (evt: CreatePlaylistEvent) => { |
| 73 | + queueId.value = evt.queueId || ""; |
| 74 | + providerId.value = evt.providerId || ""; |
| 75 | + playlistName.value = ""; |
| 76 | + showDialog.value = true; |
| 77 | + }); |
| 78 | +}); |
| 79 | +
|
| 80 | +onBeforeUnmount(() => { |
| 81 | + eventbus.off("createPlaylist"); |
| 82 | +}); |
| 83 | +
|
| 84 | +const doSave = async () => { |
| 85 | + if (!playlistName.value) return; |
| 86 | + showDialog.value = false; |
| 87 | + try { |
| 88 | + const playlist = queueId.value |
| 89 | + ? await api.queueCommandSaveAsPlaylist(queueId.value, playlistName.value) |
| 90 | + : await api.createPlaylist(playlistName.value, providerId.value); |
| 91 | + toast.success($t("playlist_created"), { |
| 92 | + action: { |
| 93 | + label: $t("open_playlist"), |
| 94 | + onClick: () => { |
| 95 | + store.showFullscreenPlayer = false; |
| 96 | + router.push({ |
| 97 | + name: "playlist", |
| 98 | + params: { |
| 99 | + itemId: playlist.item_id, |
| 100 | + provider: playlist.provider, |
| 101 | + }, |
| 102 | + }); |
| 103 | + }, |
| 104 | + }, |
| 105 | + }); |
| 106 | + } catch (e) { |
| 107 | + toast.error(e as string); |
| 108 | + } |
| 109 | +}; |
| 110 | +</script> |
0 commit comments