From 06585c8dbd9ba488f1a30d0f181c894d37b95e32 Mon Sep 17 00:00:00 2001 From: Johnny A <5891646+johnny243@users.noreply.github.com> Date: Thu, 20 May 2021 10:57:41 -0400 Subject: [PATCH] feat: prevent adding entries when note is locked (#46) * feat: prevent adding entries when note is locked * chore(deps): update editor-kit * fix: building config * chore: build * chore: increment version * chore(deps): lock editor-kit to 2.0.1 * fix: canEdit default value to true * chore(deps): update editor kit * chore: build Co-authored-by: Johnny Almonte --- app/components/AuthEntry.js | 19 +- app/components/Home.js | 53 +- app/components/ViewEntries.js | 6 +- app/stylesheets/main.scss | 4 + dist/dist.css | 2074 +-------------------------------- dist/dist.css.map | 1 - dist/dist.js | 2 +- dist/index.html | 2 +- editor.index.ejs | 1 - package.json | 5 +- webpack.config.js | 17 +- yarn.lock | 13 +- 12 files changed, 71 insertions(+), 2126 deletions(-) delete mode 100644 dist/dist.css.map diff --git a/app/components/AuthEntry.js b/app/components/AuthEntry.js index d4eda79..2b0c904 100644 --- a/app/components/AuthEntry.js +++ b/app/components/AuthEntry.js @@ -67,7 +67,7 @@ export default class AuthEntry extends React.Component { render() { const { service, account, notes } = this.props.entry; - const { id, onEdit, onRemove } = this.props; + const { id, onEdit, onRemove, canEdit } = this.props; const { token } = this.state; const timeLeft = this.getTimeLeft(); @@ -89,12 +89,14 @@ export default class AuthEntry extends React.Component { -
- -
+ {canEdit && ( +
+ +
+ )} {notes && (
@@ -112,5 +114,6 @@ AuthEntry.propTypes = { onEdit: PropTypes.func.isRequired, onRemove: PropTypes.func.isRequired, onEntryChange: PropTypes.func, - onCopyToken: PropTypes.func.isRequired + onCopyToken: PropTypes.func.isRequired, + canEdit: PropTypes.bool.isRequired }; diff --git a/app/components/Home.js b/app/components/Home.js index 56e2277..b03f56a 100644 --- a/app/components/Home.js +++ b/app/components/Home.js @@ -4,7 +4,7 @@ import EditEntry from '@Components/EditEntry'; import ViewEntries from '@Components/ViewEntries'; import ConfirmDialog from '@Components/ConfirmDialog'; import DataErrorAlert from '@Components/DataErrorAlert'; -import { EditorKit, EditorKitDelegate } from 'sn-editor-kit'; +import EditorKit from '@standardnotes/editor-kit'; const initialState = { text: '', @@ -13,7 +13,8 @@ const initialState = { editMode: false, editEntry: null, confirmRemove: false, - displayCopy: false + displayCopy: false, + canEdit: true }; export default class Home extends React.Component { @@ -24,7 +25,7 @@ export default class Home extends React.Component { } configureEditorKit() { - let delegate = new EditorKitDelegate({ + const delegate = { setEditorRawText: text => { let parseError = false; let entries = []; @@ -61,14 +62,20 @@ export default class Home extends React.Component { } }, clearUndoHistory: () => {}, - getElementsBySelector: () => [] - }); + getElementsBySelector: () => [], + onNoteLockToggle: (isLocked) => { + this.setState({ + canEdit: !isLocked + }); + } + }; - this.editorKit = new EditorKit({ - delegate: delegate, - mode: 'json', - supportsFilesafe: false - }); + this.editorKit = new EditorKit(delegate, + { + mode: 'json', + supportsFileSafe: false + } + ); } saveNote(entries) { @@ -117,6 +124,9 @@ export default class Home extends React.Component { // Event Handlers onAddNew = () => { + if (!this.state.canEdit) { + return; + } this.setState({ editMode: true, editEntry: null @@ -124,6 +134,9 @@ export default class Home extends React.Component { }; onEdit = id => { + if (!this.state.canEdit) { + return; + } this.setState(state => ({ editMode: true, editEntry: { @@ -142,6 +155,9 @@ export default class Home extends React.Component { }; onRemove = id => { + if (!this.state.canEdit) { + return; + } this.setState(state => ({ confirmRemove: true, editEntry: { @@ -177,11 +193,13 @@ export default class Home extends React.Component { render() { const editEntry = this.state.editEntry || {}; + const { canEdit, displayCopy, parseError, editMode, entries, confirmRemove } = this.state; + return (
@@ -190,17 +208,17 @@ export default class Home extends React.Component {
- {this.state.parseError && } -