File size: 1,091 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
import { findNextNoteId } from '../../../templates';
import * as types from '../../action-types';
import actions from '../../actions';
import getAllNotes from '../../selectors/get-all-notes';
import getIsNoteHidden from '../../selectors/get-is-note-hidden';

export const advanceToNextNote = ( { dispatch, getState }, { noteId } ) => {
	const state = getState();

	// move to next note in the sequence…
	const nextNoteId = findNextNoteId(
		noteId,
		getAllNotes( state ).filter( ( { id } ) => ! getIsNoteHidden( state, id ) )
	);

	// if the window is wide enough and we have a next node
	// then go ahead and open it
	// otherwise go back to the list
	if ( nextNoteId && window.innerWidth >= 800 ) {
		dispatch( actions.ui.selectNote( nextNoteId ) );
	} else {
		dispatch( actions.ui.unselectNote() );
	}
};

const toggleDrawer = ( { dispatch }, { noteId } ) =>
	dispatch( actions.ui.setLayout( noteId ? 'widescreen' : 'narrow' ) );

export default {
	[ types.SELECT_NOTE ]: [ toggleDrawer ],
	[ types.SPAM_NOTE ]: [ advanceToNextNote ],
	[ types.TRASH_NOTE ]: [ advanceToNextNote ],
};