Handle all navigations from the state layer
This commit is contained in:
+2
-4
@@ -1,10 +1,9 @@
|
|||||||
import notifee, {EventType} from '@notifee/react-native'
|
import notifee, {EventType} from '@notifee/react-native'
|
||||||
import {StackActions} from '@react-navigation/native'
|
|
||||||
import {AppBskyEmbedImages} from '@atproto/api'
|
import {AppBskyEmbedImages} from '@atproto/api'
|
||||||
import {RootStoreModel} from 'state/models/root-store'
|
import {RootStoreModel} from 'state/models/root-store'
|
||||||
import {NotificationsViewItemModel} from 'state/models/notifications-view'
|
import {NotificationsViewItemModel} from 'state/models/notifications-view'
|
||||||
import {enforceLen} from 'lib/strings/helpers'
|
import {enforceLen} from 'lib/strings/helpers'
|
||||||
import {navigation} from '../Routes'
|
import {resetToTab} from '../Routes'
|
||||||
|
|
||||||
export function init(store: RootStoreModel) {
|
export function init(store: RootStoreModel) {
|
||||||
store.onUnreadNotifications(count => notifee.setBadgeCount(count))
|
store.onUnreadNotifications(count => notifee.setBadgeCount(count))
|
||||||
@@ -17,8 +16,7 @@ export function init(store: RootStoreModel) {
|
|||||||
store.log.debug('Notifee foreground event', {type})
|
store.log.debug('Notifee foreground event', {type})
|
||||||
if (type === EventType.PRESS) {
|
if (type === EventType.PRESS) {
|
||||||
store.log.debug('User pressed a notifee, opening notifications')
|
store.log.debug('User pressed a notifee, opening notifications')
|
||||||
navigation.navigate('NotificationsTab')
|
resetToTab('NotificationsTab')
|
||||||
navigation.dispatch(StackActions.popToTop())
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
notifee.onBackgroundEvent(async _e => {}) // notifee requires this but we handle it with onForegroundEvent
|
notifee.onBackgroundEvent(async _e => {}) // notifee requires this but we handle it with onForegroundEvent
|
||||||
|
|||||||
@@ -1,18 +1,4 @@
|
|||||||
import {State, NavigationProp} from './types'
|
import {State} from './types'
|
||||||
|
|
||||||
// TODO needed?
|
|
||||||
// export function getCurrentTabName(
|
|
||||||
// navigator: NavigationProp | undefined,
|
|
||||||
// ): string {
|
|
||||||
// if (!navigator) {
|
|
||||||
// throw new Error('Failed to get current tab')
|
|
||||||
// }
|
|
||||||
// const state = navigator.getState()
|
|
||||||
// if (state.type !== 'tab') {
|
|
||||||
// return getCurrentTabName(navigator.getParent())
|
|
||||||
// }
|
|
||||||
// return state.routes[state.index].name
|
|
||||||
// }
|
|
||||||
|
|
||||||
export function getCurrentRoute(state: State) {
|
export function getCurrentRoute(state: State) {
|
||||||
let node = state.routes[state.index || 0]
|
let node = state.routes[state.index || 0]
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export type NotificationsDrawerNavigatorParams = {
|
|||||||
export type AllNavigatorParams = CommonNavigatorParams & {
|
export type AllNavigatorParams = CommonNavigatorParams & {
|
||||||
HomeTab: undefined
|
HomeTab: undefined
|
||||||
Home: undefined
|
Home: undefined
|
||||||
SeachTab: undefined
|
SearchTab: undefined
|
||||||
Search: undefined
|
Search: undefined
|
||||||
NotificationsTab: undefined
|
NotificationsTab: undefined
|
||||||
Notifications: undefined
|
Notifications: undefined
|
||||||
|
|||||||
+19
-1
@@ -2,6 +2,7 @@ import * as React from 'react'
|
|||||||
import {
|
import {
|
||||||
NavigationContainer,
|
NavigationContainer,
|
||||||
createNavigationContainerRef,
|
createNavigationContainerRef,
|
||||||
|
StackActions,
|
||||||
} from '@react-navigation/native'
|
} from '@react-navigation/native'
|
||||||
import {createNativeStackNavigator} from '@react-navigation/native-stack'
|
import {createNativeStackNavigator} from '@react-navigation/native-stack'
|
||||||
import {createDrawerNavigator} from '@react-navigation/drawer'
|
import {createDrawerNavigator} from '@react-navigation/drawer'
|
||||||
@@ -277,4 +278,21 @@ function RoutesContainer({children}: React.PropsWithChildren<{}>) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export {navigationRef as navigation, matchPath, TabsNavigator, RoutesContainer}
|
function navigate<K extends keyof AllNavigatorParams>(
|
||||||
|
name: K,
|
||||||
|
params?: AllNavigatorParams[K],
|
||||||
|
) {
|
||||||
|
if (navigationRef.isReady()) {
|
||||||
|
// @ts-ignore I dont know what would make typescript happy but I have a life -prf
|
||||||
|
navigationRef.navigate(name, params)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetToTab(tabName: 'HomeTab' | 'SearchTab' | 'NotificationsTab') {
|
||||||
|
if (navigationRef.isReady()) {
|
||||||
|
navigate(tabName)
|
||||||
|
navigationRef.dispatch(StackActions.popToTop())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export {navigate, resetToTab, matchPath, TabsNavigator, RoutesContainer}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {ProfilesViewModel} from './profiles-view'
|
|||||||
import {LinkMetasViewModel} from './link-metas-view'
|
import {LinkMetasViewModel} from './link-metas-view'
|
||||||
import {NotificationsViewItemModel} from './notifications-view'
|
import {NotificationsViewItemModel} from './notifications-view'
|
||||||
import {MeModel} from './me'
|
import {MeModel} from './me'
|
||||||
|
import {resetToTab} from '../../Routes'
|
||||||
|
|
||||||
export const appInfo = z.object({
|
export const appInfo = z.object({
|
||||||
build: z.string(),
|
build: z.string(),
|
||||||
@@ -138,7 +139,7 @@ export class RootStoreModel {
|
|||||||
*/
|
*/
|
||||||
async handleSessionDrop() {
|
async handleSessionDrop() {
|
||||||
this.log.debug('RootStoreModel:handleSessionDrop')
|
this.log.debug('RootStoreModel:handleSessionDrop')
|
||||||
// this.nav.clear() TODO
|
resetToTab('HomeTab')
|
||||||
this.me.clear()
|
this.me.clear()
|
||||||
this.emitSessionDropped()
|
this.emitSessionDropped()
|
||||||
}
|
}
|
||||||
@@ -149,7 +150,7 @@ export class RootStoreModel {
|
|||||||
clearAllSessionState() {
|
clearAllSessionState() {
|
||||||
this.log.debug('RootStoreModel:clearAllSessionState')
|
this.log.debug('RootStoreModel:clearAllSessionState')
|
||||||
this.session.clear()
|
this.session.clear()
|
||||||
// this.nav.clear() TODO
|
resetToTab('HomeTab')
|
||||||
this.me.clear()
|
this.me.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {s, colors, gradients} from 'lib/styles'
|
|||||||
import {usePalette} from 'lib/hooks/usePalette'
|
import {usePalette} from 'lib/hooks/usePalette'
|
||||||
import {ErrorMessage} from '../util/error/ErrorMessage'
|
import {ErrorMessage} from '../util/error/ErrorMessage'
|
||||||
import {cleanError} from 'lib/strings/errors'
|
import {cleanError} from 'lib/strings/errors'
|
||||||
|
import {resetToTab} from '../../../Routes'
|
||||||
|
|
||||||
export const snapPoints = ['60%']
|
export const snapPoints = ['60%']
|
||||||
|
|
||||||
@@ -46,7 +47,7 @@ export function Component({}: {}) {
|
|||||||
token: confirmCode,
|
token: confirmCode,
|
||||||
})
|
})
|
||||||
Toast.show('Your account has been deleted')
|
Toast.show('Your account has been deleted')
|
||||||
// store.nav.tab.fixedTabReset() TODO
|
resetToTab('HomeTab')
|
||||||
store.session.clear()
|
store.session.clear()
|
||||||
store.shell.closeModal()
|
store.shell.closeModal()
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
|||||||
Reference in New Issue
Block a user