Explorar o código

feat: toggle active state of selected client when pressing space bar

Fela Maslen %!s(int64=4) %!d(string=hai) anos
pai
achega
0cd84d2efe

+ 29 - 1
gmus-web/src/components/ui/cmus/reducer/keypress.spec.ts

@@ -1,4 +1,11 @@
-import { masterSet, playPaused, queuePushed, queueRemoved, stateSet } from '../../../../actions';
+import {
+  activeClientToggled,
+  masterSet,
+  playPaused,
+  queuePushed,
+  queueRemoved,
+  stateSet,
+} from '../../../../actions';
 import { ActionKeyPressed, ActionTypeKeyPressed, Keys } from '../../../../hooks/vim';
 
 import { CmusUIState, LibraryModeWindow, Overlay, View } from '../types';
@@ -271,6 +278,27 @@ describe(ActionTypeKeyPressed, () => {
     });
   });
 
+  describe('Space bar', () => {
+    const action: ActionKeyPressed = { type: ActionTypeKeyPressed, key: Keys.space };
+
+    describe('when in client list view', () => {
+      const state: CmusUIState = {
+        ...initialCmusUIState,
+        globalActionSerialNumber: 123,
+        view: View.ClientList,
+        clientList: {
+          active: 'our-client',
+        },
+      };
+
+      it('should set the globalAction to toggle the active state of the given client', () => {
+        expect.assertions(1);
+        const result = cmusUIReducer(state, action);
+        expect(result.globalAction).toStrictEqual(activeClientToggled('our-client'));
+      });
+    });
+  });
+
   describe(Keys.D, () => {
     const action: ActionKeyPressed = { type: ActionTypeKeyPressed, key: Keys.D };
 

+ 28 - 7
gmus-web/src/components/ui/cmus/reducer/keypress.ts

@@ -1,4 +1,11 @@
-import { masterSet, playPaused, queuePushed, queueRemoved, stateSet } from '../../../../actions';
+import {
+  activeClientToggled,
+  masterSet,
+  playPaused,
+  queuePushed,
+  queueRemoved,
+  stateSet,
+} from '../../../../actions';
 import { ActionKeyPressed, Keys } from '../../../../hooks/vim';
 import { getFilteredSongs } from '../selectors';
 import { CmusUIState, LibraryModeWindow, Overlay, View } from '../types';
@@ -77,6 +84,25 @@ function handleActivate(state: CmusUIState): CmusUIState {
   }
 }
 
+function handleToggle(state: CmusUIState): CmusUIState {
+  switch (state.view) {
+    case View.Library:
+      if (state.library.modeWindow === LibraryModeWindow.ArtistList) {
+        return { ...state, library: toggleExpandArtist(state.library) };
+      }
+      return state;
+
+    case View.ClientList:
+      if (!state.clientList.active) {
+        return state;
+      }
+      return withGlobalAction(state, activeClientToggled(state.clientList.active));
+
+    default:
+      return state;
+  }
+}
+
 function addSelectedToQueue(state: CmusUIState): CmusUIState {
   if (state.view !== View.Library) {
     return state;
@@ -113,12 +139,7 @@ export function handleKeyPress(state: CmusUIState, action: ActionKeyPressed): Cm
       return state;
 
     case Keys.space:
-      if (state.view === View.Library) {
-        if (state.library.modeWindow === LibraryModeWindow.ArtistList) {
-          return { ...state, library: toggleExpandArtist(state.library) };
-        }
-      }
-      return state;
+      return handleToggle(state);
 
     case Keys.enter:
       return handleActivate(state);

+ 1 - 0
gmus-web/src/components/ui/cmus/views/help.tsx

@@ -31,6 +31,7 @@ const commandsLibrary: Command[] = [
 
 const commandsClientList: Command[] = [
   { command: '<Enter>', description: 'set the selected client to master' },
+  { command: '<Space>', description: 'toggle active state of selected client' },
 ];
 
 const commandsQueue: Command[] = [