From 571ea3c653d802393d657194412b9de466e77789 Mon Sep 17 00:00:00 2001 From: jeffvli Date: Sat, 23 Sep 2023 03:20:04 -0700 Subject: [PATCH] Add rating hotkeys (#208) --- .../features/player/components/right-controls.tsx | 8 +++++++- .../components/hotkeys/hotkey-manager-settings.tsx | 6 ++++++ src/renderer/store/settings.store.ts | 12 ++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/renderer/features/player/components/right-controls.tsx b/src/renderer/features/player/components/right-controls.tsx index c3124f94..9221f3b9 100644 --- a/src/renderer/features/player/components/right-controls.tsx +++ b/src/renderer/features/player/components/right-controls.tsx @@ -69,7 +69,7 @@ export const RightControls = () => { }); }; - const handleClearRating = (_e: MouseEvent, rating?: number) => { + const handleClearRating = (_e: MouseEvent | null, rating?: number) => { if (!currentSong || !rating) return; updateRatingMutation.mutate({ @@ -115,6 +115,12 @@ export const RightControls = () => { [bindings.volumeUp.isGlobal ? '' : bindings.volumeUp.hotkey, handleVolumeUp], [bindings.volumeMute.isGlobal ? '' : bindings.volumeMute.hotkey, handleMute], [bindings.toggleQueue.isGlobal ? '' : bindings.toggleQueue.hotkey, handleToggleQueue], + [bindings.rate0.isGlobal ? '' : bindings.rate0.hotkey, () => handleClearRating(null, 0)], + [bindings.rate1.isGlobal ? '' : bindings.rate1.hotkey, () => handleUpdateRating(1)], + [bindings.rate2.isGlobal ? '' : bindings.rate2.hotkey, () => handleUpdateRating(2)], + [bindings.rate3.isGlobal ? '' : bindings.rate3.hotkey, () => handleUpdateRating(3)], + [bindings.rate4.isGlobal ? '' : bindings.rate4.hotkey, () => handleUpdateRating(4)], + [bindings.rate5.isGlobal ? '' : bindings.rate5.hotkey, () => handleUpdateRating(5)], ]); useEffect(() => { diff --git a/src/renderer/features/settings/components/hotkeys/hotkey-manager-settings.tsx b/src/renderer/features/settings/components/hotkeys/hotkey-manager-settings.tsx index 5d949a0d..8762715b 100644 --- a/src/renderer/features/settings/components/hotkeys/hotkey-manager-settings.tsx +++ b/src/renderer/features/settings/components/hotkeys/hotkey-manager-settings.tsx @@ -20,6 +20,12 @@ const BINDINGS_MAP: Record = { play: 'Play', playPause: 'Play / Pause', previous: 'Previous track', + rate0: 'Rating clear', + rate1: 'Rating 1 star', + rate2: 'Rating 2 star', + rate3: 'Rating 3 star', + rate4: 'Rating 4 star', + rate5: 'Rating 5 star', skipBackward: 'Skip backward', skipForward: 'Skip forward', stop: 'Stop', diff --git a/src/renderer/store/settings.store.ts b/src/renderer/store/settings.store.ts index 09cd8e3b..bfe33ab6 100644 --- a/src/renderer/store/settings.store.ts +++ b/src/renderer/store/settings.store.ts @@ -91,6 +91,12 @@ export enum BindingActions { PLAY = 'play', PLAY_PAUSE = 'playPause', PREVIOUS = 'previous', + RATE_0 = 'rate0', + RATE_1 = 'rate1', + RATE_2 = 'rate2', + RATE_3 = 'rate3', + RATE_4 = 'rate4', + RATE_5 = 'rate5', SHUFFLE = 'toggleShuffle', SKIP_BACKWARD = 'skipBackward', SKIP_FORWARD = 'skipForward', @@ -234,6 +240,12 @@ const initialState: SettingsState = { play: { allowGlobal: true, hotkey: '', isGlobal: false }, playPause: { allowGlobal: true, hotkey: '', isGlobal: false }, previous: { allowGlobal: true, hotkey: '', isGlobal: false }, + rate0: { allowGlobal: true, hotkey: '', isGlobal: false }, + rate1: { allowGlobal: true, hotkey: '', isGlobal: false }, + rate2: { allowGlobal: true, hotkey: '', isGlobal: false }, + rate3: { allowGlobal: true, hotkey: '', isGlobal: false }, + rate4: { allowGlobal: true, hotkey: '', isGlobal: false }, + rate5: { allowGlobal: true, hotkey: '', isGlobal: false }, skipBackward: { allowGlobal: true, hotkey: '', isGlobal: false }, skipForward: { allowGlobal: true, hotkey: '', isGlobal: false }, stop: { allowGlobal: true, hotkey: '', isGlobal: false },