A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
feat: add note edit locking (#205)
Muhammad Ali5397f6abcfa4
diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.jsindex f1be274bd..3b4a25e8d 100644--- a/apps/web/src/components/editor/index.js+++ b/apps/web/src/components/editor/index.js@@ -45,6 +45,7 @@ function Editor({ noteId, nonce }) {const [isEditorLoading, setIsEditorLoading] = useState(true);const sessionId = useStore((store) => store.session.id);const sessionState = useStore((store) => store.session.state);+ const isPreviewMode = useStore((store) => store.session.previewMode);const isReadonly = useStore((store) => store.session.readonly);const contentId = useStore((store) => store.session.contentId);const contentType = useStore((store) => store.session.content?.type);@@ -149,14 +150,24 @@ function Editor({ noteId, nonce }) {useEffect(function openPreviewSession() {- if (!isReadonly || sessionState !== SESSION_STATES.new) return;+ if (!isPreviewMode || sessionState !== SESSION_STATES.new) return;setContent();enabledPreviewMode();},- [isReadonly, sessionState, setContent, enabledPreviewMode]+ [isPreviewMode, sessionState, setContent, enabledPreviewMode]);+ useEffect(() => {+ const editor = editorRef.current?.editor;+ if (editor)+ if (isReadonly) {+ editor.mode.set("readonly");+ } else {+ editor.mode.set("design");+ }+ }, [isReadonly]);+useEffect(function newSession() {if (!nonce) return;@@ -215,7 +226,7 @@ function Editor({ noteId, nonce }) {py: 1,}}/>- {isReadonly && (+ {isPreviewMode && (<Noticetitle={"Readonly mode"}subtitle={`You are previewing note version edited from ${formatDate(@@ -246,7 +257,7 @@ function Editor({ noteId, nonce }) {px={[2, 2, 35]}mt={[2, 2, 25]}>- <Header readonly={isReadonly} />+ <Header readonly={isPreviewMode || isReadonly} />{isSessionReady && (<Suspense fallback={<div />}>diff --git a/apps/web/src/components/icons/index.js b/apps/web/src/components/icons/index.jsindex 8834accc3..90f662d97 100644--- a/apps/web/src/components/icons/index.js+++ b/apps/web/src/components/icons/index.js@@ -126,6 +126,7 @@ import {mdiLinkVariantOff,mdiNetworkOffOutline,mdiCheckNetworkOutline,+ mdiPencilLockOutline,mdiSort,mdiOrderAlphabeticalAscending,mdiOrderAlphabeticalDescending,@@ -330,6 +331,7 @@ export const ShortcutLink = createIcon(mdiLinkVariant);export const RemoveShortcutLink = createIcon(mdiLinkVariantOff);export const Offline = createIcon(mdiNetworkOffOutline);export const Online = createIcon(mdiCheckNetworkOutline);+export const Readonly = createIcon(mdiPencilLockOutline);export const SortBy = createIcon(mdiSort);export const GroupBy = createIcon(mdiSelectGroup);diff --git a/apps/web/src/components/properties/index.js b/apps/web/src/components/properties/index.jsindex d4085947d..b162b63b0 100644--- a/apps/web/src/components/properties/index.js+++ b/apps/web/src/components/properties/index.js@@ -25,6 +25,7 @@ const tools = [label: "Favorite",},{ key: "locked", icon: Icon.Unlock, label: "Lock" },+ { key: "readonly", icon: Icon.Readonly, label: "Readonly" },];const metadataItems = [@@ -45,6 +46,7 @@ function Properties() {const [versionHistory, setVersionHistory] = useState([]);const toggleLocked = useStore((store) => store.toggleLocked);+ const toggleReadonly = useStore((store) => store.toggleReadonly);const setSession = useStore((store) => store.setSession);const openPreviewSession = useStore((store) => store.openPreviewSession);const setColor = useStore((store) => store.setColor);@@ -57,7 +59,7 @@ function Properties() {color,notebooks,attachments,- readonly: isReadonly,+ previewMode: isPreviewMode,} = session;const changeState = useCallback(@@ -66,9 +68,14 @@ function Properties() {toggleLocked();return;}+setSession((state) => {state.session[prop] = value;});++ if (prop === "readonly") {+ toggleReadonly();+ }},[setSession, toggleLocked]);@@ -149,7 +156,7 @@ function Properties() {/>}>- {!isReadonly && (+ {!isPreviewMode && (<>{tools.map((tool, _) => (<Toggle@@ -181,7 +188,7 @@ function Properties() {</Text></Flex>))}- {!isReadonly && (+ {!isPreviewMode && (<><Flexpy={2}diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.jsindex 4476eac45..251921180 100644--- a/apps/web/src/stores/editor-store.js+++ b/apps/web/src/stores/editor-store.js@@ -19,6 +19,7 @@ const SESSION_STATES = {const getDefaultSession = (sessionId = Date.now()) => {return {+ previewMode: false,readonly: false,state: undefined,saveState: 1, // -1 = not saved, 0 = saving, 1 = saved@@ -94,7 +95,7 @@ class EditorStore extends BaseStore {state.session.sessionId = undefined;state.session.dateCreated = dateCreated;state.session.dateEdited = dateEdited;- state.session.readonly = true;+ state.session.previewMode = true;state.session.state = SESSION_STATES.new;});};@@ -105,7 +106,7 @@ class EditorStore extends BaseStore {state.session.sessionId = newSession.sessionId;state.session.dateCreated = newSession.dateCreated;state.session.dateEdited = newSession.dateEdited;- state.session.readonly = false;+ state.session.previewMode = false;state.session.state = SESSION_STATES.stale;delete state.session.oldContent;@@ -274,6 +275,10 @@ class EditorStore extends BaseStore {else noteStore.lock(this.get().session.id);};+ toggleReadonly = () => {+ noteStore.readonly(this.get().session.id);+ };+setColor = (color) => {//this._setTagOrColor("color", color);return noteStore.setColor(this.get().session.id, color);diff --git a/apps/web/src/stores/note-store.js b/apps/web/src/stores/note-store.jsindex 00c47b788..47c2ded8f 100644--- a/apps/web/src/stores/note-store.js+++ b/apps/web/src/stores/note-store.js@@ -115,6 +115,12 @@ class NoteStore extends BaseStore {await editorStore.openSession(id, true);};+ readonly = async (id) => {+ const note = db.notes.note(id)+ await note.readonly();+ this.refresh();+ }+setColor = async (id, color) => {try {let note = db.notes.note(id);