diff --git a/oxlint-suppressions.json b/oxlint-suppressions.json index cce0cb762..bc3698767 100644 --- a/oxlint-suppressions.json +++ b/oxlint-suppressions.json @@ -656,11 +656,6 @@ "count": 1 } }, - "src/lib/routes/types.ts": { - "typescript/no-explicit-any": { - "count": 1 - } - }, "src/lib/sharing.ts": { "typescript/no-floating-promises": { "count": 1 diff --git a/src/Navigation.tsx b/src/Navigation.tsx index ec62e60f2..c13f857a5 100644 --- a/src/Navigation.tsx +++ b/src/Navigation.tsx @@ -1101,7 +1101,6 @@ function RoutesContainer({children}: React.PropsWithChildren<{}>) { ) { // chat-added-to-group routes to the convo because the recipient was // just added and now has access. - // @ts-expect-error nested navigators aren't typed -sfn void navigate('MessagesTab', { screen: 'Messages', params: { @@ -1111,7 +1110,6 @@ function RoutesContainer({children}: React.PropsWithChildren<{}>) { } else { // chat-removed-from-group, chat-join-request-rejected: the convo is // no longer accessible to the recipient, so just open the list. - // @ts-expect-error nested navigators aren't typed -sfn void navigate('MessagesTab', {screen: 'Messages'}) } }, @@ -1166,7 +1164,7 @@ function RoutesContainer({children}: React.PropsWithChildren<{}>) { notyLogger.debug(`handlePushNotificationEntry: default navigate`) } else if (path) { const [screen, params] = router.matchPath(path) - // @ts-expect-error nested navigators aren't typed -sfn + // @ts-expect-error router.matchPath does not correlate screen names with params void navigate('HomeTab', {screen, params}) notyLogger.debug(`handlePushNotificationEntry: navigate`, { screen, diff --git a/src/components/dialogs/nuxs/GroupChatsAnnouncement.tsx b/src/components/dialogs/nuxs/GroupChatsAnnouncement.tsx index 4cdf4a2cc..73e0cdf49 100644 --- a/src/components/dialogs/nuxs/GroupChatsAnnouncement.tsx +++ b/src/components/dialogs/nuxs/GroupChatsAnnouncement.tsx @@ -79,7 +79,6 @@ export function GroupChatsAnnouncement() { navigation.navigate('Messages', {pushToNewGroupChat: true}) } else { // On native, Messages is nested inside MessagesTab. - // @ts-expect-error nested navigators aren't typed -sfn navigation.navigate('MessagesTab', { screen: 'Messages', params: {pushToNewGroupChat: true}, diff --git a/src/lib/routes/router.ts b/src/lib/routes/router.ts index c74192f29..91782ca9f 100644 --- a/src/lib/routes/router.ts +++ b/src/lib/routes/router.ts @@ -56,16 +56,17 @@ function createRoute(pattern: string): Route { return undefined }, build(params = {}) { - const str = pattern.replace( - /:([\w]+)/g, - (_m, name) => params[encodeURIComponent(name)] || 'undefined', - ) + const str = pattern.replace(/:([\w]+)/g, (_m, name) => { + const value = params[encodeURIComponent(name)] + const serialized = String(value) + return value ? serialized : 'undefined' + }) let hasQp = false const qp = new URLSearchParams() for (const paramName in params) { if (!pathParamNames.has(paramName)) { - qp.set(paramName, params[paramName]) + qp.set(paramName, String(params[paramName])) hasQp = true } } diff --git a/src/lib/routes/types.ts b/src/lib/routes/types.ts index d81063a06..e8fa00f23 100644 --- a/src/lib/routes/types.ts +++ b/src/lib/routes/types.ts @@ -1,4 +1,8 @@ -import {type NavigationState, type PartialState} from '@react-navigation/native' +import { + type NavigationState, + type NavigatorScreenParams, + type PartialState, +} from '@react-navigation/native' import {type NativeStackNavigationProp} from '@react-navigation/native-stack' import {type SearchFilters} from '#/screens/Search/searchParams' @@ -108,17 +112,18 @@ export type CommonNavigatorParams = { FindContactsFlow: undefined } -export type BottomTabNavigatorParams = CommonNavigatorParams & { - HomeTab: undefined - SearchTab: undefined - NotificationsTab: undefined - MyProfileTab: undefined - MessagesTab: undefined - AtmosphereTab: undefined - FeedsTab: undefined - ListsTab: undefined - BookmarksTab: undefined - SettingsTab: undefined +export type BottomTabNavigatorParams = { + HomeTab: NavigatorScreenParams | undefined + SearchTab: NavigatorScreenParams | undefined + NotificationsTab: + NavigatorScreenParams | undefined + MyProfileTab: NavigatorScreenParams | undefined + MessagesTab: NavigatorScreenParams | undefined + AtmosphereTab: NavigatorScreenParams | undefined + FeedsTab: NavigatorScreenParams | undefined + ListsTab: NavigatorScreenParams | undefined + BookmarksTab: NavigatorScreenParams | undefined + SettingsTab: NavigatorScreenParams | undefined } export type HomeTabNavigatorParams = CommonNavigatorParams & { @@ -138,11 +143,13 @@ export type MyProfileTabNavigatorParams = CommonNavigatorParams & { } export type MessagesTabNavigatorParams = CommonNavigatorParams & { - Messages: { - pushToConversation?: string - pushToNewGroupChat?: boolean - animation?: 'push' | 'pop' - } + Messages: + | { + pushToConversation?: string + pushToNewGroupChat?: boolean + animation?: 'push' | 'pop' + } + | undefined } export type FlatNavigatorParams = CommonNavigatorParams & { @@ -157,32 +164,12 @@ export type FlatNavigatorParams = CommonNavigatorParams & { } } -export type AllNavigatorParams = CommonNavigatorParams & { - HomeTab: undefined - Home: undefined - SearchTab: undefined - Search: SearchParams - Feeds: undefined - NotificationsTab: undefined - Notifications: undefined - MyProfileTab: undefined - MessagesTab: undefined - AtmosphereTab: undefined - FeedsTab: undefined - ListsTab: undefined - BookmarksTab: undefined - SettingsTab: undefined - Messages: { - pushToConversation?: string - pushToNewGroupChat?: boolean - animation?: 'push' | 'pop' - } -} +export type AllNavigatorParams = FlatNavigatorParams & BottomTabNavigatorParams -// NOTE -// this isn't strictly correct but it should be close enough -// a TS wizard might be able to get this 100% -// -prf +/** + * Shared navigation across the web stack and native tab stacks. Destination + * params are checked, but stack helpers are not scoped to the current navigator. + */ export type NavigationProp = NativeStackNavigationProp export type State = @@ -192,5 +179,5 @@ export type RouteParams = Record export type MatchResult = {params: RouteParams} export type Route = { match: (path: string) => MatchResult | undefined - build: (params?: Record) => string + build: (params?: Record) => string }