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: readonly mode
ammarahm-edefbc011ad96d
diff --git a/apps/mobile/src/components/NoteItem/wrapper.js b/apps/mobile/src/components/NoteItem/wrapper.jsindex c1c2522af..7e4b925da 100644--- a/apps/mobile/src/components/NoteItem/wrapper.js+++ b/apps/mobile/src/components/NoteItem/wrapper.js@@ -1,7 +1,7 @@import React from 'react';import NoteItem from '.';import { notesnook } from '../../../e2e/test.ids';-import { useSelectionStore, useTrashStore } from '../../provider/stores';+import { useEditorStore, useSelectionStore, useTrashStore } from '../../provider/stores';import { DDS } from '../../services/DeviceDetection';import { eSendEvent, openVault, ToastEvent } from '../../services/EventManager';import Navigation from '../../services/Navigation';@@ -79,6 +79,7 @@ export const NoteWrapper = React.memo(}});} else {+ useEditorStore.getState().setReadonly(_note?.readonly);eSendEvent(eOnLoadNote, _note);if (!DDS.isTab) {tabBarRef.current?.goToPage(1);diff --git a/apps/mobile/src/components/Properties/index.js b/apps/mobile/src/components/Properties/index.jsindex c7da2e118..4dcf06119 100644--- a/apps/mobile/src/components/Properties/index.js+++ b/apps/mobile/src/components/Properties/index.js@@ -129,6 +129,7 @@ Properties.present = (item, buttons = []) => {break;case 'note':android = Platform.OS === 'android' ? ['PinToNotif'] : [];+ item = db.notes.note(item.id).data;props.push(['Add to notebook','Share',@@ -148,12 +149,15 @@ Properties.present = (item, buttons = []) => {]);break;case 'notebook':+ item = db.notebooks.notebook(item.id).data;props.push(['Edit Notebook', 'Pin', 'Add Shortcut', 'Delete']);break;case 'topic':+ item = db.notebooks.notebook(item.notebookId).topics.topic(item.id)._topic;props.push(['Move notes', 'Edit Topic', 'Add Shortcut', 'Delete']);break;case 'tag':+ item = db.tags.tag(item.id);props.push(['Add Shortcut', 'Delete', 'Rename Tag']);break;}diff --git a/apps/mobile/src/components/Properties/useActions.js b/apps/mobile/src/components/Properties/useActions.jsindex 0eead6f29..80bc5fed1 100644--- a/apps/mobile/src/components/Properties/useActions.js+++ b/apps/mobile/src/components/Properties/useActions.js@@ -5,7 +5,13 @@ import Share from 'react-native-share';import { notesnook } from '../../../e2e/test.ids';import { useTracked } from '../../provider';import { Actions } from '../../provider/Actions';-import { useMenuStore, useSelectionStore, useTagStore, useUserStore } from '../../provider/stores';+import {+ useEditorStore,+ useMenuStore,+ useSelectionStore,+ useTagStore,+ useUserStore+} from '../../provider/stores';import {eSendEvent,eSubscribeEvent,@@ -59,7 +65,7 @@ export const useActions = ({ close = () => {}, item }) => {: item.type === 'color'? db.colors.alias(item.id): item.title;-+ console.log(item);const isPublished = item.type === 'note' && db.monographs.isPublished(item.id);const noteInTopic =item.type === 'note' &&@@ -470,7 +476,16 @@ export const useActions = ({ close = () => {}, item }) => {eSendEvent(eOpenExportDialog, [item]);}- const toggleReadyOnlyMode = async () => {};+ const toggleReadyOnlyMode = async () => {+ await db.notes.note(item.id).readonly();+ useEditorStore.getState().setReadonly(db.notes.note(item.id).data.readonly);+ Navigation.setRoutesToUpdate([+ Navigation.routeNames.NotesPage,+ Navigation.routeNames.Favorites,+ Navigation.routeNames.Notes+ ]);+ close();+ };const actions = [{diff --git a/apps/mobile/src/provider/interfaces.ts b/apps/mobile/src/provider/interfaces.tsindex b8d15d7d8..705415721 100644--- a/apps/mobile/src/provider/interfaces.ts+++ b/apps/mobile/src/provider/interfaces.ts@@ -110,6 +110,8 @@ export interface EditorStore extends State {searchReplace: boolean;setSearchReplace: (searchReplace: boolean) => void;searchSelection: string | null;+ readonly: boolean;+ setReadonly: (readonly: boolean) => void;}export interface SearchStore extends State {diff --git a/apps/mobile/src/provider/stores.ts b/apps/mobile/src/provider/stores.tsindex 91f09f06e..bcf2ec339 100644--- a/apps/mobile/src/provider/stores.ts+++ b/apps/mobile/src/provider/stores.ts@@ -288,6 +288,10 @@ export const useEditorStore = create<EditorStore>((set, get) => ({},searchReplace: false,searchSelection: null,+ readonly: false,+ setReadonly: readonly => {+ set({ readonly: readonly });+ },setSearchReplace: searchReplace => {if (!searchReplace) {set({ searchSelection: null, searchReplace: false });diff --git a/apps/mobile/src/views/Editor/EditorHeader.js b/apps/mobile/src/views/Editor/EditorHeader.jsindex 57d5600ff..775463764 100644--- a/apps/mobile/src/views/Editor/EditorHeader.js+++ b/apps/mobile/src/views/Editor/EditorHeader.js@@ -57,6 +57,7 @@ const EditorHeader = () => {const closing = useRef(false);const editorTags = useEditorTags();const searchReplace = useEditorStore(state => state.searchReplace);+ const readonly = useEditorStore(state => state.readonly);useEffect(() => {setColors(colors);@@ -341,7 +342,7 @@ const EditorHeader = () => {}}/>- {currentlyEditingNote && (+ {currentlyEditingNote && !readonly && (<ActionIconname="cloud-upload-outline"color={colors.pri}@@ -353,15 +354,17 @@ const EditorHeader = () => {/>)}- <ActionIcon- name="attachment"- color={colors.pri}- customStyle={{- marginLeft: 5- }}- top={50}- onPress={picker.pick}- />+ {!readonly && (+ <ActionIcon+ name="attachment"+ color={colors.pri}+ customStyle={{+ marginLeft: 5+ }}+ top={50}+ onPress={picker.pick}+ />+ )}{deviceMode !== 'mobile' && !fullscreen ? (<ActionIcondiff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.jsindex f8624d0c1..078b52114 100644--- a/apps/mobile/src/views/Editor/Functions.js+++ b/apps/mobile/src/views/Editor/Functions.js@@ -152,6 +152,10 @@ export function getNote() {return note;}+export function setReadOnly(readonly) {+ note.readonly = readonly;+}+export function setNoteOnly(n) {note = n;}@@ -270,6 +274,7 @@ export const loadNote = async item => {clearNote();eSendEvent('loadingNote');eSendEvent('updateTags');+ useEditorStore.getState().setReadonly(false);closingSession = false;disableSaving = false;lastEditTime = 0;@@ -328,7 +333,7 @@ export const loadNote = async item => {noteEdited = false;webviewInit = false;editing.isFocused = false;-+ useEditorStore.getState().setReadonly(item.readonly);await setNote(item);if (loading_queue && (loading_queue?.id !== item?.id || loading_queue?.type === 'new')) {clearNote();diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/index.js b/apps/mobile/src/views/Editor/tiny/toolbar/index.jsindex 6b892022f..508ce2730 100644--- a/apps/mobile/src/views/Editor/tiny/toolbar/index.js+++ b/apps/mobile/src/views/Editor/tiny/toolbar/index.js@@ -1,15 +1,16 @@-import React, { useEffect } from 'react';+import React, { useEffect, useState } from 'react';import { ScrollView, View } from 'react-native';import { ActionIcon } from '../../../../components/ActionIcon';import { useTracked } from '../../../../provider';import { useEditorStore } from '../../../../provider/stores';import { getElevation } from '../../../../utils';+import { db } from '../../../../utils/database';import { normalize } from '../../../../utils/SizeUtils';-import { EditorWebView, getNote } from '../../Functions';+import { EditorWebView, getNote, setNoteOnly } from '../../Functions';import HistoryComponent from '../../HistoryComponent';import tiny from '../tiny';import { TOOLBAR_CONFIG } from './config';-import { properties, toolbarRef } from './constants';+import { focusEditor, properties, reFocusEditor, toolbarRef } from './constants';import ToolbarGroup from './group';import SearcReplace from './searchreplace';import Tooltip from './tooltip';@@ -20,7 +21,8 @@ const EditorToolbar = React.memo(const { colors } = state;const config = TOOLBAR_CONFIG;const searchReplace = useEditorStore(state => state.searchReplace);- const currentEditingNote = useEditorStore(state => state.currentEditingNote);+ const readonly = useEditorStore(state => state.readonly);+ const setReadonly = useEditorStore(state => state.setReadonly);useEffect(() => {properties.selection = {};@@ -29,9 +31,13 @@ const EditorToolbar = React.memo(};}, []);- const onPress = () => {- // todo- tiny.call(EditorWebView, tiny.toogleReadMode('design'));+ const onPress = async () => {+ if (getNote()) {+ await db.notes.note(getNote().id).readonly();+ setNoteOnly(db.notes.note(getNote().id).data);+ tiny.call(EditorWebView, tiny.toogleReadMode('design'));+ setReadonly(false);+ }};return (@@ -43,7 +49,7 @@ const EditorToolbar = React.memo(position: 'relative'}}>- {currentEditingNote && getNote()?.readonly ? (+ {readonly ? (<ActionIconname="pencil-lock"type="grayBg"diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.jsindex 28e371f53..30ea0b561 100755--- a/apps/mobile/src/views/Home/index.js+++ b/apps/mobile/src/views/Home/index.js@@ -1,6 +1,6 @@import React, { useCallback, useEffect } from 'react';import { StatusBar } from 'react-native-bars';-import { ChangePassword } from '../../components/LoginDialog/change-password';+import { ChangePassword } from '../../components/Auth/change-password';import { ContainerBottomButton } from '../../components/Container/ContainerBottomButton';import { ContainerTopSection } from '../../components/Container/ContainerTopSection';import { Header } from '../../components/Header/index';diff --git a/apps/mobile/src/views/Settings/usersection.js b/apps/mobile/src/views/Settings/usersection.jsindex b42ad9965..3668c3060 100644--- a/apps/mobile/src/views/Settings/usersection.js+++ b/apps/mobile/src/views/Settings/usersection.js@@ -3,7 +3,7 @@ import React from 'react';import { Linking, Platform, View } from 'react-native';import * as RNIap from 'react-native-iap';import Icon from 'react-native-vector-icons/MaterialCommunityIcons';-import { ChangePassword } from '../../components/LoginDialog/change-password';+import { ChangePassword } from '../../components/Auth/change-password';import { Button } from '../../components/Button';import Seperator from '../../components/Seperator';import Heading from '../../components/Typography/Heading';