update state in move note dialog

This commit is contained in:
ammarahm-ed
2021-02-22 09:59:34 +05:00
parent 1b853019c2
commit 572a3aafd6

View File

@@ -6,7 +6,6 @@ import {notesnook} from '../../../e2e/test.ids';
import {useTracked} from '../../provider'; import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions'; import {Actions} from '../../provider/Actions';
import { import {
eSendEvent,
eSubscribeEvent, eSubscribeEvent,
eUnSubscribeEvent, eUnSubscribeEvent,
sendNoteEditedEvent, sendNoteEditedEvent,
@@ -14,17 +13,12 @@ import {
} from '../../services/EventManager'; } from '../../services/EventManager';
import Navigation from '../../services/Navigation'; import Navigation from '../../services/Navigation';
import {db} from '../../utils/DB'; import {db} from '../../utils/DB';
import { import {eOpenMoveNoteDialog} from '../../utils/Events';
eOnNewTopicAdded,
eOpenMoveNoteDialog,
refreshNotesPage,
} from '../../utils/Events';
import {pv, SIZE} from '../../utils/SizeUtils'; import {pv, SIZE} from '../../utils/SizeUtils';
import ActionSheetWrapper from '../ActionSheetComponent/ActionSheetWrapper'; import ActionSheetWrapper from '../ActionSheetComponent/ActionSheetWrapper';
import {Button} from '../Button'; import {Button} from '../Button';
import DialogHeader from '../Dialog/dialog-header'; import DialogHeader from '../Dialog/dialog-header';
import {PressableButton} from '../PressableButton'; import {PressableButton} from '../PressableButton';
import {Toast} from '../Toast';
import Heading from '../Typography/Heading'; import Heading from '../Typography/Heading';
import Paragraph from '../Typography/Paragraph'; import Paragraph from '../Typography/Paragraph';
@@ -84,7 +78,7 @@ export default MoveNoteDialog;
const MoveNoteComponent = ({close, note, setNote}) => { const MoveNoteComponent = ({close, note, setNote}) => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
const {colors, selectedItemsList} = state; const {colors, selectedItemsList, notebooks} = state;
const [expanded, setExpanded] = useState(''); const [expanded, setExpanded] = useState('');
const [notebookInputFocused, setNotebookInputFocused] = useState(false); const [notebookInputFocused, setNotebookInputFocused] = useState(false);
const [topicInputFocused, setTopicInputFocused] = useState(false); const [topicInputFocused, setTopicInputFocused] = useState(false);
@@ -105,7 +99,7 @@ const MoveNoteComponent = ({close, note, setNote}) => {
}); });
notebookInput.current?.clear(); notebookInput.current?.clear();
notebookInput.current?.blur(); notebookInput.current?.blur();
Navigation.setRoutesToUpdate([Navigation.routeNames.Notebooks]); dispatch({type: Actions.NOTEBOOKS});
}; };
const addNewTopic = async () => { const addNewTopic = async () => {
@@ -117,7 +111,7 @@ const MoveNoteComponent = ({close, note, setNote}) => {
}); });
} }
await db.notebooks.notebook(expanded).topics.add(newTopicTitle); await db.notebooks.notebook(expanded).topics.add(newTopicTitle);
Navigation.setRoutesToUpdate([Navigation.routeNames.Notebooks]); dispatch({type: Actions.NOTEBOOKS});
topicInput.current?.clear(); topicInput.current?.clear();
topicInput.current?.blur(); topicInput.current?.blur();
newTopicTitle = null; newTopicTitle = null;
@@ -144,7 +138,7 @@ const MoveNoteComponent = ({close, note, setNote}) => {
forced: true, forced: true,
}); });
} }
Navigation.setRoutesToUpdate([Navigation.routeNames.Notebooks]); dispatch({type: Actions.NOTEBOOKS});
return; return;
} }
@@ -167,7 +161,7 @@ const MoveNoteComponent = ({close, note, setNote}) => {
forced: true, forced: true,
}); });
} }
Navigation.setRoutesToUpdate([Navigation.routeNames.Notebooks]); dispatch({type: Actions.NOTEBOOKS});
}; };
return ( return (
@@ -208,7 +202,7 @@ const MoveNoteComponent = ({close, note, setNote}) => {
}} }}
keyboardShouldPersistTaps="always" keyboardShouldPersistTaps="always"
keyboardDismissMode="none" keyboardDismissMode="none"
data={state.notebooks} data={notebooks}
ListFooterComponent={ ListFooterComponent={
<View <View
style={{ style={{