Skip to content

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

minor refactor

ammarahm-eddf9de4146e38
diff --git a/apps/mobile/src/components/SimpleList/NoteItemWrapper.js b/apps/mobile/src/components/SimpleList/NoteItemWrapper.js
index 60e665c56..39e6584da 100644
--- a/apps/mobile/src/components/SimpleList/NoteItemWrapper.js
+++ b/apps/mobile/src/components/SimpleList/NoteItemWrapper.js
@@ -3,107 +3,111 @@ import NoteItem from '../../components/NoteItem';
import SelectionWrapper from '../../components/SelectionWrapper';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
-import {eSendEvent, eSubscribeEvent, eUnSubscribeEvent, openVault} from '../../services/EventManager';
+import {
+ eSendEvent,
+ eSubscribeEvent,
+ eUnSubscribeEvent,
+ openVault,
+} from '../../services/EventManager';
import {eShowMergeDialog, eOnLoadNote, eOnNoteEdited} from '../../utils/Events';
import {simpleDialogEvent} from '../DialogManager/recievers';
import {TEMPLATE_TRASH} from '../DialogManager/Templates';
-import {openEditorAnimation} from '../../utils/Animations';
-import {db} from "../../utils/DB";
-import {DDS} from "../../services/DeviceDetection";
-
-
+import {db} from '../../utils/DB';
+import {DDS} from '../../services/DeviceDetection';
+import { tabBarRef } from '../../utils/Refs';
export const NoteItemWrapper = ({
- item,
- index,
- isTrash = false,
- pinned = false,
- }) => {
- const [state, dispatch] = useTracked();
- const {colors, selectionMode} = state;
- const [note, setNote] = useState(item);
- const [editing, setEditing] = useState(false);
+ item,
+ index,
+ isTrash = false,
+}) => {
+ const [state, dispatch] = useTracked();
+ const {colors, selectionMode} = state;
+ const [note, setNote] = useState(item);
+ const [editing, setEditing] = useState(false);
- useEffect(() => {
- setNote(item);
- },[item])
+ useEffect(() => {
+ setNote(item);
+ }, [item]);
- const onNoteChange = (data) => {
- if (data.id !== note.id || data.closed) {
- if (editing) {
- setEditing(false);
- }
- return;
- }
- if (!editing && !data.noEdit) {
- setEditing(true);
- }
- let newNote = db.notes.note(data.id).data;
-
- if (!data.noEdit && newNote.title === note.title && newNote.headline === note.headline) {
- return;
- }
- setNote(newNote);
+ const onNoteChange = (data) => {
+ if (data.id !== note.id || data.closed) {
+ if (editing) {
+ setEditing(false);
+ }
+ return;
}
+ if (!editing && !data.noEdit) {
+ setEditing(true);
+ }
+ let newNote = db.notes.note(data.id).data;
- useEffect(() => {
- eSubscribeEvent(eOnNoteEdited , onNoteChange);
- return () => {
- eUnSubscribeEvent(eOnNoteEdited , onNoteChange);
- }
- }, [editing,note]);
-
- const style = useMemo(() => {
- return {width: selectionMode ? '90%' : '100%', marginHorizontal: 0};
- }, [selectionMode]);
-
+ if (
+ !data.noEdit &&
+ newNote.title === note.title &&
+ newNote.headline === note.headline
+ ) {
+ return;
+ }
+ setNote(newNote);
+ };
- const onLongPress = () => {
- if (!selectionMode) {
- dispatch({type: Actions.SELECTION_MODE, enabled: true});
- }
- dispatch({type: Actions.SELECTED_ITEMS, item: note});
+ useEffect(() => {
+ eSubscribeEvent(eOnNoteEdited, onNoteChange);
+ return () => {
+ eUnSubscribeEvent(eOnNoteEdited, onNoteChange);
};
+ }, [editing, note]);
- const onPress = async (event) => {
- if (note.conflicted) {
- eSendEvent(eShowMergeDialog, note);
- return;
- }
- if (selectionMode) {
- onLongPress();
- return;
- } else if (note.locked) {
- openVault(item, true, true, false, true, false);
- return;
- }
- if (isTrash) {
- simpleDialogEvent(TEMPLATE_TRASH(note.type));
- } else {
- eSendEvent(eOnLoadNote, note);
- }
- if (DDS.isPhone || DDS.isSmallTab) {
- openEditorAnimation(event.nativeEvent);
- }
- };
+ const style = useMemo(() => {
+ return {width: selectionMode ? '90%' : '100%', marginHorizontal: 0};
+ }, [selectionMode]);
+
+ const onLongPress = () => {
+ if (!selectionMode) {
+ dispatch({type: Actions.SELECTION_MODE, enabled: true});
+ }
+ dispatch({type: Actions.SELECTED_ITEMS, item: note});
+ };
+ const onPress = async (event) => {
+ if (note.conflicted) {
+ eSendEvent(eShowMergeDialog, note);
+ return;
+ }
+ if (selectionMode) {
+ onLongPress();
+ return;
+ } else if (note.locked) {
+ openVault(item, true, true, false, true, false);
+ return;
+ }
+ if (isTrash) {
+ simpleDialogEvent(TEMPLATE_TRASH(note.type));
+ } else {
+ eSendEvent(eOnLoadNote, note);
+ }
+ if (DDS.isPhone || DDS.isSmallTab) {
+ tabBarRef.current?.goToPage(1);
+ //openEditorAnimation(event.nativeEvent);
+ }
+ };
- return (
- <SelectionWrapper
- index={index}
- pinned={pinned}
- onLongPress={onLongPress}
- onPress={onPress}
- currentEditingNote={editing}
- item={note}>
- <NoteItem
- colors={colors}
- customStyle={style}
- currentEditingNote={editing}
- selectionMode={selectionMode}
- item={note}
- isTrash={isTrash}
- />
- </SelectionWrapper>
- );
-}
+ return (
+ <SelectionWrapper
+ index={index}
+ onLongPress={onLongPress}
+ onPress={onPress}
+ currentEditingNote={editing}
+ item={note}>
+ <NoteItem
+ colors={colors}
+ customStyle={style}
+ currentEditingNote={editing}
+ selectionMode={selectionMode}
+ item={note}
+ isTrash={isTrash}
+ />
+ </SelectionWrapper>
+ );
+};
diff --git a/apps/mobile/src/components/SimpleList/NotebookItemWrapper.js b/apps/mobile/src/components/SimpleList/NotebookItemWrapper.js
index 6427be430..e69734910 100644
--- a/apps/mobile/src/components/SimpleList/NotebookItemWrapper.js
+++ b/apps/mobile/src/components/SimpleList/NotebookItemWrapper.js
@@ -10,6 +10,7 @@ export const NotebookItemWrapper = ({
index,
isTrash = false,
pinned = false,
+ isTopic,
}) => {
const [state, dispatch] = useTracked();
const {selectionMode, preventDefaultMargins} = state;
@@ -37,6 +38,14 @@ export const NotebookItemWrapper = ({
onLongPress();
return;
}
+
+ if (isTopic) {
+ NavigationService.navigate('NotesPage', {
+ ...item,
+ });
+ return;
+ }
+
dispatch({
type: Actions.HEADER_TEXT_STATE,
state: {
@@ -45,7 +54,7 @@ export const NotebookItemWrapper = ({
});
dispatch({
type: Actions.HEADER_STATE,
- state:false,
+ state: false,
});
NavigationService.navigate('Notebook', {
@@ -64,7 +73,7 @@ export const NotebookItemWrapper = ({
item={item}>
<NotebookItem
hideMore={preventDefaultMargins}
- isTopic={item.type === 'topic'}
+ isTopic={isTopic}
customStyle={style}
item={item}
index={index}