File size: 1,462 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { combineReducers } from 'redux';
import {
	NOTES_LOADED,
	NOTES_LOADING,
	SELECT_NOTE,
	SET_IS_SHOWING,
	SET_FILTER,
	ENABLE_KEYBOARD_SHORTCUTS,
	DISABLE_KEYBOARD_SHORTCUTS,
} from '../action-types';

export const isLoading = ( state = true, { type } ) => {
	if ( NOTES_LOADING === type ) {
		return true;
	}

	if ( NOTES_LOADED === type ) {
		return false;
	}

	return state;
};

export const isPanelOpen = ( state = false, { type, isShowing } ) =>
	SET_IS_SHOWING === type ? isShowing : state;

export const selectedNoteId = ( state = null, { type, noteId } ) => {
	if ( SELECT_NOTE === type ) {
		return noteId;
	}

	if ( SET_FILTER === type ) {
		return null;
	}

	return state;
};

export const keyboardShortcutsAreEnabled = ( state = false, action ) => {
	switch ( action.type ) {
		case ENABLE_KEYBOARD_SHORTCUTS: {
			return true;
		}
		case DISABLE_KEYBOARD_SHORTCUTS: {
			return false;
		}
	}
	return state;
};

// eslint-disable-next-line no-shadow
export const filterName = ( state = 'all', { type, filterName } ) =>
	SET_FILTER === type ? filterName : state;

export const shortcutsPopoverIsOpen = ( state = false, { type } ) => {
	switch ( type ) {
		case 'TOGGLE_SHORTCUTS_POPOVER':
			return ! state;
		case 'CLOSE_SHORTCUTS_POPOVER':
			return false;
		default:
			return state;
	}
};

export default combineReducers( {
	isLoading,
	isPanelOpen,
	selectedNoteId,
	filterName,
	keyboardShortcutsAreEnabled,
	shortcutsPopoverIsOpen,
} );