Skip to content

Commit

Permalink
feat(RL-104): more deeplinks
Browse files Browse the repository at this point in the history
  • Loading branch information
NoodleOfDeath committed Oct 6, 2023
1 parent f193186 commit 659ab2a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/mobile/src/components/common/RoutedScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
26 changes: 20 additions & 6 deletions src/mobile/src/hooks/useNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ export function useNavigation() {

const { preferredReadingFormat, setPreference } = React.useContext(SessionContext);

const navigate = React.useCallback(<R extends keyof RoutingParams>(route: R, params?: RoutingParams[R], navigator?: NativeStackNavigationProp<RoutingParams>) => {
const navigate = React.useCallback(<R extends keyof RoutingParams>(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<RoutingParams>) => {
const search = React.useCallback((params: RoutingParams['search'], navigator?: any) => {
const prefilter = params.prefilter;
if (!prefilter) {
return;
Expand All @@ -35,7 +35,7 @@ export function useNavigation() {
navigate('search', params, navigator);
}, [navigate, setPreference]);

const openSummary = React.useCallback((props: RoutingParams['summary'], navigator?: NativeStackNavigationProp<RoutingParams>) => {
const openSummary = React.useCallback((props: RoutingParams['summary'], navigator?: any) => {
navigate('summary', {
...props,
initialFormat: props.initialFormat ?? preferredReadingFormat ?? ReadingFormat.Bullets,
Expand All @@ -50,7 +50,7 @@ export function useNavigation() {
navigate('category', { category });
}, [navigate]);

const router = React.useCallback(({ url, navigator }: { url: string, navigator?: NativeStackNavigationProp<RoutingParams> }) => {
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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 659ab2a

Please sign in to comment.