Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: readonly mode

ammarahm-ed4b2de44c2886
diff --git a/apps/mobile/html/Web.bundle/site/listeners.js b/apps/mobile/html/Web.bundle/site/listeners.js
index cdb3b254d..f9c1c7492 100755
--- a/apps/mobile/html/Web.bundle/site/listeners.js
+++ b/apps/mobile/html/Web.bundle/site/listeners.js
@@ -38,19 +38,17 @@ function attachTitleInputListeners() {
}
};
- document
- .getElementById('titleInput')
- .addEventListener('focus', function (evt) {
- if (window.ReactNativeWebView) {
- window.ReactNativeWebView.postMessage(
- JSON.stringify({
- type: 'focus',
- value: 'title',
- sessionId: sessionId
- })
- );
- }
- });
+ document.getElementById('titleInput').addEventListener('focus', function (evt) {
+ if (window.ReactNativeWebView) {
+ window.ReactNativeWebView.postMessage(
+ JSON.stringify({
+ type: 'focus',
+ value: 'title',
+ sessionId: sessionId
+ })
+ );
+ }
+ });
document.getElementById('titleInput').onpaste = function (evt) {
onTitleChange();
};
@@ -76,8 +74,7 @@ function onTitleChange() {
info = document.querySelector(infoBar);
if (tinymce.activeEditor) {
- info.querySelector('#infowords').innerText =
- editor.countWords() + ' words';
+ info.querySelector('#infowords').innerText = editor.countWords() + ' words';
updateInfoBar();
}
@@ -156,12 +153,13 @@ function attachMessageListener() {
isLoading = true;
globalThis.isClearingNoteData = false;
tinymce.activeEditor.mode.set('readonly');
- if (!isInvalidValue(value)) {
- tinymce.activeEditor.setHTML(value);
+ let html = value.data;
+ if (!isInvalidValue(html)) {
+ tinymce.activeEditor.setHTML(html);
let timeout = 0;
if (value.length > 400000) {
timeout = 900;
- }else if (value.length > 300000) {
+ } else if (value.length > 300000) {
timeout = 600;
} else if (value.length > 200000) {
timeout = 450;
@@ -181,17 +179,16 @@ function attachMessageListener() {
globalThis.isClearingNoteData = false;
reactNativeEventHandler('noteLoaded', true);
}
- tinymce.activeEditor.mode.set('design');
+ if (!value.readOnly) {
+ tinymce.activeEditor.mode.set('design');
+ }
info = document.querySelector(infoBar);
- info.querySelector('#infowords').innerText =
- editor.countWords() + ' words';
+ info.querySelector('#infowords').innerText = editor.countWords() + ' words';
updateInfoBar();
break;
case 'htmldiff':
document.getElementsByClassName('htmldiff_div')[0].innerHTML = value;
- document
- .querySelector('.htmldiff_div')
- .setAttribute('contenteditable', 'false');
+ document.querySelector('.htmldiff_div').setAttribute('contenteditable', 'false');
break;
case 'theme':
pageTheme.colors = JSON.parse(value);
diff --git a/apps/mobile/src/components/Properties/index.js b/apps/mobile/src/components/Properties/index.js
index d8b31628c..c7da2e118 100644
--- a/apps/mobile/src/components/Properties/index.js
+++ b/apps/mobile/src/components/Properties/index.js
@@ -142,6 +142,7 @@ Properties.present = (item, buttons = []) => {
'Delete',
'RemoveTopic',
'History',
+ 'ReadOnly',
...android,
...buttons
]);
diff --git a/apps/mobile/src/components/Properties/useActions.js b/apps/mobile/src/components/Properties/useActions.js
index bef9c27b2..cf0b32194 100644
--- a/apps/mobile/src/components/Properties/useActions.js
+++ b/apps/mobile/src/components/Properties/useActions.js
@@ -470,6 +470,8 @@ export const useActions = ({ close = () => {}, item }) => {
eSendEvent(eOpenExportDialog, [item]);
}
+ const toggleReadyOnlyMode = async () => {};
+
const actions = [
{
name: 'Dark Mode',
@@ -637,6 +639,13 @@ export const useActions = ({ close = () => {}, item }) => {
icon: 'delete',
func: deleteTrashItem
},
+ {
+ name: 'ReadOnly',
+ title: 'Read only',
+ icon: 'pencil-lock',
+ func: toggleReadyOnlyMode,
+ on: item.readonly
+ },
{
name: 'History',
title: 'History',
diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.js
index 569765b6e..300e4efa5 100644
--- a/apps/mobile/src/views/Editor/Functions.js
+++ b/apps/mobile/src/views/Editor/Functions.js
@@ -985,7 +985,10 @@ const loadNoteInEditor = async (keepHistory = true) => {
);
} else {
console.log('posting html');
- post('html', content.data);
+ post('html', {
+ data: content.data,
+ readOnly: note.readonly
+ });
}
if (id) {
db.attachments.downloadImages(id);
diff --git a/apps/mobile/src/views/Editor/tiny/tiny.js b/apps/mobile/src/views/Editor/tiny/tiny.js
index 6b199d921..bc391cfd2 100644
--- a/apps/mobile/src/views/Editor/tiny/tiny.js
+++ b/apps/mobile/src/views/Editor/tiny/tiny.js
@@ -2,7 +2,12 @@ import { Platform } from 'react-native';
import { editing } from '../../../utils';
import { EditorWebView, getWebviewInit, post, textInput } from '../Functions';
-const placeholders = ['hello world', 'this \n that'];
+/**
+ *
+ * @param {"design" | "readonly"} mode
+ * @returns
+ */
+const toogleReadMode = mode => `tinymce.activeEditor.mode.set('${mode}')`;
const reset = id => `
sessionId = null;
@@ -246,5 +251,6 @@ export default {
pre,
setMarkdown,
removeMarkdown,
- setPlaceholder
+ setPlaceholder,
+ toogleReadMode
};
diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/index.js b/apps/mobile/src/views/Editor/tiny/toolbar/index.js
index 65a9ca0c4..6b892022f 100644
--- a/apps/mobile/src/views/Editor/tiny/toolbar/index.js
+++ b/apps/mobile/src/views/Editor/tiny/toolbar/index.js
@@ -1,9 +1,13 @@
import React, { useEffect } 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 { normalize } from '../../../../utils/SizeUtils';
+import { EditorWebView, getNote } from '../../Functions';
import HistoryComponent from '../../HistoryComponent';
+import tiny from '../tiny';
import { TOOLBAR_CONFIG } from './config';
import { properties, toolbarRef } from './constants';
import ToolbarGroup from './group';
@@ -16,6 +20,7 @@ const EditorToolbar = React.memo(
const { colors } = state;
const config = TOOLBAR_CONFIG;
const searchReplace = useEditorStore(state => state.searchReplace);
+ const currentEditingNote = useEditorStore(state => state.currentEditingNote);
useEffect(() => {
properties.selection = {};
@@ -24,6 +29,11 @@ const EditorToolbar = React.memo(
};
}, []);
+ const onPress = () => {
+ // todo
+ tiny.call(EditorWebView, tiny.toogleReadMode('design'));
+ };
+
return (
<>
<View
@@ -33,47 +43,66 @@ const EditorToolbar = React.memo(
position: 'relative'
}}
>
- {searchReplace ? (
- <SearcReplace />
+ {currentEditingNote && getNote()?.readonly ? (
+ <ActionIcon
+ name="pencil-lock"
+ type="grayBg"
+ onPress={onPress}
+ color={colors.accent}
+ customStyle={{
+ position: 'absolute',
+ bottom: 20,
+ width: 60,
+ height: 60,
+ right: 12,
+ ...getElevation(5)
+ }}
+ />
) : (
<>
- <Tooltip />
- <ScrollView
- ref={toolbarRef}
- style={{
- width: '100%',
- maxWidth: '100%',
- minHeight: normalize(50),
- backgroundColor: colors.bg,
- paddingLeft: 6,
- zIndex: 11
- }}
- contentContainerStyle={{
- alignItems: 'center'
- }}
- keyboardShouldPersistTaps="always"
- keyboardDismissMode="none"
- horizontal={true}
- showsHorizontalScrollIndicator={false}
- showsVerticalScrollIndicator={false}
- bounces={false}
- >
- <HistoryComponent />
- {config.map((item, index) =>
- typeof item !== 'string' ? (
- <ToolbarGroup key={item[0].format} group={item} />
- ) : (
- <View
- style={{
- height: 30,
- width: 2,
- marginHorizontal: 2,
- backgroundColor: colors.nav
- }}
- />
- )
- )}
- </ScrollView>
+ {searchReplace ? (
+ <SearcReplace />
+ ) : (
+ <>
+ <Tooltip />
+ <ScrollView
+ ref={toolbarRef}
+ style={{
+ width: '100%',
+ maxWidth: '100%',
+ minHeight: normalize(50),
+ backgroundColor: colors.bg,
+ paddingLeft: 6,
+ zIndex: 11
+ }}
+ contentContainerStyle={{
+ alignItems: 'center'
+ }}
+ keyboardShouldPersistTaps="always"
+ keyboardDismissMode="none"
+ horizontal={true}
+ showsHorizontalScrollIndicator={false}
+ showsVerticalScrollIndicator={false}
+ bounces={false}
+ >
+ <HistoryComponent />
+ {config.map((item, index) =>
+ typeof item !== 'string' ? (
+ <ToolbarGroup key={item[0].format} group={item} />
+ ) : (
+ <View
+ style={{
+ height: 30,
+ width: 2,
+ marginHorizontal: 2,
+ backgroundColor: colors.nav
+ }}
+ />
+ )
+ )}
+ </ScrollView>
+ </>
+ )}
</>
)}
</View>
diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/searchreplace.js b/apps/mobile/src/views/Editor/tiny/toolbar/searchreplace.js
index 6aa88e94b..6c8f3ab66 100644
--- a/apps/mobile/src/views/Editor/tiny/toolbar/searchreplace.js
+++ b/apps/mobile/src/views/Editor/tiny/toolbar/searchreplace.js
@@ -10,7 +10,7 @@ import layoutmanager from '../../../../utils/layout-manager';
import { SIZE } from '../../../../utils/SizeUtils';
import { useKeyboard } from '../../../../utils/use-keyboard';
import useTooltip, { hideAllTooltips, useTooltipHandler } from '../../../../utils/use-tooltip';
-import { EditorWebView } from '../../Functions';
+import { EditorWebView, getNote } from '../../Functions';
import tiny from '../tiny';
import { endSearch } from './commands';
import { properties } from './constants';
@@ -215,6 +215,7 @@ const SearcReplace = () => {
fwdRef={switchModeRef}
iconColor={enableReplace ? colors.accent : colors.icon}
onPress={() => {
+ if (getNote()?.readonly) return;
layoutmanager.withSpringAnimation(500);
if (enableReplace) {
if (focusType === 2) {