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: note history
ammarahm-edc72acbd989fd
diff --git a/apps/mobile/android/app/src/main/assets/plaineditor.html b/apps/mobile/android/app/src/main/assets/plaineditor.htmlindex 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.htmlindex 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.jsindex 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 => <NoteHistory ref={ref} note={note} />+ });+ }}];@@ -691,7 +710,7 @@ export const ActionSheetComponent = ({/></PressableButton>- <Paragraph size={SIZE.xs + 2} style={{textAlign: 'center'}}>+ <Paragraph size={SIZE.xs + 2} style={{textAlign: 'center'}}>{rowItem.title}</Paragraph></View>@@ -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}}><ButtononPress={async () => {console.log('copy data');- let additionalData = {}- if (note.type === "note") {+ let additionalData = {};+ if (note.type === 'note') {let content = await db.content.raw(note.contentId);if (content) {content = db.debug.strip(content);@@ -1004,11 +1023,10 @@ export const ActionSheetComponent = ({Clipboard.setString(db.debug.strip(_note));ToastEvent.show({- heading:"Debug data copied!",- type:'success',- context:'local'- })-+ heading: 'Debug data copied!',+ type: 'success',+ context: 'local'+ });}}fontSize={SIZE.sm}title="Copy data"diff --git a/apps/mobile/src/components/GeneralSheet/index.js b/apps/mobile/src/components/GeneralSheet/index.jsindex dc4aa43e1..52adc12dd 100644--- a/apps/mobile/src/components/GeneralSheet/index.js+++ b/apps/mobile/src/components/GeneralSheet/index.js@@ -42,7 +42,10 @@ const GeneralSheet = ({context}) => {actionSheetRef.current?.setModalVisible(true);};- const close = () => {+ const close = ctx => {+ if ((ctx && !context) || (ctx && ctx !== context)) {+ return;+ }actionSheetRef.current?.setModalVisible(false);};diff --git a/apps/mobile/src/components/NoteHistory/index.js b/apps/mobile/src/components/NoteHistory/index.jsnew file mode 100644index 000000000..53ece2896--- /dev/null+++ b/apps/mobile/src/components/NoteHistory/index.js@@ -0,0 +1,97 @@+import React, {useCallback, useEffect, useState} from 'react';+import {View} from 'react-native';+import {FlatList} from 'react-native-gesture-handler';+import Icon from 'react-native-vector-icons/MaterialCommunityIcons';+import {useTracked} from '../../provider';+import {presentSheet} from '../../services/EventManager';+import {db} from '../../utils/database';+import {timeConverter} from '../../utils/TimeUtils';+import DialogHeader from '../Dialog/dialog-header';+import GeneralSheet from '../GeneralSheet';+import {PressableButton} from '../PressableButton';+import Seperator from '../Seperator';+import Paragraph from '../Typography/Paragraph';+import NotePreview from './preview';++export default function NoteHistory({note, ref}) {+ const [history, setHistory] = useState([]);+ const [loading, setLoading] = useState(true);+ const [state] = useTracked();+ const {colors} = state;++ useEffect(() => {+ (async () => {+ console.log(note.id);+ console.log(await db.noteHistory.get(note.id));++ setHistory([...(await db.noteHistory.get(note.id))].reverse());+ setLoading(false);+ })();+ }, []);++ async function preview(item) {+ let content = await db.noteHistory.content(item.sessionContentId);++ presentSheet({+ component: <NotePreview session={item} content={content} />,+ context: 'note_history',+ noProgress: true,+ noIcon: true+ });+ }++ const renderItem = useCallback(+ ({item, index}) => (+ <PressableButton+ type="grayBg"+ onPress={() => preview(item)}+ customStyle={{+ justifyContent: 'center',+ alignItems: 'flex-start',+ paddingHorizontal: 12,+ height: 45,+ marginBottom: 10+ }}>+ <Paragraph>{timeConverter(item.dateEdited)}</Paragraph>+ </PressableButton>+ ),+ []+ );++ return (+ <View>+ <GeneralSheet context="note_history" />+ <DialogHeader+ title="Note history"+ paragraph="Revert back to an older version of this note"+ padding={12}+ />++ <Seperator />++ <FlatList+ onMomentumScrollEnd={() => {+ ref?.current?.handleChildScrollEnd();+ }}+ style={{+ paddingHorizontal: 12+ }}+ keyExtractor={item => item.id}+ data={history}+ ListEmptyComponent={+ <View+ style={{+ width: '100%',+ justifyContent: 'center',+ alignItems: 'center',+ height: 200+ }}>+ <Icon name="history" size={60} color={colors.icon} />+ <Paragraph color={colors.icon}>No note history found.</Paragraph>+ </View>+ }+ renderItem={renderItem}+ />+ </View>+ );+}diff --git a/apps/mobile/src/components/NoteHistory/preview.js b/apps/mobile/src/components/NoteHistory/preview.jsnew file mode 100644index 000000000..e02a17f74--- /dev/null+++ b/apps/mobile/src/components/NoteHistory/preview.js@@ -0,0 +1,119 @@+import React, {useRef} from 'react';+import {View} from 'react-native';+import WebView from 'react-native-webview';+import {useTracked} from '../../provider';+import {eSendEvent, ToastEvent} from '../../services/EventManager';+import Navigation from '../../services/Navigation';+import {dHeight} from '../../utils';+import {db} from '../../utils/database';+import {eCloseProgressDialog} from '../../utils/Events';+import {normalize} from '../../utils/SizeUtils';+import {timeConverter} from '../../utils/TimeUtils';+import {sourceUri} from '../../views/Editor/Functions';+import {Button} from '../Button';+import DialogHeader from '../Dialog/dialog-header';++export default function NotePreview({session, content}) {+ const [state] = useTracked();+ const {colors} = state;+ const webviewRef = useRef();++ const onLoad = async () => {+ console.log(content);+ let preview = await db.content.insertPlaceholders(+ content,+ 'placeholder.svg'+ );+ console.log(preview, 'preview');+ postMessage('htmldiff', preview?.data);+ let theme = {...colors};+ theme.factor = normalize(1);+ postMessage('theme', JSON.stringify(theme));+ };++ function postMessage(type, value = null) {+ let message = {+ type: type,+ value+ };+ webviewRef.current?.postMessage(JSON.stringify(message));+ }++ const _onShouldStartLoadWithRequest = request => {+ if (request.url.includes('http')) {+ openLinkInBrowser(request.url, colors)+ .catch(e =>+ ToastEvent.show({+ title: 'Failed to open link',+ message: e.message,+ type: 'success',+ context: 'local'+ })+ )+ .then(r => {+ console.log('closed');+ });++ return false;+ } else {+ return true;+ }+ };++ async function restore() {+ await db.noteHistory.restore(session.id);+ eSendEvent(eCloseProgressDialog, 'note_history');+ eSendEvent(eCloseProgressDialog);+ Navigation.setRoutesToUpdate([+ Navigation.routeNames.NotesPage,+ Navigation.routeNames.Favorites,+ Navigation.routeNames.Notes+ ]);+ ToastEvent.show({+ heading: 'Note restored successfully',+ type: 'success'+ });+ }++ return (+ <View+ style={{+ height: 600,+ width: '100%'+ }}>+ <DialogHeader padding={12} title={timeConverter(session.dateEdited)} />+ <WebView+ ref={webviewRef}+ onShouldStartLoadWithRequest={_onShouldStartLoadWithRequest}+ onLoad={onLoad}+ style={{+ width: '100%',+ height: '100%',+ backgroundColor: 'transparent'+ }}+ cacheMode="LOAD_DEFAULT"+ domStorageEnabled={true}+ scrollEnabled={true}+ bounces={false}+ allowFileAccess={true}+ scalesPageToFit={true}+ allowingReadAccessToURL={Platform.OS === 'android' ? true : null}+ allowFileAccessFromFileURLs={true}+ allowUniversalAccessFromFileURLs={true}+ originWhitelist={['*']}+ javaScriptEnabled={true}+ cacheEnabled={true}+ source={{+ uri: sourceUri + 'plaineditor.html'+ }}+ />++ <View+ style={{+ paddingHorizontal: 12+ }}>+ <Button onPress={restore} title="Restore" type="accent" width="100%" />+ </View>+ </View>+ );+}diff --git a/apps/mobile/src/components/NoteItem/index.js b/apps/mobile/src/components/NoteItem/index.jsindex ff2c2278f..68fcaf033 100644--- a/apps/mobile/src/components/NoteItem/index.js+++ b/apps/mobile/src/components/NoteItem/index.js@@ -67,6 +67,7 @@ const showActionSheet = (item, isTrash) => {'Vault','Delete','RemoveTopic',+ "History",...android]);diff --git a/apps/mobile/src/views/Settings/backuprestore.js b/apps/mobile/src/views/Settings/backuprestore.jsindex 945938f82..ddcadddcb 100644--- a/apps/mobile/src/views/Settings/backuprestore.js+++ b/apps/mobile/src/views/Settings/backuprestore.js@@ -1,9 +1,9 @@-import React, {useEffect, useState} from 'react';-import {Platform, TouchableOpacity, View} from 'react-native';+import React, { useEffect, useState } from 'react';+import { Platform, TouchableOpacity, View } from 'react-native';import ToggleSwitch from 'toggle-switch-react-native';import Paragraph from '../../components/Typography/Paragraph';-import {useTracked} from '../../provider';-import {useSettingStore, useUserStore} from '../../provider/stores';+import { useTracked } from '../../provider';+import { useSettingStore, useUserStore } from '../../provider/stores';import Backup from '../../services/Backup';import {eSendEvent,@@ -17,14 +17,13 @@ import {eOpenLoginDialog,eOpenRestoreDialog} from '../../utils/Events';-import {openLinkInBrowser} from '../../utils/functions';-import {MMKV} from '../../utils/mmkv';-import {SIZE} from '../../utils/SizeUtils';-import {sleep} from '../../utils/TimeUtils';-import {CustomButton} from './button';-import {verifyUser} from './functions';+import { openLinkInBrowser } from '../../utils/functions';+import { MMKV } from '../../utils/mmkv';+import { SIZE } from '../../utils/SizeUtils';+import { sleep } from '../../utils/TimeUtils';+import { CustomButton } from './button';+import { verifyUser } from './functions';import SectionHeader from './section-header';-import * as ScopedStorage from 'react-native-scoped-storage';const SettingsBackupAndRestore = ({isSheet}) => {const [state] = useTracked();