tooot/src/utils/navigation/navigators.ts

210 lines
7.1 KiB
TypeScript
Raw Normal View History

2021-08-29 15:25:38 +02:00
import { BottomTabScreenProps } from '@react-navigation/bottom-tabs'
2023-01-04 22:39:29 +01:00
import { NavigatorScreenParams, useNavigationState } from '@react-navigation/native'
2021-08-29 15:25:38 +02:00
import { NativeStackScreenProps } from '@react-navigation/native-stack'
2021-08-29 16:08:02 +02:00
import { StackNavigationProp } from '@react-navigation/stack'
2022-12-04 13:26:36 +01:00
import { ComposeState } from '@screens/Compose/utils/types'
2021-08-29 15:25:38 +02:00
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
2023-01-04 22:39:29 +01:00
export const useNavState = () =>
useNavigationState(state =>
state.routes.map(
route => (route.params as { queryKey?: QueryKeyTimeline } | undefined)?.queryKey
)
)
.filter(key => key?.[0] === 'Timeline')
.reverse()
2021-08-29 15:25:38 +02:00
export type RootStackParamList = {
'Screen-Tabs': NavigatorScreenParams<ScreenTabsStackParamList>
'Screen-Announcements': { showAll: boolean }
'Screen-Compose':
| {
type: 'edit'
incomingStatus: Mastodon.Status
replyToStatus?: Mastodon.Status
2023-01-04 22:39:29 +01:00
navigationState: (QueryKeyTimeline | undefined)[]
2022-04-30 17:44:39 +02:00
}
| {
type: 'deleteEdit'
incomingStatus: Mastodon.Status
replyToStatus?: Mastodon.Status
2023-01-04 22:39:29 +01:00
navigationState: (QueryKeyTimeline | undefined)[]
2021-08-29 15:25:38 +02:00
}
| {
type: 'reply'
incomingStatus: Mastodon.Status
accts: Mastodon.Account['acct'][]
2023-01-04 22:39:29 +01:00
navigationState: (QueryKeyTimeline | undefined)[]
2021-08-29 15:25:38 +02:00
}
| {
type: 'conversation'
accts: Mastodon.Account['acct'][]
2022-12-04 13:26:36 +01:00
visibility: ComposeState['visibility']
2022-11-17 21:48:22 +01:00
text?: string // For contacting tooot only
2023-01-06 01:01:10 +01:00
navigationState: (QueryKeyTimeline | undefined)[]
2021-08-29 15:25:38 +02:00
}
2022-05-02 22:31:22 +02:00
| {
type: 'share'
text?: string
2022-06-09 21:33:10 +02:00
media?: { uri: string; mime: string }[]
2022-05-02 22:31:22 +02:00
}
2021-08-29 15:25:38 +02:00
| undefined
'Screen-ImagesViewer': {
imageUrls: {
id: Mastodon.Attachment['id']
2022-12-18 20:55:33 +01:00
preview_url?: Mastodon.AttachmentImage['preview_url']
2021-08-29 15:25:38 +02:00
url: Mastodon.AttachmentImage['url']
remote_url?: Mastodon.AttachmentImage['remote_url']
width?: number
height?: number
}[]
id: Mastodon.Attachment['id']
2022-12-18 20:55:33 +01:00
hideCounter?: boolean
2021-08-29 15:25:38 +02:00
}
2022-08-12 16:44:28 +02:00
'Screen-AccountSelection': {
component?: () => JSX.Element | undefined
share?: { text?: string; media?: { uri: string; mime: string }[] }
}
2021-08-29 15:25:38 +02:00
}
export type RootStackScreenProps<T extends keyof RootStackParamList> = NativeStackScreenProps<
RootStackParamList,
T
>
2021-08-29 15:25:38 +02:00
export type ScreenComposeStackParamList = {
'Screen-Compose-Root': undefined
'Screen-Compose-EditAttachment': { index: number }
'Screen-Compose-DraftsList': { timestamp: number }
}
export type ScreenComposeStackScreenProps<T extends keyof ScreenComposeStackParamList> =
NativeStackScreenProps<ScreenComposeStackParamList, T>
2021-08-29 15:25:38 +02:00
export type ScreenTabsStackParamList = {
'Tab-Local': NavigatorScreenParams<TabLocalStackParamList>
'Tab-Public': NavigatorScreenParams<TabPublicStackParamList>
'Tab-Compose': undefined
'Tab-Notifications': NavigatorScreenParams<TabNotificationsStackParamList>
'Tab-Me': NavigatorScreenParams<TabMeStackParamList>
}
export type ScreenTabsScreenProps<T extends keyof ScreenTabsStackParamList> = BottomTabScreenProps<
ScreenTabsStackParamList,
T
>
2021-08-29 15:25:38 +02:00
export type TabSharedStackParamList = {
'Tab-Shared-Account': {
2023-01-05 00:49:10 +01:00
account: Partial<Pick<Mastodon.Account, 'id' | 'url' | '_remote'>> &
Pick<Mastodon.Account, 'acct' | 'url'>
2023-01-04 22:39:29 +01:00
queryKey?: QueryKeyTimeline
2021-08-29 15:25:38 +02:00
}
2023-01-04 22:39:29 +01:00
'Tab-Shared-Account-In-Lists': { account: Pick<Mastodon.Account, 'id' | 'username'> }
'Tab-Shared-Attachments': { account: Mastodon.Account; queryKey?: QueryKeyTimeline }
2023-01-26 23:07:13 +01:00
'Tab-Shared-Filter':
| { source: 'status'; status: Mastodon.Status }
| { source: 'hashtag'; tag_name: Mastodon.Tag['name'] }
'Tab-Shared-Hashtag': { tag_name: Mastodon.Tag['name']; queryKey?: QueryKeyTimeline }
2023-01-04 22:39:29 +01:00
'Tab-Shared-History': { status: Mastodon.Status; detectedLanguage: string }
2023-07-13 21:55:26 +02:00
'Tab-Shared-Mute': {
account: Pick<Mastodon.Account, 'id' | 'acct' | 'username' | 'url'>
}
2022-12-22 18:38:04 +01:00
'Tab-Shared-Report': {
2023-01-02 23:18:22 +01:00
account: Pick<Mastodon.Account, 'id' | 'acct' | 'username' | 'url'>
2023-01-02 02:08:12 +01:00
status?: Pick<Mastodon.Status, 'id' | '_remote' | 'uri'>
2022-12-22 18:38:04 +01:00
}
2022-12-04 20:08:55 +01:00
'Tab-Shared-Search': undefined
2023-01-04 22:39:29 +01:00
'Tab-Shared-Toot': { toot: Mastodon.Status; queryKey?: QueryKeyTimeline }
2021-08-29 15:25:38 +02:00
'Tab-Shared-Users':
| {
reference: 'accounts'
2022-12-15 01:41:34 +01:00
account: Pick<Mastodon.Account, 'id' | 'username' | 'acct' | 'url'>
2021-08-29 15:25:38 +02:00
type: 'following' | 'followers'
count: number
}
| {
reference: 'statuses'
2022-12-15 01:41:34 +01:00
status: Pick<Mastodon.Status, 'id'>
2021-08-29 15:25:38 +02:00
type: 'reblogged_by' | 'favourited_by'
count: number
}
}
2022-04-29 23:57:18 +02:00
export type TabSharedStackScreenProps<T extends keyof TabSharedStackParamList> =
NativeStackScreenProps<TabSharedStackParamList, T>
2021-08-29 15:25:38 +02:00
export type TabLocalStackParamList = {
2023-01-04 22:39:29 +01:00
'Tab-Local-Root': { queryKey?: QueryKeyTimeline }
2021-08-29 15:25:38 +02:00
} & TabSharedStackParamList
export type TabPublicStackParamList = {
2023-01-04 22:39:29 +01:00
'Tab-Public-Root': { queryKey?: QueryKeyTimeline }
2021-08-29 15:25:38 +02:00
} & TabSharedStackParamList
export type TabNotificationsStackParamList = {
2023-01-04 22:39:29 +01:00
'Tab-Notifications-Root': { queryKey?: QueryKeyTimeline }
'Tab-Notifications-Filters': undefined
2021-08-29 15:25:38 +02:00
} & TabSharedStackParamList
export type TabNotificationsStackScreenProps<T extends keyof TabNotificationsStackParamList> =
NativeStackScreenProps<TabNotificationsStackParamList, T>
2021-08-29 15:25:38 +02:00
export type TabMeStackParamList = {
'Tab-Me-Root': undefined
2023-01-04 22:39:29 +01:00
'Tab-Me-Bookmarks': { queryKey?: QueryKeyTimeline }
'Tab-Me-Conversations': { queryKey?: QueryKeyTimeline }
'Tab-Me-Favourites': { queryKey?: QueryKeyTimeline }
2022-12-10 20:19:18 +01:00
'Tab-Me-FollowedTags': undefined
2023-01-04 22:39:29 +01:00
'Tab-Me-List': { list: Mastodon.List; queryKey?: QueryKeyTimeline }
'Tab-Me-List-Accounts': Omit<Mastodon.List, 'replies_policy'>
'Tab-Me-List-Edit':
| {
type: 'add'
}
| {
type: 'edit'
payload: Mastodon.List
key: string // To update title after successful mutation
}
'Tab-Me-List-List': undefined
'Tab-Me-Preferences': undefined
2021-08-29 15:25:38 +02:00
'Tab-Me-Profile': undefined
'Tab-Me-Push': undefined
'Tab-Me-Settings': undefined
'Tab-Me-Settings-Fontsize': undefined
'Tab-Me-Settings-Language': undefined
2021-08-29 15:25:38 +02:00
'Tab-Me-Switch': undefined
} & TabSharedStackParamList
export type TabMeStackScreenProps<T extends keyof TabMeStackParamList> = NativeStackScreenProps<
TabMeStackParamList,
T
>
export type TabMeStackNavigationProp<RouteName extends keyof TabMeStackParamList> =
StackNavigationProp<TabMeStackParamList, RouteName>
2021-08-29 15:25:38 +02:00
export type TabMeProfileStackParamList = {
'Tab-Me-Profile-Root': undefined
'Tab-Me-Profile-Name': {
display_name: Mastodon.Account['display_name']
}
'Tab-Me-Profile-Note': {
note: Mastodon.Source['note']
}
'Tab-Me-Profile-Fields': {
fields?: Mastodon.Source['fields']
}
}
export type TabMeProfileStackScreenProps<T extends keyof TabMeProfileStackParamList> =
NativeStackScreenProps<TabMeProfileStackParamList, T>
export type TabMePreferencesStackParamList = {
'Tab-Me-Preferences-Root': undefined
'Tab-Me-Preferences-Filters': undefined
'Tab-Me-Preferences-Filter':
| {
type: 'add'
}
| {
type: 'edit'
filter: Mastodon.Filter<'v2'>
}
}
export type TabMePreferencesStackScreenProps<T extends keyof TabMePreferencesStackParamList> =
NativeStackScreenProps<TabMePreferencesStackParamList, T>