Skip to content

Commit

Permalink
feat: replace create playlist prompt with custom modal
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro committed Feb 20, 2024
1 parent 8bb98c1 commit c112a4b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 19 deletions.
41 changes: 41 additions & 0 deletions src/components/CreatePlaylistModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<template>
<ModalComponent @close="$emit('close')">
<div class="flex flex-col">
<h2 v-t="'actions.create_playlist'" />
<input type="text" class="input mt-2" v-model="playlistName" />

Check warning on line 5 in src/components/CreatePlaylistModal.vue

View workflow job for this annotation

GitHub Actions / build

Attribute "v-model" should go before "class"
<div class="flex mt-3 ml-auto w-min">

Check warning on line 6 in src/components/CreatePlaylistModal.vue

View workflow job for this annotation

GitHub Actions / build

UnoCSS utilities are not ordered
<button class="btn" v-t="'actions.cancel'" @click="$emit('close')" />

Check warning on line 7 in src/components/CreatePlaylistModal.vue

View workflow job for this annotation

GitHub Actions / build

Attribute "v-t" should go before "class"
<button class="btn ml-2" v-t="'actions.okay'" @click="onCreatePlaylist" />

Check warning on line 8 in src/components/CreatePlaylistModal.vue

View workflow job for this annotation

GitHub Actions / build

Attribute "v-t" should go before "class"
</div>
</div>
</ModalComponent>
</template>

<script>
import ModalComponent from "./ModalComponent.vue";
export default {
components: {
ModalComponent,
},
emits: ["created", "close"],
data() {
return {
playlistName: "",
};
},
methods: {
onCreatePlaylist() {
if (!this.playlistName) return;
this.createPlaylist(this.playlistName).then(response => {
if (response.error) alert(response.error);
else {
this.$emit("created");
this.$emit("close");
}
});
},
},
};
</script>
23 changes: 14 additions & 9 deletions src/components/PlaylistAddModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
<option v-for="playlist in playlists" :key="playlist.id" :value="playlist.id" v-text="playlist.name" />
</select>
<div class="mt-3 w-full flex justify-between">
<button ref="addButton" v-t="'actions.create_playlist'" class="btn" @click="onCreatePlaylist" />
<button
ref="addButton"
v-t="'actions.create_playlist'"
class="btn"
@click="showCreatePlaylistModal = true"
/>
<button
ref="addButton"
v-t="'actions.add_to_playlist'"
Expand All @@ -14,14 +19,21 @@
/>
</div>
</ModalComponent>
<CreatePlaylistModal
v-if="showCreatePlaylistModal"
@close="showCreatePlaylistModal = false"
@created="fetchPlaylists"
/>
</template>

<script>
import ModalComponent from "./ModalComponent.vue";
import CreatePlaylistModal from "./CreatePlaylistModal.vue";
export default {
components: {
ModalComponent,
CreatePlaylistModal,
},
props: {
videoInfo: {
Expand All @@ -39,6 +51,7 @@ export default {
playlists: [],
selectedPlaylist: null,
processing: false,
showCreatePlaylistModal: false,
};
},
mounted() {
Expand Down Expand Up @@ -79,14 +92,6 @@ export default {
this.playlists = json;
});
},
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();
});
},
},
};
</script>
19 changes: 9 additions & 10 deletions src/components/PlaylistsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<h2 v-t="'titles.playlists'" class="my-4 font-bold" />

<div class="mb-3 flex justify-between">
<button v-t="'actions.create_playlist'" class="btn" @click="onCreatePlaylist" />
<button v-t="'actions.create_playlist'" class="btn" @click="showCreatePlaylistModal = true" />
<div class="flex">
<button v-if="playlists.length > 0" v-t="'actions.export_to_json'" class="btn" @click="exportPlaylists" />
<input
Expand Down Expand Up @@ -92,14 +92,20 @@
</router-link>
</div>
<br />
<CreatePlaylistModal
v-if="showCreatePlaylistModal"
@close="showCreatePlaylistModal = false"
@created="fetchPlaylists"
/>
</template>

<script>
import ConfirmModal from "./ConfirmModal.vue";
import ModalComponent from "./ModalComponent.vue";
import CreatePlaylistModal from "./CreatePlaylistModal.vue";
export default {
components: { ConfirmModal, ModalComponent },
components: { ConfirmModal, ModalComponent, CreatePlaylistModal },
data() {
return {
playlists: [],
Expand All @@ -108,6 +114,7 @@ export default {
playlistToEdit: null,
newPlaylistName: "",
newPlaylistDescription: "",
showCreatePlaylistModal: false,
};
},
mounted() {
Expand Down Expand Up @@ -153,14 +160,6 @@ export default {
});
this.playlistToDelete = null;
},
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();
});
},
async exportPlaylists() {
if (!this.playlists) return;
let json = {
Expand Down

0 comments on commit c112a4b

Please sign in to comment.