From f0b3a41f6b6ab6e729f341bb52fb9a093712e697 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Tue, 14 Dec 2021 11:09:54 +0500 Subject: [PATCH 1/3] add session history saving --- apps/mobile/src/views/Editor/Functions.js | 49 +++++++++++++++++++---- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.js index b8b3218a3..7b1fa897a 100644 --- a/apps/mobile/src/views/Editor/Functions.js +++ b/apps/mobile/src/views/Editor/Functions.js @@ -60,6 +60,7 @@ let waitForContent = false; let prevNoteContent = null; let timerForEditor = null; let sessionId = null; +let historySessionId = null; export function startClosingSession() { closingSession = true; @@ -118,7 +119,7 @@ export async function clearTimer(clear) { }); } waitForContent = false; - console.log("cleared timer & saving note",content.data); + console.log('cleared timer & saving note', content.data); if (clear) { if (!noteEdited) return; if ( @@ -228,6 +229,7 @@ function clearNote() { note = null; title = ''; noteEdited = false; + historySessionId = null; prevNoteContent = content.data; id = null; content = { @@ -401,7 +403,15 @@ function updateSessionStatus() { } function isContentInvalid(content) { - return !content || content === '' || content.trim() === "" || content === '

' || content === '


' || content === '

 

' || content === `


` + return ( + !content || + content === '' || + content.trim() === '' || + content === '

' || + content === '


' || + content === '

 

' || + content === `


` + ); } function check_session_status() { @@ -446,7 +456,7 @@ export const _onMessage = async evt => { if (message.sessionId !== sessionId) return; console.log('noteedited'); noteEdited = true; - break; + break; case 'tiny': if (message.sessionId !== sessionId) return; if (message.value === '
') return; @@ -542,7 +552,7 @@ export const _onMessage = async evt => { return; } if (!id) return; - console.log('content not loaded',content.data); + console.log('content not loaded', content.data); if (message.value) { console.log('reloading'); await loadNoteInEditor(); @@ -712,7 +722,7 @@ export async function saveNote(preventUpdate) { if (disableSaving || !noteEdited || (isSaving && !id)) return; if (preventUpdate) { noteEdited = false; - }; + } isSaving = true; try { @@ -731,7 +741,7 @@ export async function saveNote(preventUpdate) { locked = _note.locked; } - console.log('note saved',preventUpdate,closingSession); + console.log('note saved', preventUpdate, closingSession); let noteData = { title, @@ -762,7 +772,6 @@ export async function saveNote(preventUpdate) { await setNoteInEditorAfterSaving(id, noteId); saveCounter++; } - } else { noteData.contentId = note.contentId; await db.vault.save(noteData); @@ -781,10 +790,36 @@ export async function saveNote(preventUpdate) { ); tiny.call(EditorWebView, tiny.updateSavingState(!n ? '' : 'Saved')); } + + await updateSessionHistory(id, noteData.content); } catch (e) {} isSaving = false; } +async function updateSessionHistory(id, content) { + let note = db.notes.note(id)?.data; + if (!note) return; + if (!historySessionId) { + historySessionId = `${id}_${note.dateEdited}`; + } + + if (!historySessionId.includes(id)) { + historySessionId = null; + return; + } + if (!note.locked) { + console.log('saving session with id: ',historySessionId); + await db.noteHistory.add(id, historySessionId, content); + } else { + let content = await db.content.get(note.contentId); + + await db.noteHistory.add(id, historySessionId, { + data: content.data, + type: content.type + }); + } +} + export async function onWebViewLoad(premium, colors) { setTimeout(() => { if (premium) { From c72acbd989fda81b6393500ec610d1363dc730c0 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Tue, 14 Dec 2021 12:33:39 +0500 Subject: [PATCH 2/3] feat: note history --- .../app/src/main/assets/plaineditor.html | 1 + .../html/Web.bundle/site/plaineditor.html | 1 + .../components/ActionSheetComponent/index.js | 86 ++++++++----- .../src/components/GeneralSheet/index.js | 5 +- .../src/components/NoteHistory/index.js | 97 ++++++++++++++ .../src/components/NoteHistory/preview.js | 119 ++++++++++++++++++ apps/mobile/src/components/NoteItem/index.js | 1 + .../src/views/Settings/backuprestore.js | 21 ++-- 8 files changed, 285 insertions(+), 46 deletions(-) create mode 100644 apps/mobile/src/components/NoteHistory/index.js create mode 100644 apps/mobile/src/components/NoteHistory/preview.js diff --git a/apps/mobile/android/app/src/main/assets/plaineditor.html b/apps/mobile/android/app/src/main/assets/plaineditor.html index c972282cc..91788463b 100644 --- a/apps/mobile/android/app/src/main/assets/plaineditor.html +++ b/apps/mobile/android/app/src/main/assets/plaineditor.html @@ -79,6 +79,7 @@ .htmldiff_div { padding: 12px !important; + padding-top: 0px !important; overflow-x: hidden; overflow-y: scroll; min-height: 150px; diff --git a/apps/mobile/html/Web.bundle/site/plaineditor.html b/apps/mobile/html/Web.bundle/site/plaineditor.html index c972282cc..91788463b 100644 --- a/apps/mobile/html/Web.bundle/site/plaineditor.html +++ b/apps/mobile/html/Web.bundle/site/plaineditor.html @@ -79,6 +79,7 @@ .htmldiff_div { padding: 12px !important; + padding-top: 0px !important; overflow-x: hidden; overflow-y: scroll; min-height: 150px; diff --git a/apps/mobile/src/components/ActionSheetComponent/index.js b/apps/mobile/src/components/ActionSheetComponent/index.js index 55dd83dc1..fd71b5558 100644 --- a/apps/mobile/src/components/ActionSheetComponent/index.js +++ b/apps/mobile/src/components/ActionSheetComponent/index.js @@ -1,6 +1,5 @@ -import Clipboard from "@react-native-clipboard/clipboard"; - -import React, { useEffect, useState } from 'react'; +import Clipboard from '@react-native-clipboard/clipboard'; +import React, {useEffect, useState} from 'react'; import { Dimensions, Keyboard, @@ -9,30 +8,32 @@ import { TouchableOpacity, View } from 'react-native'; -import { FlatList } from 'react-native-gesture-handler'; +import {FlatList} from 'react-native-gesture-handler'; import Share from 'react-native-share'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; -import { notesnook } from '../../../e2e/test.ids'; -import { useTracked } from '../../provider'; -import { Actions } from '../../provider/Actions'; +import {notesnook} from '../../../e2e/test.ids'; +import {useTracked} from '../../provider'; +import {Actions} from '../../provider/Actions'; import { useMenuStore, useSelectionStore, - useSettingStore, useUserStore + useSettingStore, + useUserStore } from '../../provider/stores'; -import { DDS } from '../../services/DeviceDetection'; +import {DDS} from '../../services/DeviceDetection'; import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent, openVault, + presentSheet, ToastEvent } from '../../services/EventManager'; import Navigation from '../../services/Navigation'; import Notifications from '../../services/Notifications'; -import SettingsService from "../../services/SettingsService"; +import SettingsService from '../../services/SettingsService'; import Sync from '../../services/Sync'; -import { editing } from '../../utils'; +import {editing} from '../../utils'; import { ACCENT, COLOR_SCHEME, @@ -40,7 +41,7 @@ import { COLOR_SCHEME_LIGHT, setColorScheme } from '../../utils/Colors'; -import { db } from '../../utils/database'; +import {db} from '../../utils/database'; import { eOpenAttachmentsDialog, eOpenLoginDialog, @@ -49,20 +50,20 @@ import { eOpenTagsDialog, refreshNotesPage } from '../../utils/Events'; -import { deleteItems, openLinkInBrowser } from '../../utils/functions'; -import { MMKV } from '../../utils/mmkv'; -import { SIZE } from '../../utils/SizeUtils'; -import { sleep, timeConverter } from '../../utils/TimeUtils'; -import { Button } from '../Button'; -import { presentDialog } from '../Dialog/functions'; -import { PressableButton } from '../PressableButton'; +import {deleteItems, openLinkInBrowser} from '../../utils/functions'; +import {MMKV} from '../../utils/mmkv'; +import {SIZE} from '../../utils/SizeUtils'; +import {sleep, timeConverter} from '../../utils/TimeUtils'; +import {Button} from '../Button'; +import {presentDialog} from '../Dialog/functions'; +import NoteHistory from '../NoteHistory'; +import {PressableButton} from '../PressableButton'; import Heading from '../Typography/Heading'; import Paragraph from '../Typography/Paragraph'; -import { ActionSheetColorsSection } from './ActionSheetColorsSection'; -import { ActionSheetTagsSection } from './ActionSheetTagsSection'; +import {ActionSheetColorsSection} from './ActionSheetColorsSection'; +import {ActionSheetTagsSection} from './ActionSheetTagsSection'; const w = Dimensions.get('window').width; - let htmlToText; export const ActionSheetComponent = ({ close = () => {}, @@ -193,7 +194,11 @@ export const ActionSheetComponent = ({ func: () => { if (!colors.night) { MMKV.setStringAsync('theme', JSON.stringify({night: true})); - changeColorScheme(SettingsService.get().pitchBlack ? COLOR_SCHEME_PITCH_BLACK : COLOR_SCHEME_DARK); + changeColorScheme( + SettingsService.get().pitchBlack + ? COLOR_SCHEME_PITCH_BLACK + : COLOR_SCHEME_DARK + ); } else { MMKV.setStringAsync('theme', JSON.stringify({night: false})); changeColorScheme(COLOR_SCHEME_LIGHT); @@ -547,7 +552,7 @@ export const ActionSheetComponent = ({ func: async () => { close(); await sleep(300); - eSendEvent(eOpenAttachmentsDialog,note); + eSendEvent(eOpenAttachmentsDialog, note); } }, { @@ -649,6 +654,20 @@ export const ActionSheetComponent = ({ positiveType: 'errorShade' }); } + }, + { + name: 'History', + title: 'History', + icon: 'history', + func: async () => { + close(); + await sleep(300); + presentSheet({ + noProgress: true, + noIcon: true, + component: ref => + }); + } } ]; @@ -691,7 +710,7 @@ export const ActionSheetComponent = ({ /> - + {rowItem.title} @@ -831,7 +850,7 @@ export const ActionSheetComponent = ({ heading: topic.title, id: topic.id, type: topic.type - }; + }; eSendEvent(refreshNotesPage, params); Navigation.navigate(routeName, params, headerState); }} @@ -984,13 +1003,13 @@ export const ActionSheetComponent = ({ style={{ width: '100%', paddingHorizontal: 12, - marginTop: 10, + marginTop: 10 }}>