ReactNativeClient/lib/reducer.js
function handleItemDelete(state, action) {
	let newState = Object.assign({}, state);

	const map = {
		'FOLDER_DELETE': ['folders', 'selectedFolderId'],
		'NOTE_DELETE': ['notes', 'selectedNoteIds'],
		'TAG_DELETE': ['tags', 'selectedTagId'],
		'SEARCH_DELETE': ['searches', 'selectedSearchId'],
	};

	const listKey = map[action.type][0];
	const selectedItemKey = map[action.type][1];

	let previousIndex = 0;
	let newItems = [];
	const items = state[listKey];
	for (let i = 0; i < items.length; i++) {
		let item = items[i];
		if (item.id == action.id) {
			previousIndex = i;
			continue;
		}
		newItems.push(item);
	}

	newState = Object.assign({}, state);
	newState[listKey] = newItems;

	if (previousIndex >= newItems.length) {
		previousIndex = newItems.length - 1;
	}

	const newId = previousIndex >= 0 ? newItems[previousIndex].id : null;
	newState[selectedItemKey] = action.type === 'NOTE_DELETE' ? [newId] : newId;

	if (!newId && newState.notesParentType !== 'Folder') {
		newState.notesParentType = 'Folder';
	}

	return newState;
}
function handleItemDelete(state, action) {
	let newState = Object.assign({}, state);

	const map = {
		'FOLDER_DELETE': ['folders', 'selectedFolderId'],
		'NOTE_DELETE': ['notes', 'selectedNoteIds'],
		'TAG_DELETE': ['tags', 'selectedTagId'],
		'SEARCH_DELETE': ['searches', 'selectedSearchId'],
	};

	const listKey = map[action.type][0];
	const selectedItemKey = map[action.type][1];

	let previousIndex = 0;
	let newItems = [];
	const items = state[listKey];
	for (let i = 0; i < items.length; i++) {
		let item = items[i];
		if (item.id == action.id) {
			previousIndex = i;
			continue;
		}
		newItems.push(item);
	}

	newState = Object.assign({}, state);
	newState[listKey] = newItems;

	if (previousIndex >= newItems.length) {
		previousIndex = newItems.length - 1;
	}

	const newId = previousIndex >= 0 ? newItems[previousIndex].id : null;
	newState[selectedItemKey] = action.type === 'NOTE_DELETE' ? [newId] : newId;

	if (!newId && newState.notesParentType !== 'Folder') {
		newState.notesParentType = 'Folder';
	}

	return newState;
}
function handleItemDelete ( state , action ) { let newState = Object . assign ( { } , state ) ; const map = { 'FOLDER_DELETE' : [ 'folders' , 'selectedFolderId' ] , 'NOTE_DELETE' : [ 'notes' , 'selectedNoteIds' ] , 'TAG_DELETE' : [ 'tags' , 'selectedTagId' ] , 'SEARCH_DELETE' : [ 'searches' , 'selectedSearchId' ] , } ; const listKey = map [ action . type ] [ 0 ] ; const selectedItemKey = map [ action . type ] [ 1 ] ; let previousIndex = 0 ; let newItems = [ ] ; const items = state [ listKey ] ; for ( let i = 0 ; i < items . length ; i ++ ) { let item = items [ i ] ; if ( item . id == action . id ) { previousIndex = i ; continue ; } newItems . push ( item ) ; } newState = Object . assign ( { } , state ) ; newState [ listKey ] = newItems ; if ( previousIndex >= newItems . length ) { previousIndex = newItems . length - 1 ; } const newId = previousIndex >= 0 ? newItems [ previousIndex ] . id : null ; newState [ selectedItemKey ] = action . type === 'NOTE_DELETE' ? [ newId ] : newId ; if ( ! newId && newState . notesParentType !== 'Folder' ) { newState . notesParentType = 'Folder' ; } return newState ; }
When deleting a note, tag or folder
When deleting a note tag or folder