|
@@ -1,6 +1,6 @@
|
|
|
import { createContext, Dispatch } from 'react';
|
|
import { createContext, Dispatch } from 'react';
|
|
|
|
|
|
|
|
-import { stateSet } from '../../../actions';
|
|
|
|
|
|
|
+import { LocalAction, loggedOut, stateSet } from '../../../actions';
|
|
|
import { nullDispatch } from '../../../context/state';
|
|
import { nullDispatch } from '../../../context/state';
|
|
|
import { ActionTypeKeyPressed, Keys } from '../../../hooks/vim';
|
|
import { ActionTypeKeyPressed, Keys } from '../../../hooks/vim';
|
|
|
import { scrollThroughItems } from '../../../utils/delta';
|
|
import { scrollThroughItems } from '../../../utils/delta';
|
|
@@ -17,6 +17,7 @@ export const initialCmusUIState: CmusUIState = {
|
|
|
globalAction: null,
|
|
globalAction: null,
|
|
|
globalActionSerialNumber: 0,
|
|
globalActionSerialNumber: 0,
|
|
|
view: View.Library,
|
|
view: View.Library,
|
|
|
|
|
+ commandMode: false,
|
|
|
artists: [],
|
|
artists: [],
|
|
|
artistAlbums: {},
|
|
artistAlbums: {},
|
|
|
artistSongs: {},
|
|
artistSongs: {},
|
|
@@ -35,6 +36,12 @@ export const CmusUIDispatchContext = createContext<Dispatch<CmusUIAction>>(nullD
|
|
|
|
|
|
|
|
const libraryModeWindows: LibraryModeWindow[] = Object.values(LibraryModeWindow);
|
|
const libraryModeWindows: LibraryModeWindow[] = Object.values(LibraryModeWindow);
|
|
|
|
|
|
|
|
|
|
+const withGlobalAction = (state: CmusUIState, action: LocalAction): CmusUIState => ({
|
|
|
|
|
+ ...state,
|
|
|
|
|
+ globalAction: action,
|
|
|
|
|
+ globalActionSerialNumber: state.globalActionSerialNumber + 1,
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
const switchLibraryMode = (state: CmusUIState): CmusUIState => ({
|
|
const switchLibraryMode = (state: CmusUIState): CmusUIState => ({
|
|
|
...state,
|
|
...state,
|
|
|
library: {
|
|
library: {
|
|
@@ -127,6 +134,9 @@ function handleScrollUp(state: CmusUIState): CmusUIState {
|
|
|
|
|
|
|
|
function handleKeyPress(state: CmusUIState, key: string): CmusUIState {
|
|
function handleKeyPress(state: CmusUIState, key: string): CmusUIState {
|
|
|
switch (key) {
|
|
switch (key) {
|
|
|
|
|
+ case Keys.colon:
|
|
|
|
|
+ return { ...state, commandMode: true };
|
|
|
|
|
+
|
|
|
case Keys['1']:
|
|
case Keys['1']:
|
|
|
return { ...state, view: View.Library };
|
|
return { ...state, view: View.Library };
|
|
|
case Keys.tab:
|
|
case Keys.tab:
|
|
@@ -150,16 +160,15 @@ function handleKeyPress(state: CmusUIState, key: string): CmusUIState {
|
|
|
return state;
|
|
return state;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return {
|
|
|
|
|
- ...state,
|
|
|
|
|
- globalAction: stateSet({
|
|
|
|
|
|
|
+ return withGlobalAction(
|
|
|
|
|
+ state,
|
|
|
|
|
+ stateSet({
|
|
|
playing: true,
|
|
playing: true,
|
|
|
songId: state.library.activeSongId,
|
|
songId: state.library.activeSongId,
|
|
|
currentTime: 0,
|
|
currentTime: 0,
|
|
|
seekTime: 0,
|
|
seekTime: 0,
|
|
|
}),
|
|
}),
|
|
|
- globalActionSerialNumber: state.globalActionSerialNumber + 1,
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -198,6 +207,17 @@ const setArtistSongs = (state: CmusUIState, action: ArtistSongsLoaded): CmusUISt
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+function onCommand(state: CmusUIState, command: string | null): CmusUIState {
|
|
|
|
|
+ const nextState: CmusUIState = { ...state, commandMode: false };
|
|
|
|
|
+
|
|
|
|
|
+ switch (command) {
|
|
|
|
|
+ case 'q':
|
|
|
|
|
+ return withGlobalAction(nextState, loggedOut());
|
|
|
|
|
+ default:
|
|
|
|
|
+ return nextState;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
export function cmusUIReducer(state: CmusUIState, action: CmusUIAction): CmusUIState {
|
|
export function cmusUIReducer(state: CmusUIState, action: CmusUIAction): CmusUIState {
|
|
|
switch (action.type) {
|
|
switch (action.type) {
|
|
|
case ActionTypeKeyPressed:
|
|
case ActionTypeKeyPressed:
|
|
@@ -210,8 +230,8 @@ export function cmusUIReducer(state: CmusUIState, action: CmusUIAction): CmusUIS
|
|
|
case CmusUIActionType.ArtistSongsLoaded:
|
|
case CmusUIActionType.ArtistSongsLoaded:
|
|
|
return setArtistSongs(state, action);
|
|
return setArtistSongs(state, action);
|
|
|
|
|
|
|
|
- case CmusUIActionType.LibraryModeSet:
|
|
|
|
|
- return { ...state, library: { ...state.library, modeWindow: action.payload } };
|
|
|
|
|
|
|
+ case CmusUIActionType.CommandSet:
|
|
|
|
|
+ return onCommand(state, action.payload);
|
|
|
|
|
|
|
|
default:
|
|
default:
|
|
|
return state;
|
|
return state;
|