Преглед изворни кода

feat: binding to remove song from queue

Fela Maslen пре 5 година
родитељ
комит
8a49b14b5f

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

@@ -1,4 +1,11 @@
-import { masterSet, playPaused, queueOrdered, queuePushed, stateSet } from '../../../../actions';
+import {
+  masterSet,
+  playPaused,
+  queueOrdered,
+  queuePushed,
+  queueRemoved,
+  stateSet,
+} from '../../../../actions';
 import { ActionKeyPressed, ActionTypeKeyPressed, Keys } from '../../../../hooks/vim';
 import { Song } from '../../../../types';
 
@@ -657,6 +664,23 @@ describe(ActionTypeKeyPressed, () => {
     });
   });
 
+  describe(Keys.D, () => {
+    const action: ActionKeyPressed = { type: ActionTypeKeyPressed, key: Keys.D };
+
+    describe('when on the queue view', () => {
+      it('should set the globalAction to remove the active song from the queue', () => {
+        expect.assertions(1);
+
+        const result = cmusUIReducer(
+          { ...stateQueue, queue: { ...stateQueue.queue, active: 75 } },
+          action,
+        );
+
+        expect(result.globalAction).toStrictEqual(queueRemoved(75));
+      });
+    });
+  });
+
   describe(Keys.esc, () => {
     const action: ActionKeyPressed = { type: ActionTypeKeyPressed, key: Keys.esc };
 

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

@@ -1,4 +1,4 @@
-import { masterSet, playPaused, queuePushed, stateSet } from '../../../../actions';
+import { masterSet, playPaused, queuePushed, queueRemoved, stateSet } from '../../../../actions';
 import { ActionKeyPressed, Keys } from '../../../../hooks/vim';
 import { CmusUIState, LibraryModeWindow, Overlay, View } from '../types';
 import { handleOrder } from './order';
@@ -118,6 +118,12 @@ export function handleKeyPress(state: CmusUIState, action: ActionKeyPressed): Cm
     case Keys.C:
       return withGlobalAction(state, playPaused());
 
+    case Keys.D:
+      if (state.view === View.Queue && state.queue.active) {
+        return withGlobalAction(state, queueRemoved(state.queue.active));
+      }
+      return state;
+
     case Keys.E:
       if (
         state.view === View.Library &&

+ 3 - 1
gmus-web/src/components/ui/cmus/views/queue.tsx

@@ -35,7 +35,9 @@ export const ViewQueue: React.FC<Props> = ({ currentSong }) => {
   });
 
   useEffect(() => {
-    fetchQueueInfo(queue);
+    if (queue.length) {
+      fetchQueueInfo(queue);
+    }
   }, [fetchQueueInfo, queue]);
 
   const orderedSongInfo = useMemo<Song[]>(

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

@@ -15,6 +15,7 @@ export const Keys = {
   '3': '3',
   B: 'b',
   C: 'c',
+  D: 'd',
   E: 'e',
   J: 'j',
   K: 'k',