Skip to content

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

add new search to views

ammarahm-edb3817b1f30b6
diff --git a/apps/mobile/src/views/Favorites/index.js b/apps/mobile/src/views/Favorites/index.js
index 4dcf745a6..eb397e200 100644
--- a/apps/mobile/src/views/Favorites/index.js
+++ b/apps/mobile/src/views/Favorites/index.js
@@ -1,16 +1,17 @@
-import React, {useCallback, useEffect, useState} from 'react';
-import {Placeholder} from '../../components/ListPlaceholders';
+import React, { useCallback, useEffect } from 'react';
+import { Placeholder } from '../../components/ListPlaceholders';
import SimpleList from '../../components/SimpleList';
-import {NoteItemWrapper} from '../../components/SimpleList/NoteItemWrapper';
-import {useTracked} from '../../provider';
-import {Actions} from '../../provider/Actions';
-import {eSendEvent} from "../../services/EventManager";
-import {eUpdateSearchState} from "../../utils/Events";
+import { useTracked } from '../../provider';
+import { Actions } from '../../provider/Actions';
+import { eSendEvent } from "../../services/EventManager";
+import SearchService from '../../services/SearchService';
+import { eScrollEvent } from "../../utils/Events";
export const Favorites = ({route, navigation}) => {
const [state, dispatch] = useTracked();
const {favorites} = state;
const onFocus = useCallback(() => {
+ eSendEvent(eScrollEvent, {name: 'Favorites', type: 'in'});
dispatch({
type: Actions.HEADER_STATE,
state: {
@@ -35,6 +36,7 @@ export const Favorites = ({route, navigation}) => {
useEffect(() => {
navigation.addListener('focus', onFocus);
return () => {
+ eSendEvent(eScrollEvent, {name: 'Notebooks', type: 'back'});
navigation.removeListener('focus', onFocus);
};
});
@@ -47,19 +49,13 @@ export const Favorites = ({route, navigation}) => {
}
}, [favorites]);
+
const updateSearch = () => {
- if (favorites.length === 0) {
- eSendEvent('showSearch', true);
- } else {
- eSendEvent('showSearch');
- eSendEvent(eUpdateSearchState,{
- placeholder: 'Search all favorites',
- data: favorites,
- noSearch: false,
- type: 'notes',
- color: null,
- })
- }
+ SearchService.update({
+ placeholder: 'Search in favorites',
+ data: favorites,
+ type: 'notes',
+ });
};
return (
@@ -75,7 +71,6 @@ export const Favorites = ({route, navigation}) => {
button:null,
}}
focused={() => navigation.isFocused()}
- RenderItem={NoteItemWrapper}
placeholder={<Placeholder type="favorites" />}
placeholderText="Notes you favorite appear here"
/>
diff --git a/apps/mobile/src/views/Folders/index.js b/apps/mobile/src/views/Folders/index.js
index 0a7937c32..1f6d45a2f 100644
--- a/apps/mobile/src/views/Folders/index.js
+++ b/apps/mobile/src/views/Folders/index.js
@@ -7,12 +7,16 @@ import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';
import {eSendEvent} from '../../services/EventManager';
-import {eUpdateSearchState} from '../../utils/Events';
+import SearchService from '../../services/SearchService';
+import { eScrollEvent } from '../../utils/Events';
+
+
export const Folders = ({route, navigation}) => {
const [state, dispatch] = useTracked();
const {notebooks} = state;
const onFocus = useCallback(() => {
+ eSendEvent(eScrollEvent, {name: 'Notebooks', type: 'in'});
dispatch({
type: Actions.HEADER_STATE,
state: true,
@@ -32,25 +36,11 @@ export const Folders = ({route, navigation}) => {
updateSearch();
}, [notebooks]);
- const updateSearch = () => {
- if (notebooks.length === 0) {
- eSendEvent('showSearch', true);
- } else {
- eSendEvent('showSearch');
- eSendEvent(eUpdateSearchState, {
- placeholder: 'Search all notebooks',
- data: notebooks,
- noSearch: false,
- type: 'notebooks',
- color: null,
- });
- }
- };
-
useEffect(() => {
navigation.addListener('focus', onFocus);
return () => {
navigation.removeListener('focus', onFocus);
+ eSendEvent(eScrollEvent, {name: 'Notebooks', type: 'back'});
};
});
@@ -60,9 +50,13 @@ export const Folders = ({route, navigation}) => {
}
}, [notebooks]);
- useEffect(() => {
- console.log('render folders');
- });
+ const updateSearch = () => {
+ SearchService.update({
+ placeholder: 'Search in notebooks',
+ data: notebooks,
+ type: 'notebooks',
+ });
+ };
const _onPressBottomButton = () => AddNotebookEvent();
@@ -74,10 +68,10 @@ export const Folders = ({route, navigation}) => {
focused={() => navigation.isFocused()}
RenderItem={NotebookItemWrapper}
placeholderData={{
- heading:"Your Notebooks",
- paragraph:"You have not added any notebooks yet.",
- button:"Add a Notebook",
- action:_onPressBottomButton
+ heading: 'Your Notebooks',
+ paragraph: 'You have not added any notebooks yet.',
+ button: 'Add a Notebook',
+ action: _onPressBottomButton,
}}
placeholder={<Placeholder type="notebooks" />}
/>
diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.js
index 7e11a2823..3e44d06f0 100755
--- a/apps/mobile/src/views/Home/index.js
+++ b/apps/mobile/src/views/Home/index.js
@@ -1,25 +1,25 @@
import React, {useCallback, useEffect} from 'react';
import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';
-import {Placeholder} from '../../components/ListPlaceholders';
import SimpleList from '../../components/SimpleList';
-import {NoteItemWrapper} from '../../components/SimpleList/NoteItemWrapper';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
import {DDS} from '../../services/DeviceDetection';
import {eSendEvent} from '../../services/EventManager';
+import SearchService from '../../services/SearchService';
import {scrollRef} from '../../utils';
-import {openEditorAnimation} from '../../utils/Animations';
import {
eOnLoadNote,
eScrollEvent,
eUpdateSearchState,
} from '../../utils/Events';
+import {tabBarRef} from '../../utils/Refs';
export const Home = ({navigation}) => {
const [state, dispatch] = useTracked();
const {notes} = state;
const onFocus = useCallback(() => {
+ eSendEvent(eScrollEvent, {name: 'Notes', type: 'in'});
dispatch({
type: Actions.HEADER_TEXT_STATE,
state: {
@@ -36,7 +36,6 @@ export const Home = ({navigation}) => {
});
updateSearch();
- eSendEvent(eScrollEvent, 0);
dispatch({type: Actions.COLORS});
dispatch({type: Actions.NOTES});
}, [notes]);
@@ -47,6 +46,7 @@ export const Home = ({navigation}) => {
navigation.addListener('focus', onFocus);
navigation.addListener('blur', onBlur);
return () => {
+ eSendEvent(eScrollEvent, {name: 'Notes', type: 'back'});
navigation.removeListener('focus', onFocus);
navigation.removeListener('blur', onBlur);
};
@@ -59,25 +59,18 @@ export const Home = ({navigation}) => {
}, [notes]);
const updateSearch = () => {
- if (notes.length === 0) {
- eSendEvent('showSearch', true);
- } else {
- eSendEvent('showSearch');
- eSendEvent(eUpdateSearchState, {
- placeholder: 'Search all notes',
- data: notes,
- noSearch: false,
- type: 'notes',
- color: null,
- });
- }
+ SearchService.update({
+ placeholder: 'Search in notes',
+ data: notes,
+ type: 'notes',
+ });
};
const _onPressBottomButton = async (event) => {
- eSendEvent(eOnLoadNote, {type: 'new'});
-
if (DDS.isPhone || DDS.isSmallTab) {
- openEditorAnimation();
+ tabBarRef.current?.goToPage(1);
+ } else {
+ eSendEvent(eOnLoadNote, {type: 'new'});
}
};
@@ -90,9 +83,6 @@ export const Home = ({navigation}) => {
isHome={true}
pinned={true}
sortMenuButton={true}
- focused={() => navigation.isFocused()}
- RenderItem={NoteItemWrapper}
- placeholder={<Placeholder type="notes" />}
placeholderText={`Notes you write appear here`}
jumpToDialog={true}
placeholderData={{
diff --git a/apps/mobile/src/views/Notebook/index.js b/apps/mobile/src/views/Notebook/index.js
index 19b9419a7..040cc8262 100644
--- a/apps/mobile/src/views/Notebook/index.js
+++ b/apps/mobile/src/views/Notebook/index.js
@@ -1,19 +1,17 @@
-import React, {useCallback, useEffect, useState} from 'react';
-import {AddTopicEvent} from '../../components/DialogManager/recievers';
-import {NotebookItem} from '../../components/NotebookItem';
-import SelectionWrapper from '../../components/SelectionWrapper';
+import React, { useEffect, useState } from 'react';
+import { ContainerBottomButton } from '../../components/Container/ContainerBottomButton';
+import { AddTopicEvent } from '../../components/DialogManager/recievers';
import SimpleList from '../../components/SimpleList';
-import {useTracked} from '../../provider';
-import {Actions} from '../../provider/Actions';
-import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';
+import { useTracked } from '../../provider';
+import { Actions } from '../../provider/Actions';
import {
eSendEvent,
eSubscribeEvent,
- eUnSubscribeEvent,
+ eUnSubscribeEvent
} from '../../services/EventManager';
-import {eOnNewTopicAdded, eScrollEvent, eUpdateSearchState} from '../../utils/Events';
-import NavigationService from '../../services/Navigation';
-import {db} from "../../utils/DB";
+import SearchService from '../../services/SearchService';
+import { db } from "../../utils/DB";
+import { eOnNewTopicAdded, eScrollEvent } from '../../utils/Events';
export const Notebook = ({route, navigation}) => {
const [, dispatch] = useTracked();
@@ -40,6 +38,7 @@ export const Notebook = ({route, navigation}) => {
}, []);
const onFocus = () => {
+ eSendEvent(eScrollEvent, {name: params.title, type: 'in'});
onLoad();
dispatch({
type: Actions.HEADER_TEXT_STATE,
@@ -59,11 +58,15 @@ export const Notebook = ({route, navigation}) => {
useEffect(() => {
navigation.addListener('focus', onFocus);
return () => {
+ eSendEvent(eScrollEvent, {name: params.title, type: 'back'});
navigation.removeListener('focus', onFocus);
};
});
+
+
+
useEffect(() => {
if (navigation.isFocused()) {
updateSearch();
@@ -71,18 +74,11 @@ export const Notebook = ({route, navigation}) => {
}, [topics]);
const updateSearch = () => {
- if (topics.length === 0) {
- eSendEvent('showSearch', true);
- } else {
- eSendEvent('showSearch');
- eSendEvent(eUpdateSearchState,{
- placeholder: `Search in "${params.title}"`,
- data: topics,
- noSearch: false,
- type: 'topics',
- color: null,
- })
- }
+ SearchService.update({
+ placeholder: `Search in "${params.title}"`,
+ data: topics,
+ type: 'topics',
+ });
};
@@ -102,7 +98,6 @@ export const Notebook = ({route, navigation}) => {
onLoad();
}}
focused={() => navigation.isFocused()}
- RenderItem={RenderItem}
placeholder={<></>}
placeholderText=""
/>
@@ -116,7 +111,7 @@ export const Notebook = ({route, navigation}) => {
};
export default Notebook;
-
+/*
const RenderItem = ({item, index}) => {
const [state, dispatch] = useTracked();
const {colors,selectionMode } = state;
@@ -155,3 +150,4 @@ const RenderItem = ({item, index}) => {
</SelectionWrapper>
);
};
+ */
\ No newline at end of file
diff --git a/apps/mobile/src/views/Notes/index.js b/apps/mobile/src/views/Notes/index.js
index fd772dc3c..26d718d2b 100644
--- a/apps/mobile/src/views/Notes/index.js
+++ b/apps/mobile/src/views/Notes/index.js
@@ -1,49 +1,27 @@
import React, {useCallback, useEffect, useState} from 'react';
-import {Placeholder} from '../../components/ListPlaceholders';
+import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';
import SimpleList from '../../components/SimpleList';
import {NoteItemWrapper} from '../../components/SimpleList/NoteItemWrapper';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
-import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';
+import {DDS} from '../../services/DeviceDetection';
import {
eSendEvent,
eSubscribeEvent,
eUnSubscribeEvent,
} from '../../services/EventManager';
-import {
- eOnLoadNote,
- eScrollEvent, eUpdateSearchState,
- refreshNotesPage,
-} from '../../utils/Events';
-import {openEditorAnimation} from '../../utils/Animations';
+import SearchService from '../../services/SearchService';
import {editing} from '../../utils';
-import {COLORS_NOTE} from "../../utils/Colors";
-import {db} from "../../utils/DB";
-import {DDS} from "../../services/DeviceDetection";
+import {COLORS_NOTE} from '../../utils/Colors';
+import {db} from '../../utils/DB';
+import {eOnLoadNote, eScrollEvent, refreshNotesPage} from '../../utils/Events';
+import {tabBarRef} from '../../utils/Refs';
export const Notes = ({route, navigation}) => {
const [state, dispatch] = useTracked();
- const {colorNotes} = state;
- const allNotes = state.notes;
const [notes, setNotes] = useState([]);
let params = route.params ? route.params : null;
- useEffect(() => {
- if (navigation.isFocused()) {
- if (!params) {
- params = {
- title: 'Notes',
- };
- }
- init();
- } else {
- setNotes([]);
- editing.actionAfterFirstSave = {
- type: null,
- };
- }
- }, [allNotes, colorNotes]);
-
useEffect(() => {
eSubscribeEvent(refreshNotesPage, init);
return () => {
@@ -55,13 +33,12 @@ export const Notes = ({route, navigation}) => {
}, []);
const init = (data) => {
- console.log('refreshing notes!');
+ console.log('rerendering');
params = route.params;
if (data) {
params = data;
}
let allNotes = [];
- eSendEvent(eScrollEvent, 0);
if (params.type === 'tag') {
allNotes = db.notes.tagged(params.tag.title);
} else if (params.type === 'color') {
@@ -96,6 +73,13 @@ export const Notes = ({route, navigation}) => {
};
const onFocus = useCallback(() => {
+ eSendEvent(eScrollEvent, {
+ name:
+ params.type === 'tag'
+ ? '#' + params.title
+ : params.title.slice(0, 1).toUpperCase() + params.title.slice(1),
+ type: 'in',
+ });
init();
}, []);
@@ -110,6 +94,16 @@ export const Notes = ({route, navigation}) => {
navigation.addListener('focus', onFocus);
navigation.addListener('blur', onBlur);
return () => {
+ eSendEvent(eScrollEvent, {
+ name:
+ params.type === 'tag'
+ ? '#' + params.title
+ : params.title.slice(0, 1).toUpperCase() + params.title.slice(1),
+ type: 'hide',
+ });
+ editing.actionAfterFirstSave = {
+ type: null,
+ };
navigation.removeListener('focus', onFocus);
navigation.removeListener('blur', onBlur);
};
@@ -122,24 +116,17 @@ export const Notes = ({route, navigation}) => {
}, [notes]);
const updateSearch = () => {
- if (notes.length === 0) {
- eSendEvent('showSearch', true);
- } else {
- eSendEvent('showSearch');
- eSendEvent(eUpdateSearchState,{
- placeholder: `Search in ${
- params.type === 'tag' ? '#' + params.title : params.title
- }`,
- data: notes,
- noSearch: false,
- type: 'notes',
- color: params.type === 'color' ? params.title : null,
- })
- }
+ SearchService.update({
+ placeholder: `Search in ${
+ params.type === 'tag' ? '#' + params.title : params.title
+ }`,
+ data: notes,
+ noSearch: false,
+ type: 'notes',
+ color: params.type === 'color' ? params.title : null,
+ });
};
-
-
const _onPressBottomButton = useCallback(() => {
if (params.type === 'tag') {
editing.actionAfterFirstSave = {
@@ -159,9 +146,10 @@ export const Notes = ({route, navigation}) => {
};
}
- eSendEvent(eOnLoadNote, {type: 'new'});
if (DDS.isPhone || DDS.isSmallTab) {
- openEditorAnimation();
+ tabBarRef.current?.goToPage(1);
+ } else {
+ eSendEvent(eOnLoadNote, {type: 'new'});
}
}, [params.type]);
@@ -175,10 +163,15 @@ export const Notes = ({route, navigation}) => {
}}
focused={() => navigation.isFocused()}
RenderItem={NoteItemWrapper}
- placeholder={<Placeholder type="notes" />}
placeholderText={`Add some notes to this" ${
params.type ? params.type : 'topic.'
}`}
+ placeholderData={{
+ heading: 'Your Notes',
+ paragraph: 'You have not added any notes yet.',
+ button: 'Add your First Note',
+ action: _onPressBottomButton,
+ }}
/>
<ContainerBottomButton
title="Create a new note"
diff --git a/apps/mobile/src/views/Settings/index.js b/apps/mobile/src/views/Settings/index.js
index 360139943..624d23d6e 100644
--- a/apps/mobile/src/views/Settings/index.js
+++ b/apps/mobile/src/views/Settings/index.js
@@ -204,6 +204,7 @@ export const Settings = ({navigation}) => {
backgroundColor: colors.bg,
}}>
<ScrollView
+
onScroll={(e) =>
eSendEvent(eScrollEvent, e.nativeEvent.contentOffset.y)
}
diff --git a/apps/mobile/src/views/Trash/index.js b/apps/mobile/src/views/Trash/index.js
index 46d9da497..5aead1f19 100644
--- a/apps/mobile/src/views/Trash/index.js
+++ b/apps/mobile/src/views/Trash/index.js
@@ -4,18 +4,18 @@ import {simpleDialogEvent} from '../../components/DialogManager/recievers';
import {TEMPLATE_EMPTY_TRASH} from '../../components/DialogManager/Templates';
import {Placeholder} from '../../components/ListPlaceholders';
import SimpleList from '../../components/SimpleList';
-import {NotebookItemWrapper} from '../../components/SimpleList/NotebookItemWrapper';
-import {NoteItemWrapper} from '../../components/SimpleList/NoteItemWrapper';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
-import {eSendEvent} from '../../services/EventManager';
-import {eUpdateSearchState} from '../../utils/Events';
+import { eSendEvent } from '../../services/EventManager';
+import SearchService from '../../services/SearchService';
+import { eScrollEvent } from '../../utils/Events';
export const Trash = ({route, navigation}) => {
const [state, dispatch] = useTracked();
const {trash} = state;
const onFocus = useCallback(() => {
+ eSendEvent(eScrollEvent, {name:'Trash', type: 'in'});
dispatch({
type: Actions.HEADER_STATE,
state: true,
@@ -40,6 +40,7 @@ export const Trash = ({route, navigation}) => {
useEffect(() => {
navigation.addListener('focus', onFocus);
return () => {
+ eSendEvent(eScrollEvent, {name:'Trash', type: 'back'});
navigation.removeListener('focus', onFocus);
};
});
@@ -51,18 +52,11 @@ export const Trash = ({route, navigation}) => {
}, [trash]);
const updateSearch = () => {
- if (trash.length === 0) {
- eSendEvent('showSearch', true);
- } else {
- eSendEvent('showSearch');
- eSendEvent(eUpdateSearchState, {
- placeholder: 'Search all trash',
- data: trash,
- noSearch: false,
- type: 'trash',
- color: null,
- });
- }
+ SearchService.update({
+ placeholder: 'Search in trash',
+ data: trash,
+ type: 'notes',
+ });
};
const _onPressBottomButton = () => simpleDialogEvent(TEMPLATE_EMPTY_TRASH);
@@ -73,7 +67,6 @@ export const Trash = ({route, navigation}) => {
data={trash}
type="trash"
focused={() => navigation.isFocused()}
- RenderItem={RenderItem}
placeholderData={{
heading: 'Your Favorites',
paragraph: 'You have not added any notes to favorites yet.',
@@ -94,12 +87,3 @@ export const Trash = ({route, navigation}) => {
};
export default Trash;
-
-const RenderItem = ({item, index}) => {
- console.log(item.itemType);
- return item.itemType === 'note' ? (
- <NoteItemWrapper item={item} index={index} isTrash={true} />
- ) : (
- <NotebookItemWrapper item={item} index={index} isTrash={true} />
- );
-};