Skip to content

Commit

Permalink
guard against selected note ID being bad (#1776)
Browse files Browse the repository at this point in the history
  • Loading branch information
codebykat authored Dec 13, 2019
1 parent 8c5227f commit 86f0d3a
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions lib/note-list/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,7 @@ const { recordEvent } = tracks;
const mapStateToProps = ({ appState: state, settings: { noteDisplay } }) => {
const tagResultsFound = getMatchingTags(state.tags, state.filter).length;

const filteredNotes = createCompositeNoteList(
filterNotes(state),
state.filter,
tagResultsFound
);
const filteredNotes = filterNotes(state);

const noteIndex = Math.max(state.previousIndex, 0);
const selectedNote = state.note ? state.note : filteredNotes[noteIndex];
Expand All @@ -524,6 +520,12 @@ const mapStateToProps = ({ appState: state, settings: { noteDisplay } }) => {
const nextNote = filteredNotes[nextNoteId];
const prevNote = filteredNotes[prevNoteId];

const compositeNoteList = createCompositeNoteList(
filteredNotes,
state.filter,
tagResultsFound
);

/**
* Although not used directly in the React component this value
* is used to bust the cache when editing a note and the number
Expand Down Expand Up @@ -552,7 +554,7 @@ const mapStateToProps = ({ appState: state, settings: { noteDisplay } }) => {
hasLoaded: state.notes !== null,
nextNote,
noteDisplay,
notes: filteredNotes,
notes: compositeNoteList,
prevNote,
selectedNotePreview,
selectedNoteContent: get(selectedNote, 'data.content'),
Expand All @@ -566,13 +568,12 @@ const mapDispatchToProps = (dispatch, { noteBucket }) => ({
closeNote: () => dispatch(closeNote()),
onEmptyTrash: () => dispatch(emptyTrash({ noteBucket })),
onSelectNote: noteId => {
dispatch(loadAndSelectNote({ noteBucket, noteId }));
recordEvent('list_note_opened');
if (noteId) {
dispatch(loadAndSelectNote({ noteBucket, noteId }));
recordEvent('list_note_opened');
}
},
onPinNote: (note, pin) => dispatch(pinNote({ noteBucket, note, pin })),
});

export default connect(
mapStateToProps,
mapDispatchToProps
)(NoteList);
export default connect(mapStateToProps, mapDispatchToProps)(NoteList);

0 comments on commit 86f0d3a

Please sign in to comment.