Skip to content

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

allow on the fly note updating in editor

ammarahm-ed4325b4ea8197
diff --git a/apps/mobile/AppRootEvents.js b/apps/mobile/AppRootEvents.js
index 20b5e066d..4e0c8d5f8 100644
--- a/apps/mobile/AppRootEvents.js
+++ b/apps/mobile/AppRootEvents.js
@@ -42,7 +42,7 @@ import {
import {MMKV} from './src/utils/mmkv';
import Storage from './src/utils/storage';
import {sleep} from './src/utils/TimeUtils';
-import {getNote, getWebviewInit} from './src/views/Editor/Functions';
+import {getNote, getWebviewInit, updateNoteInEditor} from './src/views/Editor/Functions';
let prevTransactionId = null;
let subsriptionSuccessListener;
@@ -200,6 +200,9 @@ export const AppRootEvents = React.memo(
const onSyncComplete = async () => {
initialize();
+ if (getNote()) {
+ //updateNoteInEditor();
+ }
setLastSynced(await db.lastSynced());
};
diff --git a/apps/mobile/babel.config.js b/apps/mobile/babel.config.js
index fe43b23c6..0e9529664 100644
--- a/apps/mobile/babel.config.js
+++ b/apps/mobile/babel.config.js
@@ -1,6 +1,6 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
- "transform-remove-console"
+ //"transform-remove-console"
]
};
diff --git a/apps/mobile/src/components/MergeEditor/index.js b/apps/mobile/src/components/MergeEditor/index.js
index 5e18f693c..ae72912c7 100644
--- a/apps/mobile/src/components/MergeEditor/index.js
+++ b/apps/mobile/src/components/MergeEditor/index.js
@@ -35,6 +35,7 @@ import diff from '../../utils/differ';
import {openLinkInBrowser} from '../../utils/functions';
import Sync from '../../services/Sync';
import Navigation from '../../services/Navigation';
+import { getNote, updateNoteInEditor } from '../../views/Editor/Functions';
const {Value, timing} = Animated;
@@ -250,6 +251,9 @@ const MergeEditor = () => {
Navigation.routeNames.Favorites,
Navigation.routeNames.Notes,
]);
+ if (getNote()?.id === note.id) {
+ updateNoteInEditor();
+ }
close();
await Sync.run();
};
diff --git a/apps/mobile/src/components/Premium/PremiumComponent.js b/apps/mobile/src/components/Premium/PremiumComponent.js
index af65fd63e..2a9664921 100644
--- a/apps/mobile/src/components/Premium/PremiumComponent.js
+++ b/apps/mobile/src/components/Premium/PremiumComponent.js
@@ -129,7 +129,7 @@ export const PremiumComponent = ({close, promo}) => {
p => p.productId === 'com.streetwriters.notesnook.sub.yr',
),
};
- console.log(products.length);
+ console.log(products.map(p => p.productId));
setOffers(offers);
if (promo?.promoCode) {
diff --git a/apps/mobile/src/components/SimpleList/announcement.js b/apps/mobile/src/components/SimpleList/announcement.js
index c7eb4e276..be81c0782 100644
--- a/apps/mobile/src/components/SimpleList/announcement.js
+++ b/apps/mobile/src/components/SimpleList/announcement.js
@@ -22,6 +22,9 @@ export const Announcement = () => {
const remove = useMessageStore(state => state.remove);
let announcement = announcements.length > 0 ? announcements[0] : null;
const selectionMode = useSelectionStore(state => state.selectionMode);
+
+ console.log(announcement,'announcement');
+
return !announcement || selectionMode ? null : (
<View
style={{
diff --git a/apps/mobile/src/components/SimpleList/header.js b/apps/mobile/src/components/SimpleList/header.js
index 86a102736..374f0ada3 100644
--- a/apps/mobile/src/components/SimpleList/header.js
+++ b/apps/mobile/src/components/SimpleList/header.js
@@ -31,7 +31,7 @@ export const Header = React.memo(
const announcements = useMessageStore(state => state.announcements)
const deviceMode = useSettingStore(state => state.deviceMode)
-
+ console.log(announcements)
return announcements.length > 0 && !noAnnouncement ? (
<Announcement color={color || colors.accent} />
) : type === 'search' ? null : deviceMode !== "mobile" && !shouldShow ? (
diff --git a/apps/mobile/src/provider/stores.ts b/apps/mobile/src/provider/stores.ts
index 229ee973d..d84832c76 100644
--- a/apps/mobile/src/provider/stores.ts
+++ b/apps/mobile/src/provider/stores.ts
@@ -318,10 +318,12 @@ async function shouldShowAnnouncement(announcement) {
let show = announcement.platforms.some(
(platform) => allowedPlatforms.indexOf(platform) > -1
);
+ console.log("show",show)
if (!show) return false;
const subStatus = PremiumService.getUser()?.subscription?.type;
show = announcement.userTypes.some((userType) => {
+ console.log(userType,subStatus);
switch (userType) {
case "pro":
return PremiumService.get()
diff --git a/apps/mobile/src/services/PremiumService.js b/apps/mobile/src/services/PremiumService.js
index 6dcc3c6e0..cd5c772fb 100644
--- a/apps/mobile/src/services/PremiumService.js
+++ b/apps/mobile/src/services/PremiumService.js
@@ -1,6 +1,6 @@
import {CHECK_IDS} from 'notes-core/common';
import * as RNIap from 'react-native-iap';
-import {useUserStore} from '../provider/stores';
+import {useMessageStore, useUserStore} from '../provider/stores';
import {itemSkus, SUBSCRIPTION_STATUS} from '../utils';
import {db} from '../utils/DB';
import {
@@ -34,6 +34,7 @@ async function setPremiumStatus() {
} catch (e) {
premiumStatus = 0;
} finally {
+ useMessageStore.getState().setAnnouncement();
if (!get()) {
await RNIap.initConnection();
products = await RNIap.getSubscriptions(itemSkus);
@@ -46,6 +47,7 @@ function getProducts() {
}
function get() {
+ console.log(premiumStatus, 'pro status');
return SUBSCRIPTION_STATUS.BASIC !== premiumStatus;
}
diff --git a/apps/mobile/src/utils/index.js b/apps/mobile/src/utils/index.js
index 18481fc2e..7f6218022 100755
--- a/apps/mobile/src/utils/index.js
+++ b/apps/mobile/src/utils/index.js
@@ -243,6 +243,7 @@ export const itemSkus = [
'com.streetwriters.notesnook.sub.yr.15',
'com.streetwriters.notesnook.sub.mo.15',
'com.streetwriters.notesnook.sub.mo.ofr',
+ 'com.streetwriters.notesnook.sub.yr.ofr',
];
export const MenuItemsList = [
diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.js
index c5ff53ecf..c77aeac22 100644
--- a/apps/mobile/src/views/Editor/Functions.js
+++ b/apps/mobile/src/views/Editor/Functions.js
@@ -1,20 +1,25 @@
-import { createRef } from 'react';
-import { Platform } from 'react-native';
-import { useEditorStore, useMenuStore } from '../../provider/stores';
-import { DDS } from '../../services/DeviceDetection';
-import { eSendEvent } from '../../services/EventManager';
+import {createRef} from 'react';
+import {Platform} from 'react-native';
+import {presentDialog} from '../../components/Dialog/functions';
+import {useEditorStore, useMenuStore} from '../../provider/stores';
+import {DDS} from '../../services/DeviceDetection';
+import {eSendEvent} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import PremiumService from '../../services/PremiumService';
-import { editing, InteractionManager } from '../../utils';
-import { COLORS_NOTE, COLOR_SCHEME } from '../../utils/Colors';
-import { hexToRGBA } from '../../utils/ColorUtils';
-import { db } from '../../utils/DB';
-import { eOnLoadNote, eShowGetPremium } from '../../utils/Events';
-import { openLinkInBrowser } from '../../utils/functions';
-import { MMKV } from '../../utils/mmkv';
-import { tabBarRef } from '../../utils/Refs';
-import { normalize } from '../../utils/SizeUtils';
-import { sleep, timeConverter } from '../../utils/TimeUtils';
+import {editing, InteractionManager} from '../../utils';
+import {COLORS_NOTE, COLOR_SCHEME} from '../../utils/Colors';
+import {hexToRGBA} from '../../utils/ColorUtils';
+import {db} from '../../utils/DB';
+import {
+ eOnLoadNote,
+ eShowGetPremium,
+ eShowMergeDialog,
+} from '../../utils/Events';
+import {openLinkInBrowser} from '../../utils/functions';
+import {MMKV} from '../../utils/mmkv';
+import {tabBarRef} from '../../utils/Refs';
+import {normalize} from '../../utils/SizeUtils';
+import {sleep, timeConverter} from '../../utils/TimeUtils';
import tiny from './tiny/tiny';
export let EditorWebView = createRef();
@@ -314,7 +319,7 @@ export const _onMessage = async evt => {
eSendEvent('showTooltip');
break;
}
- showImageOptionsTooltip()
+ showImageOptionsTooltip();
break;
case 'focus':
editing.focusType = message.value;
@@ -404,8 +409,7 @@ export async function clearEditor() {
(content?.data &&
typeof content.data == 'string' &&
content.data?.trim().length > 0) ||
- (title && title?.trim().length > 0) &&
- id
+ (title && title?.trim().length > 0 && id)
) {
await saveNote(true);
}
@@ -488,15 +492,23 @@ async function addToCollection(id) {
let isSaving = false;
export async function saveNote(preventUpdate) {
- if (isSaving && !id) return;
+ console.log('saving note now');
+ if (isSaving && !id) return;
isSaving = true;
try {
if (id && !db.notes.note(id)) {
clearNote();
return;
}
-
- let locked = id ? db.notes.note(id).data.locked : null;
+ let locked = false;
+ if (id) {
+ let _note = db.notes.note(id).data;
+ if (_note.conflicted) {
+ presentResolveConflictDialog(_note)
+ return;
+ }
+ locked = _note.locked;
+ }
let noteData = {
title,
@@ -583,6 +595,30 @@ async function restoreEditorState() {
editing.isRestoringState = false;
}
+const presentResolveConflictDialog = (_note) => {
+ presentDialog({
+ title: 'Changes not saved',
+ paragraph: 'Please resolve conflicts to save changes',
+ positiveText: 'Resolve',
+ positivePress: () => {
+ eSendEvent(eShowMergeDialog, _note);
+ },
+ });
+}
+
+export async function updateNoteInEditor() {
+ console.log('updating note in editor')
+ let _note = db.notes.note(id).data;
+ if (_note.conflicted) {
+ presentResolveConflictDialog(_note)
+ return;
+ }
+ tiny.call(EditorWebView, tiny.isLoading);
+ await setNote(_note);
+ await loadNoteInEditor();
+ console.log('updated note in editor');
+}
+
const loadNoteInEditor = async () => {
if (!webviewInit) return;
saveCounter = 0;
diff --git a/apps/mobile/src/views/Trash/index.js b/apps/mobile/src/views/Trash/index.js
index 68dbba3da..846e78722 100644
--- a/apps/mobile/src/views/Trash/index.js
+++ b/apps/mobile/src/views/Trash/index.js
@@ -6,11 +6,12 @@ import { Header } from '../../components/Header';
import { Placeholder } from '../../components/ListPlaceholders';
import SelectionHeader from '../../components/SelectionHeader';
import SimpleList from '../../components/SimpleList';
-import { useTrashStore } from '../../provider/stores';
-import { eSendEvent } from '../../services/EventManager';
+import { useSelectionStore, useTrashStore } from '../../provider/stores';
+import { eSendEvent, ToastEvent } from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import SearchService from '../../services/SearchService';
import { InteractionManager } from '../../utils';
+import { db } from '../../utils/DB';
import { eScrollEvent } from '../../utils/Events';
export const Trash = ({route, navigation}) => {