A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix route state not updating on getting new changes
ammarahm-edf5a3d9370e80
diff --git a/apps/mobile/src/components/header/index.js b/apps/mobile/src/components/header/index.jsindex cbc578387..21990220d 100644--- a/apps/mobile/src/components/header/index.js+++ b/apps/mobile/src/components/header/index.js@@ -2,6 +2,7 @@ import React, { useEffect, useState } from 'react';import { Platform, StyleSheet, View } from 'react-native';import { useSafeAreaInsets } from 'react-native-safe-area-context';import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';+import { useSelectionStore } from '../../stores/use-selection-store';import { useThemeStore } from '../../stores/use-theme-store';import { eScrollEvent } from '../../utils/events';import { LeftMenus } from './left-menus';@@ -13,6 +14,7 @@ export const Header = React.memo(const colors = useThemeStore(state => state.colors);const insets = useSafeAreaInsets();const [hide, setHide] = useState(true);+ const selectionMode = useSelectionStore(state => state.selectionMode);const onScroll = data => {if (data.y > 150) {@@ -31,7 +33,7 @@ export const Header = React.memo(};}, [hide]);- return (+ return selectionMode ? null : (<Viewstyle={[styles.container,diff --git a/apps/mobile/src/components/list/card.js b/apps/mobile/src/components/list/card.jsindex 755dceb3c..9711d624e 100644--- a/apps/mobile/src/components/list/card.js+++ b/apps/mobile/src/components/list/card.js@@ -1,8 +1,6 @@import React from 'react';import { View } from 'react-native';-import Animated, { FadeInUp, FadeOutUp } from 'react-native-reanimated';import Icon from 'react-native-vector-icons/MaterialCommunityIcons';-import { useSelectionStore } from '../../stores/use-selection-store';import { useMessageStore } from '../../stores/use-message-store';import { useThemeStore } from '../../stores/use-theme-store';import { hexToRGBA } from '../../utils/color-scheme/utils';@@ -13,18 +11,14 @@ import Paragraph from '../ui/typography/paragraph';export const Card = ({ color, warning }) => {const colors = useThemeStore(state => state.colors);color = color ? color : colors.accent;-- const selectionMode = useSelectionStore(state => state.selectionMode);const messageBoardState = useMessageStore(state => state.message);const announcement = useMessageStore(state => state.announcement);- return !messageBoardState.visible || selectionMode || announcement || warning ? null : (- <Animated.View+ return !messageBoardState.visible || announcement || warning ? null : (+ <Viewstyle={{width: '95%'}}- entering={FadeInUp}- exiting={FadeOutUp}><PressableButtononPress={messageBoardState.onPress}@@ -95,6 +89,6 @@ export const Card = ({ color, warning }) => {/></View></PressableButton>- </Animated.View>+ </View>);};diff --git a/apps/mobile/src/components/list/index.js b/apps/mobile/src/components/list/index.jsindex 632e5d304..b1ce4fb6f 100644--- a/apps/mobile/src/components/list/index.js+++ b/apps/mobile/src/components/list/index.js@@ -1,5 +1,6 @@import React, { useEffect, useRef, useState } from 'react';-import { FlatList, RefreshControl, View } from 'react-native';+import { RefreshControl, View } from 'react-native';+import Animated from 'react-native-reanimated';import { notesnook } from '../../../e2e/test.ids';import { eSendEvent } from '../../services/event-manager';import Sync from '../../services/sync';@@ -69,7 +70,6 @@ const List = ({useEffect(() => {let timeout = null;if (!loading) {- console.log('LOADING ENDED');timeout = setTimeout(() => {_setLoading(false);@@ -77,7 +77,6 @@ const List = ({listData.length === 0 ? 0 : 300);} else {- console.log('STILL LOADING');_setLoading(true);}return () => {@@ -129,7 +128,7 @@ const List = ({return (<>- <FlatList+ <Animated.FlatListstyle={styles}keyExtractor={_keyExtractor}ref={scrollRef}diff --git a/apps/mobile/src/components/listitems/headers/header.js b/apps/mobile/src/components/listitems/headers/header.jsindex 35ff16d37..9ad6a0a4d 100644--- a/apps/mobile/src/components/listitems/headers/header.js+++ b/apps/mobile/src/components/listitems/headers/header.js@@ -6,15 +6,17 @@ import { COLORS_NOTE } from '../../../utils/color-scheme';import { Announcement } from '../../announcements/announcement';import { Card } from '../../list/card';import Paragraph from '../../ui/typography/paragraph';-import Icon from 'react-native-vector-icons/MaterialCommunityIcons';import { SIZE } from '../../../utils/size';+import { useSelectionStore } from '../../../stores/use-selection-store';+import Animated, { FadeInUp, FadeOutUp } from 'react-native-reanimated';export const Header = React.memo(({ type, messageCard = true, color, shouldShow = false, noAnnouncement, warning }) => {const colors = useThemeStore(state => state.colors);const announcements = useMessageStore(state => state.announcements);+ const selectionMode = useSelectionStore(state => state.selectionMode);- return (+ return selectionMode ? null : (<>{warning ? (<View@@ -36,7 +38,9 @@ export const Header = React.memo() : announcements.length !== 0 && !noAnnouncement ? (<Announcement color={color || colors.accent} />) : type === 'search' ? null : !shouldShow ? (- <View+ <Animated.View+ entering={FadeInUp.delay(500)}+ exiting={FadeOutUp}style={{marginBottom: 5,padding: 0,@@ -48,7 +52,7 @@ export const Header = React.memo({messageCard ? (<Card color={COLORS_NOTE[color?.toLowerCase()] || colors.accent} />) : null}- </View>+ </Animated.View>) : null}</>);diff --git a/apps/mobile/src/components/tabs/index.tsx b/apps/mobile/src/components/tabs/index.tsxindex 200549398..516c75db7 100644--- a/apps/mobile/src/components/tabs/index.tsx+++ b/apps/mobile/src/components/tabs/index.tsx@@ -126,7 +126,7 @@ export const NewTabs = forwardRef<TabsRef, TabProps>(const gesture = Gesture.Pan().maxPointers(1).enabled(enabled)- .activeOffsetX([-20, 20])+ .activeOffsetX([-10, 10]).failOffsetY([-10, 10]).onBegin(event => {locked.value = false;diff --git a/apps/mobile/src/screens/trash/index.tsx b/apps/mobile/src/screens/trash/index.tsxindex be0965b19..694864d82 100644--- a/apps/mobile/src/screens/trash/index.tsx+++ b/apps/mobile/src/screens/trash/index.tsx@@ -57,6 +57,9 @@ export const Trash = ({ navigation, route }: NavigationProps<'Trash'>) => {useNavigationStore.getState().update({name: route.name});+ if (useTrashStore.getState().trash.length === 0) {+ useTrashStore.getState().setTrash();+ }SearchService.prepareSearch = prepareSearch;return !prev?.current;},diff --git a/apps/mobile/src/services/navigation.ts b/apps/mobile/src/services/navigation.tsindex 46da6ae54..bb9049e1b 100755--- a/apps/mobile/src/services/navigation.ts+++ b/apps/mobile/src/services/navigation.ts@@ -69,13 +69,13 @@ export type NavigationProps<T extends RouteName> = BottomTabScreenProps<RoutePar* Functions to update each route when required.*/const routeUpdateFunctions: { [name: string]: (...args: any[]) => void } = {- Notes: useNoteStore.getState().setNotes,- Notebooks: useNotebookStore.getState().setNotebooks,- Tags: useTagStore.getState().setTags,- Favorites: useFavoriteStore.getState().setFavorites,- Trash: useTrashStore.getState().setTrash,+ Notes: () => useNoteStore.getState().setNotes(),+ Notebooks: () => useNotebookStore.getState().setNotebooks(),+ Tags: () => useTagStore.getState().setTags(),+ Favorites: () => useFavoriteStore.getState().setFavorites(),+ Trash: () => useTrashStore.getState().setTrash(),Notebook: (params: NotebookScreenParams) => eSendEvent(eOnNewTopicAdded, params),- NotesPage: (params: NotesScreenParams) => eSendEvent(refreshNotesPage, params),+ NotesPage: (params: NotesScreenParams) => eSendEvent('NotesPage', params),TaggedNotes: (params: NotesScreenParams) => eSendEvent('TaggedNotes', params),ColoredNotes: (params: NotesScreenParams) => eSendEvent('ColoredNotes', params),TopicNotes: (params: NotesScreenParams) => eSendEvent('TopicNotes', params),@@ -93,6 +93,7 @@ function clearRouteFromQueue(routeName: Route) {* Check if a route needs update*/function routeNeedsUpdate(routeName: Route, callback: () => void) {+ console.log('routeName', routesUpdateQueue);if (routesUpdateQueue.indexOf(routeName) > -1) {clearRouteFromQueue(routeName);callback();@@ -100,16 +101,17 @@ function routeNeedsUpdate(routeName: Route, callback: () => void) {}function queueRoutesForUpdate(...routes: Route[]) {+ console.log('updating routes', routes);const currentScreen = useNavigationStore.getState().currentScreen;- const routeHistory = rootNavigatorRef.getState().routes;-+ const routeHistory = rootNavigatorRef.getState()?.history || [{ key: currentScreen.name }];// filter out routes that are not rendered to prevent unnecessary updatesroutes = routes.filter(//@ts-ignore- routeName => routeHistory?.findIndex(route => route.name === routeName) > -1+ routeName => routeHistory?.findIndex(route => route.key?.startsWith(routeName)) > -1);-+ console.log('routes to update: ', routes, routeHistory, currentScreen.name);if (routes.indexOf(currentScreen.name) > -1) {+ console.log('updating current route');routeUpdateFunctions[currentScreen.name]();clearRouteFromQueue(currentScreen.name);// Remove focused screen from queuediff --git a/apps/mobile/src/stores/useNotesStore.ts b/apps/mobile/src/stores/useNotesStore.tsindex aca1b94d3..475d61178 100644--- a/apps/mobile/src/stores/useNotesStore.ts+++ b/apps/mobile/src/stores/useNotesStore.ts@@ -16,7 +16,9 @@ export const useNoteStore = create<NoteStore>((set, get) => ({notes: [],loading: true,setLoading: loading => set({ loading: loading }),+setNotes: items => {+ console.log('UPDATING NOTES');if (!items) {set({notes: groupArray((db.notes?.all as NoteType[]) || [], db.settings?.getGroupOptions('home'))diff --git a/apps/mobile/src/utils/functions.js b/apps/mobile/src/utils/functions.jsindex 317bf008d..3121d03cf 100644--- a/apps/mobile/src/utils/functions.js+++ b/apps/mobile/src/utils/functions.js@@ -50,7 +50,8 @@ export const deleteItems = async item => {'ColoredNotes','TopicNotes','Favorites',- 'Notes'+ 'Notes',+ 'Trash');eSendEvent(eClearEditor);}@@ -80,7 +81,8 @@ export const deleteItems = async item => {'TopicNotes','Favorites','Notes',- 'Notebooks'+ 'Notebooks',+ 'Trash');useMenuStore.getState().setMenuPins();}diff --git a/apps/mobile/src/utils/hooks/useActions.js b/apps/mobile/src/utils/hooks/useActions.jsindex ce7031937..a36566bef 100644--- a/apps/mobile/src/utils/hooks/useActions.js+++ b/apps/mobile/src/utils/hooks/useActions.js@@ -193,7 +193,8 @@ export const useActions = ({ close = () => {}, item }) => {'TopicNotes','Favorites','Notes',- 'Notebooks'+ 'Notebooks',+ 'Trash');let type = item.type === 'trash' ? item.itemType : item.type;ToastEvent.show({