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
Move editor mode to redux #1866
Conversation
1ea0f5c
to
8298de2
Compare
@dmsnell @codebykat ready for more review |
@dmsnell @codebykat please rereview |
lib/note-toolbar-container.ts
Outdated
@@ -129,7 +129,7 @@ const mapDispatchToProps = dispatch => ({ | |||
deleteNoteForever: args => dispatch(deleteNoteForever(args)), | |||
noteRevisions: args => dispatch(noteRevisions(args)), | |||
restoreNote: args => dispatch(restoreNote(args)), | |||
setEditorMode: args => dispatch(setEditorMode(args)), | |||
setEditorMode: mode => dispatch(setEditorMode(mode)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to do all the work in this PR, but these actions somewhat subvert our normal Redux pattern. All we're doing is passing them to the child component, so how about moving them properly while we're fixing the other aspect of this one Redux state type.
That is, can we eliminate this action from the <NoteToolBar />
container and instead put it in <NoteToolbar />
where it's used?
In that file it looks like we're using state-based logic as well when all we care about doing is toggling. If we wanted, we could further remove the duplicated logic and create a second new action-type and let the reducer centralize and isolate that logic…
// action-types
export type SetEditorMode = Action<'SET_EDITOR_MODE', { mode: T.EditorMode }>;
export type ToggleEditorMode = Action<'TOGGLE_EDITOR_MODE'>;
// reducer
const editorMode: A.Reducer<T.EditorMode> = (state = 'edit', action) => {
switch (action.type) {
case 'TOGGLE_EDITOR_MODE':
return state === 'edit' ? 'markdown' : 'edit';
case 'SET_EDITOR_MODE':
case 'App.setEditorMode':
return action.mode;
case 'App.newNote':
return 'edit';
default:
return state;
}
};
Just mentioning the toggler because it stood out to me in <NoteToolbar />
that we're doing extra logic because we didn't have a semantic way of indicating what we wanted to do and because it's a small change while updating the edit mode logic. It's not essential but might be worth it and a good example of where Redux lets us think more about semantic app interactions than merely being a bag of global setters.
It looks like if we handle // action-types
export type CreateNote = Action<'CREATE_NOTE'>;
// editorMode reducer
case 'CREATE_NOTE':
return 'edit'; Later on that action type could be filled-in with additional necessary properties when we remove it from |
5820731
to
6866e85
Compare
import * as A from '../action-types'; | ||
import * as T from '../../types'; | ||
|
||
const defaultVisiblePanes = ['editor', 'noteList']; | ||
const emptyList: unknown[] = []; | ||
|
||
const editMode: A.Reducer<boolean> = (state = true, action) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changing from named states to boolean seems like a semantic regression.
does true
or false
mean "preview"?
I can follow the idea if we're saying "edit mode" is the mode, though particularly since we talk about edit vs. preview when discussing this I personally find 'edit'
and 'preview'
clearer in the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reasoned about this for a while. I'd love to chat about it but I came to the opposite conclusion. We are in either editor more or preview. If edit mode is true then we are in preview. Just as is the tag panel open or closed, or are we in focus mode or is the note list open.
Remove print state and call print directly (#1872) 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.
e4c7a7c
to
380825c
Compare
Fix
This PR moves the editor mode state from flux to redux.
Test
Review
Only one developer is required to review these changes, but anyone can perform the review.