Kaynağa Gözat

feat: toggle shuffle mode with S key

Fela Maslen 4 yıl önce
ebeveyn
işleme
b1a694107c

+ 16 - 0
gmus-web/src/components/ui/cmus/reducer/keypress.spec.ts

@@ -1,5 +1,6 @@
 import {
   activeClientToggled,
+  LocalAction,
   masterSet,
   playPaused,
   queuePushed,
@@ -7,6 +8,7 @@ import {
   stateSet,
 } from '../../../../actions';
 import { ActionKeyPressed, ActionTypeKeyPressed, Keys } from '../../../../hooks/vim';
+import { globalReducer, initialState } from '../../../../reducer';
 
 import { CmusUIState, LibraryModeWindow, Overlay, View } from '../types';
 
@@ -116,6 +118,20 @@ describe(ActionTypeKeyPressed, () => {
     });
   });
 
+  describe(Keys.S, () => {
+    const action: ActionKeyPressed = { type: ActionTypeKeyPressed, key: Keys.S };
+
+    it('should toggle the shuffle value', () => {
+      expect.assertions(2);
+      const result = cmusUIReducer(initialCmusUIState, action);
+      const { globalAction } = result;
+      const globalResult = globalReducer(initialState, globalAction as LocalAction);
+      expect(globalResult.player.shuffleMode).toBe(true);
+      const nextGlobalResult = globalReducer(globalResult, globalAction as LocalAction);
+      expect(nextGlobalResult.player.shuffleMode).toBe(false);
+    });
+  });
+
   describe(Keys.space, () => {
     const action: ActionKeyPressed = { type: ActionTypeKeyPressed, key: Keys.space };
 

+ 6 - 0
gmus-web/src/components/ui/cmus/reducer/keypress.ts

@@ -159,6 +159,12 @@ export function handleKeyPress(state: CmusUIState, action: ActionKeyPressed): Cm
     case Keys.Z:
       return { ...state, skipSong: { delta: -1, serialNumber: state.skipSong.serialNumber + 1 } };
 
+    case Keys.S:
+      return withGlobalAction(
+        state,
+        stateSet((last) => ({ shuffleMode: !last.shuffleMode })),
+      );
+
     case Keys.C:
       return withGlobalAction(state, playPaused());
 

+ 1 - 0
gmus-web/src/hooks/vim.ts

@@ -24,6 +24,7 @@ export const Keys = {
   K: 'k',
   P: 'P',
   p: 'p',
+  S: 's',
   Z: 'z',
 };