Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Commit

Permalink
fix: saved mode by note (#49)
Browse files Browse the repository at this point in the history
Co-authored-by: Johnny Almonte <[email protected]>
  • Loading branch information
johnny243 and johnny243 authored May 13, 2021
1 parent dd08375 commit bbf49e5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
23 changes: 13 additions & 10 deletions app/components/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,19 @@ export default class Home extends React.Component {
setModeFromModeValue(value) {
for (let mode of this.modes) {
if (mode.mode == value) {
this.setState({ mode: mode });
this.setState({ mode });
return;
}
}
}

changeMode(mode) {
this.setState({ mode: mode });
if (this.note) {
this.componentRelay.setComponentDataValueForKey('mode', mode.mode);
this.setState({ mode });
if (!this.note) {
return;
}
this.note.clientData = { mode: mode.mode };
this.componentRelay.saveItem(this.note);
}

configureMarkdown() {
Expand Down Expand Up @@ -114,18 +116,19 @@ export default class Home extends React.Component {
initialPermissions,
targetWindow: window,
onReady: () => {
const savedMode = this.componentRelay.getComponentDataValueForKey('mode');
if (savedMode) {
this.setModeFromModeValue(savedMode);
}

this.setState({ platform: this.componentRelay.platform });
const { platform } = this.componentRelay;
this.setState({ platform });
}
});

this.componentRelay.streamContextItem((note) => {
this.note = note;

if (note.clientData) {
const mode = note.clientData.mode ?? EditMode;
this.setModeFromModeValue(mode);
}

// Only update UI on non-metadata updates.
if (note.isMetadataUpdate) {
return;
Expand Down
2 changes: 1 addition & 1 deletion dist/dist.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dist.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sn-simple-markdown-editor",
"version": "1.3.9",
"version": "1.3.10",
"main": "dist/dist.js",
"scripts": {
"lint": "eslint --cache --ext .jsx,.js --format=node_modules/eslint-formatter-pretty .",
Expand Down

0 comments on commit bbf49e5

Please sign in to comment.