Skip to content

Commit

Permalink
Remove print state and call print directly (#1872)
Browse files Browse the repository at this point in the history
This PR calls the print function directly from app.tsx rather than setting up state. By not having to set editor/preview mode we decrease the complexity of this functionality while giving the user the option to print the editor view OR the markdown styled mode.

Before this change, the print function was intended to only print the formatted markdown mode but the functionality is broken. This PR removes the broken code.
  • Loading branch information
belcherj committed Feb 5, 2020
1 parent 9187a0e commit 6866e85
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 26 deletions.
2 changes: 1 addition & 1 deletion desktop/menus/file-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const submenu = [
{
label: '&Print…',
accelerator: 'CommandOrControl+P',
click: appCommandSender({ action: 'setShouldPrintNote' }),
click: appCommandSender({ action: 'printNote' }),
},
];

Expand Down
4 changes: 4 additions & 0 deletions lib/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ export const App = connect(
exportZipArchive();
}

if ('printNote' === command.action) {
return window.print();
}

const canRun = overEvery(
isObject,
o => o.action !== null,
Expand Down
7 changes: 0 additions & 7 deletions lib/flux/app-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const initialState: AppState = {
editingTags: false,
dialogs: [],
nextDialogKey: 0,
shouldPrint: false,
searchFocus: false,
unsyncedNoteIds: [], // note bucket only
};
Expand Down Expand Up @@ -323,12 +322,6 @@ export const actionMap = new ActionMap({
});
},

setShouldPrintNote(state: AppState, { shouldPrint = true }) {
return update(state, {
shouldPrint: { $set: shouldPrint },
});
},

setSearchFocus(state: AppState, { searchFocus = true }) {
return update(state, {
searchFocus: { $set: searchFocus },
Expand Down
19 changes: 2 additions & 17 deletions lib/note-detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ export class NoteDetail extends Component {
fontSize: PropTypes.number,
onChangeContent: PropTypes.func.isRequired,
syncNote: PropTypes.func.isRequired,
onNotePrinted: PropTypes.func.isRequired,
note: PropTypes.object,
noteBucket: PropTypes.object.isRequired,
previewingMarkdown: PropTypes.bool,
shouldPrint: PropTypes.bool.isRequired,
showNoteInfo: PropTypes.bool.isRequired,
spellCheckEnabled: PropTypes.bool.isRequired,
storeFocusEditor: PropTypes.func,
Expand Down Expand Up @@ -72,13 +70,7 @@ export class NoteDetail extends Component {
}

componentDidUpdate(prevProps) {
const { note, onNotePrinted, previewingMarkdown, shouldPrint } = this.props;

// Immediately print once `shouldPrint` has been set
if (shouldPrint) {
window.print();
onNotePrinted();
}
const { note, previewingMarkdown } = this.props;

const prevContent = get(prevProps, 'note.data.content', '');
const nextContent = get(this.props, 'note.data.content', '');
Expand Down Expand Up @@ -243,15 +235,8 @@ export class NoteDetail extends Component {
const mapStateToProps = ({ appState: state, settings }) => ({
dialogs: state.dialogs,
filter: state.filter,
shouldPrint: state.shouldPrint,
showNoteInfo: state.showNoteInfo,
spellCheckEnabled: settings.spellCheckEnabled,
});

const { setShouldPrintNote } = appState.actionCreators;

const mapDispatchToProps = {
onNotePrinted: () => setShouldPrintNote({ shouldPrint: false }),
};

export default connect(mapStateToProps, mapDispatchToProps)(NoteDetail);
export default connect(mapStateToProps)(NoteDetail);
1 change: 0 additions & 1 deletion lib/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export type AppState = {
previousIndex: number;
revision: T.NoteEntity | null;
searchFocus: boolean;
shouldPrint: boolean;
showNavigation: boolean;
showNoteInfo: boolean;
showTrash: boolean;
Expand Down

0 comments on commit 6866e85

Please sign in to comment.