optimize moving note performance

This commit is contained in:
ammarahm-ed
2021-02-15 11:09:01 +05:00
parent d6b138ab14
commit 7be721badb

View File

@@ -12,6 +12,7 @@ import {
sendNoteEditedEvent, sendNoteEditedEvent,
ToastEvent, ToastEvent,
} from '../../services/EventManager'; } from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import {db} from '../../utils/DB'; import {db} from '../../utils/DB';
import { import {
eOnNewTopicAdded, eOnNewTopicAdded,
@@ -36,7 +37,7 @@ const MoveNoteDialog = () => {
const [, dispatch] = useTracked(); const [, dispatch] = useTracked();
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const [note, setNote] = useState(null); const [note, setNote] = useState(null);
function open(note) { function open(note) {
setNote(note); setNote(note);
setVisible(true); setVisible(true);
@@ -58,11 +59,14 @@ const MoveNoteDialog = () => {
newTopicTitle = null; newTopicTitle = null;
newNotebookTitle = null; newNotebookTitle = null;
setNote(null); setNote(null);
eSendEvent(refreshNotesPage); Navigation.setRoutesToUpdate([
eSendEvent(eOnNewTopicAdded); Navigation.routeNames.Notes,
Navigation.routeNames.Favorites,
Navigation.routeNames.NotesPage,
Navigation.routeNames.Notebook,
Navigation.routeNames.Notebooks,
]);
dispatch({type: Actions.CLEAR_SELECTION}); dispatch({type: Actions.CLEAR_SELECTION});
dispatch({type: Actions.NOTEBOOKS});
dispatch({type: Actions.NOTES});
}; };
const update = (note) => { const update = (note) => {
@@ -97,7 +101,7 @@ const MoveNoteComponent = ({close, note, setNote}) => {
}); });
notebookInput.current?.clear(); notebookInput.current?.clear();
notebookInput.current?.blur(); notebookInput.current?.blur();
dispatch({type: Actions.NOTEBOOKS}); Navigation.setRoutesToUpdate([Navigation.routeNames.Notebooks]);
}; };
const addNewTopic = async () => { const addNewTopic = async () => {
@@ -105,7 +109,7 @@ const MoveNoteComponent = ({close, note, setNote}) => {
return ToastEvent.show('Title is required', 'error', 'local'); return ToastEvent.show('Title is required', 'error', 'local');
} }
await db.notebooks.notebook(expanded).topics.add(newTopicTitle); await db.notebooks.notebook(expanded).topics.add(newTopicTitle);
dispatch({type: Actions.NOTEBOOKS}); Navigation.setRoutesToUpdate([Navigation.routeNames.Notebooks]);
topicInput.current?.clear(); topicInput.current?.clear();
topicInput.current?.blur(); topicInput.current?.blur();
newTopicTitle = null; newTopicTitle = null;
@@ -132,7 +136,7 @@ const MoveNoteComponent = ({close, note, setNote}) => {
forced: true, forced: true,
}); });
} }
dispatch({type: Actions.NOTEBOOKS}); Navigation.setRoutesToUpdate([Navigation.routeNames.Notebooks]);
return; return;
} }
@@ -155,7 +159,7 @@ const MoveNoteComponent = ({close, note, setNote}) => {
forced: true, forced: true,
}); });
} }
dispatch({type: Actions.NOTEBOOKS}); Navigation.setRoutesToUpdate([Navigation.routeNames.Notebooks]);
}; };
return ( return (
@@ -426,8 +430,8 @@ const MoveNoteComponent = ({close, note, setNote}) => {
{item.title} {item.title}
</Paragraph> </Paragraph>
<Paragraph color={colors.icon} size={SIZE.xs}> <Paragraph color={colors.icon} size={SIZE.xs}>
{item.totalNotes + ' notes'} {item.totalNotes + ' notes'}
</Paragraph> </Paragraph>
</View> </View>
{note?.notebooks?.findIndex( {note?.notebooks?.findIndex(
(o) => o.topics.indexOf(item.id) > -1, (o) => o.topics.indexOf(item.id) > -1,