Skip to content

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

feat: add search

ammarahm-ed87f3af2087a8
diff --git a/apps/mobile/App.js b/apps/mobile/App.js
index 19bf778b4..1259efe52 100644
--- a/apps/mobile/App.js
+++ b/apps/mobile/App.js
@@ -1,4 +1,4 @@
-import React, {useState, useEffect} from 'react';
+import React, { useState, useEffect } from 'react';
import NavigationService, {
AppContainer,
} from './src/services/NavigationService';
@@ -10,12 +10,12 @@ import {
DeviceEventEmitter,
Platform,
} from 'react-native';
-import {COLOR_SCHEME, SIZE, opacity, WEIGHT} from './src/common/common';
+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/api/database';
import StorageInterface from './src/utils/storage';
-import {RenderSideMenu} from './src/views/Home';
+import { RenderSideMenu } from './src/views/Home';
import * as Animatable from 'react-native-animatable';
const App = () => {
const [colors, setColors] = useState(COLOR_SCHEME);
@@ -80,8 +80,8 @@ const App = () => {
: undefined
</Animatable.View>
) : (
- undefined
- )}
+ undefined
+ )}
<AppContainer
style={{
@@ -137,12 +137,14 @@ const App = () => {
</ActionButton.Item>
</ActionButton>
) : (
- undefined
- )}
+ undefined
+ )}
</View>
);
};
+
+
export default App;
export const storage = new Storage(StorageInterface);
diff --git a/apps/mobile/android/app/src/main/assets/texteditor.html b/apps/mobile/android/app/src/main/assets/texteditor.html
index 3572d4138..792f1940c 100644
--- a/apps/mobile/android/app/src/main/assets/texteditor.html
+++ b/apps/mobile/android/app/src/main/assets/texteditor.html
@@ -420,7 +420,7 @@
.ql-editor.ql-blank::before {
color: rgba(0, 0, 0, 0.6);
content: attr(data-placeholder);
- font-style: italic;
+
left: 15px;
pointer-events: none;
position: absolute;
@@ -1103,20 +1103,17 @@
const editor = new Quill('#editor', {
modules: {
toolbar: [
- [{header: [1, 2, 3, 4, 5, 6, false]}],
- ['bold', 'italic', 'underline', 'strike'], // toggled buttons
- ['link', 'image', 'video'],
- ['blockquote', 'code-block'],
+ [{header:1},{header:2}],
+ [{size: ['small', false, 'large', 'huge']}], // custom dropdown
+ ['bold', 'italic','image'], // toggled buttons
[{list: 'ordered'}, {list: 'bullet'}],
+ [{header: [3, 4, 5, 6]}],
+ [{align: []}],
+ [{color: []}, {background: []}], // dropdown with defaults from theme
+ ['underline', 'strike','blockquote', 'code-block'],
[{script: 'sub'}, {script: 'super'}], // superscript/subscript
[{indent: '-1'}, {indent: '+1'}], // outdent/indent
[{direction: 'rtl'}], // text direction
-
- [{size: ['small', false, 'large', 'huge']}], // custom dropdown
-
- [{color: []}, {background: []}], // dropdown with defaults from theme
- [{align: []}],
-
['clean'],
],
imageCompressor: {
@@ -1191,10 +1188,12 @@
}
}
- window.ReactNativeWebView.postMessage(
- JSON.stringify(editor.getContents()),
- );
-
+
+ let m = {};
+ m.delta = editor.getContents();
+ m.text = editor.getText();
+ m.html = editor.root.innerHTML;
+ window.ReactNativeWebView.postMessage(JSON.stringify(m));
});
var Font = Quill.import('formats/font');
diff --git a/apps/mobile/ios/Notes.xcodeproj/project.pbxproj b/apps/mobile/ios/Notes.xcodeproj/project.pbxproj
index 122945987..353b914c5 100644
--- a/apps/mobile/ios/Notes.xcodeproj/project.pbxproj
+++ b/apps/mobile/ios/Notes.xcodeproj/project.pbxproj
@@ -484,9 +484,9 @@
"${PODS_ROOT}/../../node_modules/react-native-vector-icons/Fonts/FontAwesome5_Solid.ttf",
"${PODS_ROOT}/../../node_modules/react-native-vector-icons/Fonts/Fontisto.ttf",
"${PODS_ROOT}/../../node_modules/react-native-vector-icons/Fonts/Foundation.ttf",
- "${PODS_ROOT}/../../node_modules/react-native-vector-icons/Fonts/Ionicons.ttf",
"${PODS_ROOT}/../../node_modules/react-native-vector-icons/Fonts/MaterialCommunityIcons.ttf",
"${PODS_ROOT}/../../node_modules/react-native-vector-icons/Fonts/MaterialIcons.ttf",
+ "${PODS_ROOT}/../../node_modules/react-native-vector-icons/Fonts/Octicons.ttf",
"${PODS_ROOT}/../../node_modules/react-native-vector-icons/Fonts/SimpleLineIcons.ttf",
"${PODS_ROOT}/../../node_modules/react-native-vector-icons/Fonts/Zocial.ttf",
);
diff --git a/apps/mobile/ios/Podfile.lock b/apps/mobile/ios/Podfile.lock
index 48e01a56d..ac6efa41f 100644
--- a/apps/mobile/ios/Podfile.lock
+++ b/apps/mobile/ios/Podfile.lock
@@ -377,4 +377,4 @@ SPEC CHECKSUMS:
PODFILE CHECKSUM: c7f3c4928c6d0c850545a0a28079ac3abeed60a4
-COCOAPODS: 1.8.1
+COCOAPODS: 1.8.4
diff --git a/apps/mobile/src/components/NotesList/index.js b/apps/mobile/src/components/NotesList/index.js
index 5f9289682..02dd9d63c 100644
--- a/apps/mobile/src/components/NotesList/index.js
+++ b/apps/mobile/src/components/NotesList/index.js
@@ -27,48 +27,13 @@ import NoteItem from '../NoteItem';
import NavigationService from '../../services/NavigationService';
import {storage} from '../../../App';
-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 NotesList = ({keyword}) => {
+export const NotesList = ({keyword, searchResults}) => {
const [colors, setColors] = useState(COLOR_SCHEME);
- const [notes, setNotes] = useState([]);
- const fetchNotes = async () => {
- let allNotes = await storage.getNotes();
- console.log(allNotes);
- if (allNotes) {
- setNotes(allNotes);
- }
- };
- useEffect(() => {
- fetchNotes();
- }, [keyword]);
return (
<>
<FlatList
- data={notes}
+ data={searchResults}
ListFooterComponent={
<View
style={{
diff --git a/apps/mobile/src/components/SearchInput/index.js b/apps/mobile/src/components/SearchInput/index.js
index be190d521..3023f4fe4 100644
--- a/apps/mobile/src/components/SearchInput/index.js
+++ b/apps/mobile/src/components/SearchInput/index.js
@@ -24,7 +24,6 @@ export const Search = props => {
justifyContent: 'space-between',
alignItems: 'center',
width: Platform.isPad ? '95%' : '90%',
-
alignSelf: 'center',
borderRadius: br,
borderWidth: 1.5,
@@ -58,7 +57,7 @@ export const Search = props => {
<Icon
style={{paddingRight: Platform.isPad ? '1.25%' : '2.5%'}}
onPress={() => {
- props.value.length > 0 ? props.onClose() : null;
+ props.value.length > 0 ? props.clearSearch() : null;
inputRef.current.setNativeProps({
text: '',
});
diff --git a/apps/mobile/src/services/NavigationService.js b/apps/mobile/src/services/NavigationService.js
index 414af01ff..70e6dc488 100755
--- a/apps/mobile/src/services/NavigationService.js
+++ b/apps/mobile/src/services/NavigationService.js
@@ -13,6 +13,7 @@ import Signup from '../views/Signup';
import ForgotPassword from '../views/ForgotPassword';
import Settings from '../views/Settings';
import Trash from '../views/Trash';
+import Notes from '../views/Notes';
const TopLevelNavigator = createStackNavigator(
{
@@ -55,6 +56,9 @@ const TopLevelNavigator = createStackNavigator(
Trash: {
screen: Trash,
},
+ Notes: {
+ screen: Notes,
+ },
},
{
initialRouteName: 'Home',
diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.js
index be0ba2b23..3507257e8 100755
--- a/apps/mobile/src/views/Home/index.js
+++ b/apps/mobile/src/views/Home/index.js
@@ -34,6 +34,7 @@ import {Header} from '../../components/header';
import {tsPropertySignature} from '@babel/types';
import {NavigationEvents} from 'react-navigation';
import {NotesList} from '../../components/NotesList';
+import {storage} from '../../../App';
export const Home = ({navigation}) => {
const [loading, setLoading] = useState(true);
@@ -41,7 +42,7 @@ export const Home = ({navigation}) => {
const [isOpen, setOpen] = useState(false);
const [hidden, setHidden] = useState(false);
const [text, setText] = useState('');
-
+ const [searchResults, setSearchResults] = useState([]);
useEffect(() => {
setTimeout(() => {
setLoading(false);
@@ -50,15 +51,16 @@ export const Home = ({navigation}) => {
const onChangeText = value => {
setText(value);
- if (value.length > 2) {
- setHidden(true);
- } else if (value.length < 2) {
- setHidden(false);
- }
};
- const onSubmitEditing = () => {
- if (!text || text.length < 2) {
+ const onSubmitEditing = async () => {
+ if (!text || text.length < 1) {
setHidden(false);
+ } else {
+ setHidden(true);
+ let results = await storage.searchNotes(text);
+ if (results) {
+ setSearchResults(results);
+ }
}
};
@@ -70,6 +72,11 @@ export const Home = ({navigation}) => {
const onFocus = () => {};
+ const clearSearch = () => {
+ setSearchResults([]);
+ setHidden(false);
+ };
+
return Platform.isPad ? (
<SafeAreaView style={[styles.container]}>
<NavigationEvents
@@ -115,10 +122,15 @@ export const Home = ({navigation}) => {
onSubmitEditing={onSubmitEditing}
onBlur={onBlur}
onFocus={onFocus}
+ clearSearch={clearSearch}
value={text}
/>
- {hidden ? <NotesList keyword={text} /> : <RecentList />}
+ {hidden ? (
+ <NotesList searchResults={searchResults} keyword={text} />
+ ) : (
+ <RecentList />
+ )}
</SafeAreaView>
</SideMenu>
);
@@ -386,6 +398,12 @@ export const RenderSideMenu = ({colors, close}) => (
'water',
].map(item => (
<TouchableOpacity
+ onPress={() => {
+ close();
+ NavigationService.navigate('Notes', {
+ heading: item,
+ });
+ }}
style={{
flexDirection: 'row',
justifyContent: 'flex-start',
diff --git a/apps/mobile/src/views/Notes/index.js b/apps/mobile/src/views/Notes/index.js
index cd115608c..b6aec556f 100644
--- a/apps/mobile/src/views/Notes/index.js
+++ b/apps/mobile/src/views/Notes/index.js
@@ -24,6 +24,7 @@ import Icon from 'react-native-vector-icons/Ionicons';
import {Reminder} from '../../components/Reminder';
import {ListItem} from '../../components/ListItem';
import {Header} from '../../components/header';
+import {Search} from '../../components/SearchInput';
const w = Dimensions.get('window').width;
const h = Dimensions.get('window').height;
@@ -43,6 +44,7 @@ export const Notes = ({navigation}) => {
return (
<SafeAreaView>
<Header colors={colors} heading={params.heading} canGoBack={false} />
+ <Search />
</SafeAreaView>
);
};