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
connect recents with local storage
thewisefarmerr9a8fabb1a3e9
diff --git a/apps/mobile/App.js b/apps/mobile/App.jsindex 434c9669e..d914fd4a4 100644--- a/apps/mobile/App.js+++ b/apps/mobile/App.js@@ -13,7 +13,7 @@ import {import {COLOR_SCHEME, SIZE, opacity, WEIGHT} from './src/common/common';import Icon from 'react-native-vector-icons/Ionicons';import ActionButton from 'react-native-action-button';-import Storage from 'notes-core/sync/storage';+import Storage from 'notes-core/api/database';import StorageInterface from './src/utils/storage';const App = () => {const [colors, setColors] = useState(COLOR_SCHEME);diff --git a/apps/mobile/src/components/NoteItem/index.js b/apps/mobile/src/components/NoteItem/index.jsindex aa6fcb2b7..efeada9cc 100644--- a/apps/mobile/src/components/NoteItem/index.js+++ b/apps/mobile/src/components/NoteItem/index.js@@ -6,6 +6,7 @@ import {ScrollView,Dimensions,FlatList,+ TouchableWithoutFeedback,} from 'react-native';import {@@ -21,7 +22,9 @@ import {import Icon from 'react-native-vector-icons/Ionicons';import {Reminder} from '../Reminder';-import {getElevation} from '../../utils/utils';+import {getElevation, timeSince} from '../../utils/utils';+import NavigationService from '../../services/NavigationService';+const w = Dimensions.get('window').width;const h = Dimensions.get('window').height;@@ -31,74 +34,78 @@ const NoteItem = props => {return (<View- activeOpacity={opacity}style={{marginHorizontal: w * 0.05,backgroundColor: '#f0f0f0',marginVertical: h * 0.015,borderRadius: br,-justifyContent: 'center',alignItems: 'center',+ flexDirection: 'row',padding: pv,}}>- <View+ <TouchableOpacity+ activeOpacity={1}+ onPress={() => {+ NavigationService.navigate('Editor', {+ note: item,+ });+ }}style={{- width: '100%',- flexDirection: 'row',- justifyContent: 'space-between',- alignItems: 'center',+ width: '95%',}}>- <Text- numberOfLines={1}- style={{- color: colors.pri,- fontSize: SIZE.md,- fontFamily: WEIGHT.bold,- maxWidth: '100%',- }}>- {item.title}- </Text>+ <>+ <Text+ numberOfLines={1}+ style={{+ color: colors.pri,+ fontSize: SIZE.md,+ fontFamily: WEIGHT.bold,+ maxWidth: '100%',+ marginBottom: 5,+ }}>+ {item.title.replace('\n', '')}+ </Text>+ <View+ style={{+ justifyContent: 'flex-start',+ alignItems: 'flex-start',+ width: '100%',+ }}>+ <Text+ style={{+ fontSize: SIZE.xs + 1,+ color: colors.icon,+ fontFamily: WEIGHT.regular,+ width: '100%',+ maxWidth: '100%',+ paddingRight: ph,+ }}>+ {item.headline}+ </Text>- <View- style={{- width: '20%',- justifyContent: 'space-between',- flexDirection: 'row',- alignItems: 'center',- }}>- <Icon name="md-share-alt" size={SIZE.lg} color={colors.icon} />- <Icon name="md-star" size={SIZE.lg} color={colors.icon} />- <Icon name="md-more" size={SIZE.lg} color={colors.icon} />- </View>- </View>- <View+ <Text+ style={{+ color: colors.accent,+ fontSize: SIZE.xxs,+ textAlignVertical: 'center',+ fontFamily: WEIGHT.regular,+ }}>+ {timeSince(item.dateCreated) + ' '}+ </Text>+ </View>+ </>+ </TouchableOpacity>++ <TouchableOpacitystyle={{- justifyContent: 'flex-start',- alignItems: 'flex-start',- width: '100%',+ width: '5%',+ justifyContent: 'center',+ minHeight: 70,+ alignItems: 'center',}}>- <Text- style={{- fontSize: SIZE.xs + 1,- color: colors.icon,- fontFamily: WEIGHT.regular,- width: '100%',- maxWidth: '100%',- }}>- {item.headline}- </Text>-- <Text- style={{- color: colors.accent,- fontSize: SIZE.xxs,- textAlignVertical: 'center',- fontFamily: WEIGHT.regular,- }}>- {item.timestamp + ' '}- </Text>- </View>+ <Icon name="md-more" size={SIZE.lg} color={colors.icon} />+ </TouchableOpacity></View>);};diff --git a/apps/mobile/src/components/Recents/index.js b/apps/mobile/src/components/Recents/index.jsindex b9df045f2..3b7bbc7bc 100644--- a/apps/mobile/src/components/Recents/index.js+++ b/apps/mobile/src/components/Recents/index.js@@ -1,4 +1,4 @@-import React, {useState} from 'react';+import React, {useState, useEffect} from 'react';import {View,Text,@@ -24,6 +24,7 @@ import {Reminder} from '../Reminder';import {getElevation} from '../../utils/utils';import NoteItem from '../NoteItem';import NavigationService from '../../services/NavigationService';+import {storage} from '../../../App';const w = Dimensions.get('window').width;const h = Dimensions.get('window').height;@@ -57,38 +58,50 @@ const data = [timestamp: '2 months ago',},];+let blockdata = [+ {+ name: '',+ icon: 'md-add',+ func: () => {+ NavigationService.navigate('Editor');+ },+ },+ {+ name: 'All Notes',+ icon: 'md-create',+ func: () => {+ NavigationService.navigate('Reminders');+ },+ },+ {+ name: 'Lists',+ icon: 'ios-list',+ func: () => {+ NavigationService.navigate('Lists');+ },+ },+];export const RecentList = () => {const [colors, setColors] = useState(COLOR_SCHEME);+ const [notes, setNotes] = useState([]);- let blockdata = [- {- name: '',- icon: 'md-add',- func: () => {- NavigationService.navigate('Editor');- },- },- {- name: 'All Notes',- icon: 'md-create',- func: () => {- NavigationService.navigate('Reminders');- },- },- {- name: 'Lists',- icon: 'ios-list',- func: () => {- NavigationService.navigate('Lists');- },- },- ];+ const fetchNotes = async () => {+ return await storage.getNotes();+ };++ useEffect(() => {+ fetchNotes().then(allNotes => {+ if (allNotes) {+ setNotes(allNotes);+ }+ });+ });return (<><FlatList- data={data}+ data={notes}ListFooterComponent={<Viewstyle={{diff --git a/apps/mobile/src/utils/utils.js b/apps/mobile/src/utils/utils.jsindex 27c8ba24f..98768febf 100755--- a/apps/mobile/src/utils/utils.js+++ b/apps/mobile/src/utils/utils.js@@ -7,3 +7,30 @@ export const getElevation = elevation => {shadowRadius: 0.7 * elevation,};};++export function timeSince(date) {+ var seconds = Math.floor((new Date() - date) / 1000);++ var interval = Math.floor(seconds / 31536000);++ if (interval > 1) {+ return interval < 2 ? interval + ' year ago' : interval + ' years ago';+ }+ interval = Math.floor(seconds / 2592000);+ if (interval > 1) {+ return interval < 2 ? interval + ' month ago' : interval + ' months ago';+ }+ interval = Math.floor(seconds / 86400);+ if (interval > 1) {+ return interval < 2 ? interval + ' day ago' : interval + ' days ago';+ }+ interval = Math.floor(seconds / 3600);+ if (interval > 1) {+ return interval < 2 ? interval + ' hour ago' : interval + ' hours ago';+ }+ interval = Math.floor(seconds / 60);+ if (interval > 1) {+ return interval < 2 ? interval + ' min ago' : interval + ' min ago';+ }+ return Math.floor(seconds) + ' secs ago';+}diff --git a/apps/mobile/src/views/Editor/index.js b/apps/mobile/src/views/Editor/index.jsindex 7cafa9780..5a4c79899 100755--- a/apps/mobile/src/views/Editor/index.js+++ b/apps/mobile/src/views/Editor/index.js@@ -30,39 +30,29 @@ import {storage} from '../../../App';const w = Dimensions.get('window').width;const h = Dimensions.get('window').height;-const saveText = async (type, title, content) => {- let data = {- type,- title,- headline:- content.text.length < 80 ? content.text : content.text.slice(0, 80),- content,- favorite: false,- 'date-created': Date.now(),- 'last-edited': Date.now(),- length: content.text.length,- pinned: false,- size: 0,- colors: [],- tags: [],- folders: [],- };-- await storage.write('notes', [data]);-- console.log(await storage.read('notes'));-};+var timestamp = null;+var content = null;+var title = null;const Editor = ({navigation}) => {+ // STATE+const [colors, setColors] = useState(COLOR_SCHEME);const [keyboardHeight, setKeyboardHeight] = useState(0);++ // VARIABLES++ let updateInterval = null;+ let keyboardDidShowListener = null;+ let keyboardDidHideListener = null;++ // REFS+let EditorWebView = createRef();const _textRender = createRef();+ const titleRef = createRef();- let content, title, headline;-- let keyboardDidShowListener;- let keyboardDidHideListener;+ // FUNCTIONSconst _keyboardDidShow = e => {LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);@@ -76,87 +66,32 @@ const Editor = ({navigation}) => {setKeyboardHeight(0);};- function onChangeText(data) {+ async function onChange(data) {if (data !== '') {content = JSON.parse(data);- saveText('note', title, content);}}- useEffect(() => {- DeviceEventEmitter.emit('hide');- keyboardDidShowListener = Keyboard.addListener(- 'keyboardDidShow',- _keyboardDidShow,- );- keyboardDidHideListener = Keyboard.addListener(- 'keyboardDidHide',- _keyboardDidHide,- );- return () => {- DeviceEventEmitter.emit('show');- keyboardDidShowListener.remove();- keyboardDidHideListener.remove();- };- });+ const saveNote = async () => {+ if (title || content) {+ timestamp = await storage.addNote({+ title,+ content,+ dateCreated: timestamp,+ });+ }+ };const _renderWebpage = () => {- return Platform.OS === 'ios' ? (- <KeyboardAvoidingView behavior="padding" style={{height: '100%'}}>- <View- style={{- height: '100%',- }}>- <TextInput- placeholder="Untitled Note"- placeholderTextColor={colors.icon}- style={{- width: '100%',- fontFamily: WEIGHT.bold,- fontSize: SIZE.xxl,- paddingHorizontal: '3%',- paddingVertical: 0,- marginTop: Platform.OS == 'ios' ? h * 0.01 : h * 0.04,- }}- onChangeText={value => {- title = value;- }}- />-- <WebView- ref={EditorWebView}- onError={error => console.log(error)}- javaScriptEnabled- onShouldStartLoadWithRequest={request => {- if (request.url.includes('https')) {- Linking.openURL(request.url);- return false;- } else {- return true;- }- }}- cacheEnabled={true}- cacheMode="LOAD_CACHE_ELSE_NETWORK"- domStorageEnabled- scrollEnabled={false}- bounces={true}- scalesPageToFit={true}- source={require('./web/texteditor.html')}- style={{height: '100%', maxHeight: '100%'}}- onMessage={evt => {- if (evt.nativeEvent.data !== '') {- onChangeText(evt.nativeEvent.data);- }- }}- />- </View>- </KeyboardAvoidingView>- ) : (+ <KeyboardAvoidingView+ behavior={Platform.OS === 'ios' ? 'padding' : null}+ style={{height: '100%'}}><Viewstyle={{height: '100%',}}><TextInput+ ref={titleRef}placeholder="Untitled Note"placeholderTextColor={colors.icon}style={{@@ -167,15 +102,23 @@ const Editor = ({navigation}) => {paddingVertical: 0,marginTop: Platform.OS == 'ios' ? h * 0.01 : h * 0.04,}}+ onChangeText={value => {+ title = value;+ }}+ onSubmitEditing={async () => await saveNote()}/><WebViewref={EditorWebView}onError={error => console.log(error)}+ onLoad={() => {+ if (navigation.state.params.note) {+ let note = navigation.state.params.note;++ post(JSON.stringify(note.content.delta));+ }+ }}javaScriptEnabled- domStorageEnabled- cacheEnabled- cacheMode="LOAD_CACHE_ELSE_NETWORK"onShouldStartLoadWithRequest={request => {if (request.url.includes('https')) {Linking.openURL(request.url);@@ -184,32 +127,86 @@ const Editor = ({navigation}) => {return true;}}}+ cacheEnabled={true}+ cacheMode="LOAD_CACHE_ELSE_NETWORK"+ domStorageEnabledscrollEnabled={false}- bounces- scalesPageToFit- source={{- uri: 'file:///android_asset/texteditor.html',- baseUrl: 'baseUrl:"file:///android_asset/',- }}+ bounces={true}+ scalesPageToFit={true}+ source={+ Platform.OS === 'ios'+ ? require('./web/texteditor.html')+ : {+ uri: 'file:///android_asset/texteditor.html',+ baseUrl: 'baseUrl:"file:///android_asset/',+ }+ }style={{height: '100%', maxHeight: '100%'}}onMessage={evt => {if (evt.nativeEvent.data !== '') {- onChangeText(evt.nativeEvent.data);+ onChange(evt.nativeEvent.data);}}}/></View>- );+ </KeyboardAvoidingView>;};+ // EFFECTS++ useEffect(() => {+ if (navigation.state.params.note) {+ let note = navigation.state.params.note;+ titleRef.current.setNativeProps({+ text: note.title,+ });+ title = note.title;+ timestamp = note.dateCreated;+ }+ });++ useEffect(() => {+ keyboardDidShowListener = Keyboard.addListener(+ 'keyboardDidShow',+ _keyboardDidShow,+ );+ keyboardDidHideListener = Keyboard.addListener(+ 'keyboardDidHide',+ _keyboardDidHide,+ );+ return () => {+ keyboardDidShowListener.remove();+ keyboardDidHideListener.remove();+ };+ });++ useEffect(() => {+ updateInterval = setInterval(async function() {+ await saveNote();+ }, 2000);+ return () => {+ saveNote();+ clearInterval(updateInterval);+ updateInterval = null;+ };+ });++ useEffect(() => {+ DeviceEventEmitter.emit('hide');++ return () => {+ DeviceEventEmitter.emit('show');+ };+ });+return (<SafeAreaView style={{height: '100%'}}>- {_renderWebpage()}<NavigationEventsonWillFocus={() => {DeviceEventEmitter.emit('hide');}}/>+ {_renderWebpage()}</SafeAreaView>);};