Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep editor in sync with selected note in NoteList #1220

Merged
merged 1 commit into from
Feb 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions lib/note-list/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ export class NoteList extends Component {
static displayName = 'NoteList';

static propTypes = {
closeNote: PropTypes.func.isRequired,
filter: PropTypes.string.isRequired,
isSmallScreen: PropTypes.bool.isRequired,
notes: PropTypes.array.isRequired,
selectedNoteId: PropTypes.any,
Expand Down Expand Up @@ -254,13 +256,36 @@ export class NoteList extends Component {
}

componentDidUpdate(prevProps) {
const {
closeNote,
filter,
notes,
onSelectNote,
selectedNoteId,
} = this.props;

if (
prevProps.noteDisplay !== this.props.noteDisplay ||
prevProps.notes !== this.props.notes ||
prevProps.notes !== notes ||
prevProps.selectedNoteContent !== this.props.selectedNoteContent
) {
this.recomputeHeights();
}

// Ensure that the note selected here is also selected in the editor
if (selectedNoteId !== prevProps.selectedNoteId) {
onSelectNote(selectedNoteId);
}

// Deselect the currently selected note if it doesn't match the search query
if (filter !== prevProps.filter) {
const selectedNotePassesFilter = notes.some(
note => note.id === selectedNoteId
);
if (!selectedNotePassesFilter) {
closeNote();
}
}
}

componentWillUnmount() {
Expand Down Expand Up @@ -381,7 +406,12 @@ export class NoteList extends Component {
onPinNote = note => this.props.onPinNote(note, !note.pinned);
}

const { emptyTrash, loadAndSelectNote, pinNote } = appState.actionCreators;
const {
closeNote,
emptyTrash,
loadAndSelectNote,
pinNote,
} = appState.actionCreators;
const { recordEvent } = tracks;

const mapStateToProps = ({ appState: state, settings: { noteDisplay } }) => {
Expand Down Expand Up @@ -436,6 +466,7 @@ const mapStateToProps = ({ appState: state, settings: { noteDisplay } }) => {
};

const mapDispatchToProps = (dispatch, { noteBucket }) => ({
closeNote: () => dispatch(closeNote()),
onEmptyTrash: () => dispatch(emptyTrash({ noteBucket })),
onSelectNote: noteId => {
dispatch(loadAndSelectNote({ noteBucket, noteId }));
Expand Down