diff --git a/src/RootStackParamList.tsx b/src/RootStackParamList.tsx index 8596c42..652067d 100644 --- a/src/RootStackParamList.tsx +++ b/src/RootStackParamList.tsx @@ -5,9 +5,15 @@ export type RootStackParamList = { Home: undefined; Login: undefined; Signup: undefined; - CollectionCreate: undefined; + CollectionCreate: { + goBack: boolean; + colUid?: undefined; + } | undefined; Collection: { colUid: string }; - CollectionEdit: { colUid: string }; + CollectionEdit: { + colUid: string; + goBack?: boolean; + }; CollectionChangelog: { colUid: string }; CollectionMembers: { colUid: string }; NoteCreate: { diff --git a/src/screens/CollectionEditScreen.tsx b/src/screens/CollectionEditScreen.tsx index 52551af..f7ed093 100644 --- a/src/screens/CollectionEditScreen.tsx +++ b/src/screens/CollectionEditScreen.tsx @@ -5,7 +5,7 @@ import * as React from "react"; import { useSelector } from "react-redux"; import { TextInput as NativeTextInput } from "react-native"; import { Text, HelperText, Button, Appbar, Paragraph } from "react-native-paper"; -import { useNavigation, RouteProp, useNavigationState, CommonActions } from "@react-navigation/native"; +import { useNavigation, RouteProp, useNavigationState } from "@react-navigation/native"; import { StackNavigationProp } from "@react-navigation/stack"; import { SyncManager } from "../sync/SyncManager"; @@ -47,7 +47,7 @@ export default function CollectionEditScreen(props: PropsType) { const cacheCollections = useSelector((state: StoreState) => state.cache.collections); const syncGate = useSyncGate(); const navigation = useNavigation(); - const navigationState = useNavigationState((state) => (state.index > 0) ? state.routes[state.index - 1] : null); + const previousScreen = useNavigationState((state) => (state.index > 0) ? state.routes[state.index - 1].name as keyof RootStackParamList : undefined); const etebase = useCredentials()!; const [loading, error, setPromise] = useLoading(); const colType = C.colType; @@ -126,13 +126,10 @@ export default function CollectionEditScreen(props: PropsType) { } else { dispatch(pushMessage({ message: "Notebook created", severity: "success" })); - const previousScreen = navigationState?.name; - if (navigationState && previousScreen === "NoteCreate") { - // We change the colUid - navigation.dispatch({ - ...CommonActions.setParams({ colUid: collection.uid }), - source: navigationState.key, - }); + const goBack = props.route.params?.goBack; + if (goBack && previousScreen) { + // We send back the colUid + navigation.navigate(previousScreen, { colUid: collection.uid }); } else { // We're gonna navigate to the notebook's page navigation.replace("Collection", { colUid: collection.uid }); diff --git a/src/screens/NotePropertiesScreen.tsx b/src/screens/NotePropertiesScreen.tsx index d5f1efb..0b1904b 100644 --- a/src/screens/NotePropertiesScreen.tsx +++ b/src/screens/NotePropertiesScreen.tsx @@ -202,7 +202,7 @@ export default function NotePropertiesScreen(props: PropsType) { disabled={!!itemUid} icon="plus" iconAccessibilityLabel="Create Notebook" - iconOnPress={() => navigation.navigate("CollectionCreate")} + iconOnPress={() => navigation.navigate("CollectionCreate", { goBack: true })} /> )}