From 77742dbb6ed0d80d1f8846d3bbabc9a8b6419240 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Sat, 9 Apr 2022 08:45:25 +0100 Subject: [PATCH] Add keybinds for adding playlist. Closes #963 --- src/components/PlaylistAddModal.vue | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/components/PlaylistAddModal.vue b/src/components/PlaylistAddModal.vue index a27767aa..f61511b0 100644 --- a/src/components/PlaylistAddModal.vue +++ b/src/components/PlaylistAddModal.vue @@ -51,20 +51,37 @@ export default { return { playlists: [], selectedPlaylist: null, + processing: false, }; }, mounted() { this.fetchPlaylists(); this.selectedPlaylist = this.getPreferenceString("selectedPlaylist" + this.hashCode(this.apiUrl())); + window.addEventListener("keydown", this.handleKeyDown); + window.blur(); + }, + unmounted() { + window.removeEventListener("keydown", this.handleKeyDown); }, methods: { + handleKeyDown(event) { + if (event.code === "Escape") { + this.$emit("close"); + } else if (event.code === "Enter") { + this.handleClick(this.selectedPlaylist); + } else return; + event.preventDefault(); + }, handleClick(playlistId) { if (!playlistId) { alert(this.$t("actions.please_select_playlist")); return; } + if (this.processing) return; + this.$refs.addButton.disabled = true; + this.processing = true; this.fetchJson(this.apiUrl() + "/user/playlists/add", null, { method: "POST",