From 659ab2a96b860efb4443f39e6c4336c58adfab34 Mon Sep 17 00:00:00 2001 From: noodleofdeath Date: Fri, 6 Oct 2023 14:49:59 -0400 Subject: [PATCH] feat(RL-104): more deeplinks --- .../src/components/common/RoutedScreen.tsx | 2 +- src/mobile/src/hooks/useNavigation.tsx | 26 ++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/mobile/src/components/common/RoutedScreen.tsx b/src/mobile/src/components/common/RoutedScreen.tsx index 832b3a25..443206b1 100644 --- a/src/mobile/src/components/common/RoutedScreen.tsx +++ b/src/mobile/src/components/common/RoutedScreen.tsx @@ -5,7 +5,7 @@ import { useFocusEffect } from '@react-navigation/native'; import { Screen, ScreenProps } from '~/components'; import { SessionContext } from '~/contexts'; -import { useNavigation, useTheme } from '~/hooks'; +import { useNavigation } from '~/hooks'; export function RoutedScreen({ ...props }: ScreenProps) { diff --git a/src/mobile/src/hooks/useNavigation.tsx b/src/mobile/src/hooks/useNavigation.tsx index 6fd00af1..345e4ba5 100644 --- a/src/mobile/src/hooks/useNavigation.tsx +++ b/src/mobile/src/hooks/useNavigation.tsx @@ -20,13 +20,13 @@ export function useNavigation() { const { preferredReadingFormat, setPreference } = React.useContext(SessionContext); - const navigate = React.useCallback((route: R, params?: RoutingParams[R], navigator?: NativeStackNavigationProp) => { + const navigate = React.useCallback((route: R, params?: RoutingParams[R], navigator?: any) => { emitEvent('navigate', route); // eslint-disable-next-line @typescript-eslint/no-explicit-any return (navigator?.push ?? (navigation as any).push ?? navigation.navigate)(route, params as RoutingParams[R]); }, [emitEvent, navigation]); - const search = React.useCallback((params: RoutingParams['search'], navigator?: NativeStackNavigationProp) => { + const search = React.useCallback((params: RoutingParams['search'], navigator?: any) => { const prefilter = params.prefilter; if (!prefilter) { return; @@ -35,7 +35,7 @@ export function useNavigation() { navigate('search', params, navigator); }, [navigate, setPreference]); - const openSummary = React.useCallback((props: RoutingParams['summary'], navigator?: NativeStackNavigationProp) => { + const openSummary = React.useCallback((props: RoutingParams['summary'], navigator?: any) => { navigate('summary', { ...props, initialFormat: props.initialFormat ?? preferredReadingFormat ?? ReadingFormat.Bullets, @@ -50,7 +50,7 @@ export function useNavigation() { navigate('category', { category }); }, [navigate]); - const router = React.useCallback(({ url, navigator }: { url: string, navigator?: NativeStackNavigationProp }) => { + const router = React.useCallback(({ url, navigator }: { url: string, navigator?: any }) => { // http://localhost:6969/read/?s=158&f=casual // https://dev.readless.ai/read/?s=158&f=casual // https://www.readless.ai/read/?s=4070&f=bullets @@ -79,8 +79,22 @@ export function useNavigation() { return; } search({ prefilter: filter }, navigator); - } - }, [search, openSummary]); + } else + if (route === 'publisher') { + const publisher = params['publisher']?.trim(); + if (!publisher) { + return; + } + openPublisher({ name: publisher }); + } else + if (route === 'category') { + const category = params['category']?.trim(); + if (!category) { + return; + } + openCategory({ name: category }); + } + }, [navigation, search, openSummary, openPublisher, openCategory]); return { navigate,