Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions shared/chat/blocking/invitation-to-block.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as Chat from '@/stores/chat'
import {useProfileState} from '@/stores/profile'
import * as Kb from '@/common-adapters'
import {useSafeNavigation} from '@/util/safe-navigation'
import {useRouteNavigation} from '@/constants/router'
import {useCurrentUserState} from '@/stores/current-user'

const BlockButtons = () => {
const nav = useSafeNavigation()
const nav = useRouteNavigation()
const conversationIDKey = Chat.useChatContext(s => s.id)

const team = Chat.useChatContext(s => s.meta.teamname)
Expand All @@ -27,9 +27,9 @@ const BlockButtons = () => {
)

const onViewProfile = () => showUserProfile(adder)
const onViewTeam = () => nav.safeNavigateAppend({name: 'team', params: {teamID}})
const onViewTeam = () => nav.navigateAppend({name: 'team', params: {teamID}})
const onBlock = () =>
nav.safeNavigateAppend({
nav.navigateAppend({
name: 'chatBlockingModal',
params: {
blockUserByDefault: true,
Expand Down
8 changes: 4 additions & 4 deletions shared/chat/conversation/info-panel/add-to-channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as React from 'react'
import * as Teams from '@/stores/teams'
import * as Kb from '@/common-adapters'
import * as T from '@/constants/types'
import {useSafeNavigation} from '@/util/safe-navigation'
import {useRouteNavigation} from '@/constants/router'
import {useTeamDetailsSubscribe} from '@/teams/subscriber'
import {pluralize} from '@/util/string'
import {useChannelParticipants} from '@/teams/common'
Expand All @@ -14,7 +14,7 @@ type Props = {teamID: T.Teams.TeamID}

const AddToChannel = (props: Props) => {
const {teamID} = props
const nav = useSafeNavigation()
const nav = useRouteNavigation()
const conversationIDKey = Chat.useChatContext(s => s.id)

const [toAdd, setToAdd] = React.useState(new Set<string>())
Expand All @@ -37,7 +37,7 @@ const AddToChannel = (props: Props) => {
const [error, setError] = React.useState('')
const addToChannel = C.useRPC(T.RPCChat.localBulkAddToConvRpcPromise)

const onClose = () => nav.safeNavigateUp()
const onClose = () => nav.navigateUp()
const loadTeamChannelList = Teams.useTeamsState(s => s.dispatch.loadTeamChannelList)
const onAdd = () => {
setWaiting(true)
Expand Down Expand Up @@ -65,7 +65,7 @@ const AddToChannel = (props: Props) => {
() => {
setWaiting(false)
loadTeamChannelList(teamID)
nav.safeNavigateUp()
nav.navigateUp()
},
(e: {message: string}) => {
setError(e.message)
Expand Down
6 changes: 3 additions & 3 deletions shared/chat/inbox/row/build-team.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import * as C from '@/constants'
import {useTeamsState} from '@/stores/teams'
import * as Kb from '@/common-adapters'
import {useSafeNavigation} from '@/util/safe-navigation'
import {useRouteNavigation} from '@/constants/router'

function BuildTeam() {
const nav = useSafeNavigation()
const nav = useRouteNavigation()
const launchNewTeamWizardOrModal = useTeamsState(s => s.dispatch.launchNewTeamWizardOrModal)
const switchTab = C.useRouterState(s => s.dispatch.switchTab)
const onCreateTeam = () => {
switchTab(C.Tabs.teamsTab)
launchNewTeamWizardOrModal()
}
const onJoinTeam = () => {
nav.safeNavigateAppend('teamJoinTeamDialog')
nav.navigateAppend('teamJoinTeamDialog')
}

return (
Expand Down
8 changes: 4 additions & 4 deletions shared/chat/punycode-link-warning.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Kb from '@/common-adapters'
import {useSafeNavigation} from '@/util/safe-navigation'
import {useRouteNavigation} from '@/constants/router'
import openURL from '@/util/open-url'

type PunycodeLinkWarningProps = {
Expand All @@ -10,11 +10,11 @@ type PunycodeLinkWarningProps = {

const PunycodeLinkWarning = (props: PunycodeLinkWarningProps) => {
const {url, display, punycode} = props
const nav = useSafeNavigation()
const onCancel = () => nav.safeNavigateUp()
const nav = useRouteNavigation()
const onCancel = () => nav.navigateUp()
const onConfirm = () => {
openURL(url)
nav.safeNavigateUp()
nav.navigateUp()
}
const description = `The link you clicked on appears to be ${display}, but actually points to ${punycode}.`
return (
Expand Down
1 change: 1 addition & 0 deletions shared/common-adapters/confirm-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const ConfirmModal = (props: Props) => (
disabled={props.onConfirmDeactivated || !props.onConfirm}
type="Danger"
label={props.confirmText || 'Confirm'}
lockOnClick={!!props.waitingKey}
onClick={props.onConfirm}
style={styles.button}
waitingKey={props.waitingKey}
Expand Down
4 changes: 2 additions & 2 deletions shared/common-adapters/floating-menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ export type Props = {

type SafeNavigationHook = <T extends NavigationProp<ParamListBase>>() => T | null

const useSafeNavigation: SafeNavigationHook = Styles.isMobile
const useMenuNavigation: SafeNavigationHook = Styles.isMobile
? (useNavigation as SafeNavigationHook)
: () => null

function FloatingMenu(props: Props) {
const {items, visible, onHidden, mode} = props

const navigation = useSafeNavigation()
const navigation = useMenuNavigation()

React.useEffect(() => {
const unsub = navigation?.addListener('state', () => {
Expand Down
24 changes: 22 additions & 2 deletions shared/common-adapters/waiting-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const Kb = {
}

export type Props = {
lockOnClick?: boolean
onlyDisable?: boolean
waitingKey?: Array<string> | string
} & ButtonProps
Expand All @@ -25,22 +26,41 @@ export type Props = {
*/

function WaitingButton(props: Props & {ref?: React.Ref<MeasureRef>}) {
const {onlyDisable, waitingKey, ref, ...buttonProps} = props
const {lockOnClick, onlyDisable, waitingKey, ref, ...buttonProps} = props
const storeWaiting = C.Waiting.useAnyWaiting(waitingKey)

const [localWaiting, setLocalWaiting] = React.useState(false)
const [trackingStoreWaiting, setTrackingStoreWaiting] = React.useState(false)

if (onlyDisable && !waitingKey) {
throw new Error('WaitingButton onlyDisable should only be used with a waiting key')
}

React.useEffect(() => {
if (!lockOnClick || !waitingKey || !localWaiting) {
return
}
if (storeWaiting) {
setTrackingStoreWaiting(true)
return
}
if (trackingStoreWaiting) {
setLocalWaiting(false)
setTrackingStoreWaiting(false)
return
}
setLocalWaiting(false)
}, [lockOnClick, localWaiting, storeWaiting, trackingStoreWaiting, waitingKey])

const waiting = storeWaiting || localWaiting
return (
<Kb.Button
ref={ref}
{...buttonProps}
onClick={event => {
if (!waitingKey) {
if (lockOnClick || !waitingKey) {
setLocalWaiting(true)
setTrackingStoreWaiting(false)
}
buttonProps.onClick?.(event)
}}
Expand Down
2 changes: 1 addition & 1 deletion shared/constants/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './platform'
export * from './values'
export * from './strings'
export {useRouterState, makeScreen} from '@/stores/router'
export {useRouterState, makeScreen, useRouteNavigation} from '@/stores/router'
export * as Router2 from '@/stores/router'
export * as Tabs from './tabs'
export {useWaitingState} from '@/stores/waiting'
Expand Down
22 changes: 22 additions & 0 deletions shared/constants/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
CommonActions,
type NavigationContainerRef,
useFocusEffect,
useRoute,
createNavigationContainerRef,
type NavigationState,
} from '@react-navigation/core'
Expand Down Expand Up @@ -181,6 +182,13 @@ export const navigateUp = () => {
return n?.dispatch(CommonActions.goBack())
}

const _routeIsVisible = (routeKey: string) => getVisibleScreen()?.key === routeKey

export const navigateUpFromRoute = (routeKey: string) => {
if (!_routeIsVisible(routeKey)) return
return navigateUp()
}

export const popStack = () => {
DEBUG_NAV && console.log('[Nav] popStack')
const n = _getNavigator()
Expand Down Expand Up @@ -238,6 +246,20 @@ export const navigateAppend = (path: PathParam, replace?: boolean) => {
n.dispatch(StackActions.push(routeName, params))
}

export const navigateAppendFromRoute = (routeKey: string, path: PathParam, replace?: boolean) => {
if (!_routeIsVisible(routeKey)) return
return navigateAppend(path, replace)
}

export const useRouteNavigation = () => {
const route = useRoute() as {key: string}
const routeKey = route.key
return {
navigateAppend: (path: PathParam, replace?: boolean) => navigateAppendFromRoute(routeKey, path, replace),
navigateUp: () => navigateUpFromRoute(routeKey),
}
}

export const switchTab = (name: Tabs.AppTab) => {
DEBUG_NAV && console.log('[Nav] switchTab', {name})
const n = _getNavigator()
Expand Down
8 changes: 4 additions & 4 deletions shared/fs/browser/destination-picker.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as C from '@/constants'
import {useSafeNavigation} from '@/util/safe-navigation'
import {useRouteNavigation} from '@/constants/router'
import * as FsCommon from '@/fs/common'
import * as Kb from '@/common-adapters'
import * as RowCommon from './rows/common'
Expand Down Expand Up @@ -46,7 +46,7 @@ const ConnectedDestinationPicker = (ownProps: OwnProps) => {
})
)

const nav = useSafeNavigation()
const nav = useRouteNavigation()
const clearModals = C.useRouterState(s => s.dispatch.clearModals)
const onBackUp =
isShare || !canBackUp(parentPath)
Expand All @@ -57,14 +57,14 @@ const ConnectedDestinationPicker = (ownProps: OwnProps) => {
? () => {
moveOrCopy(parentPath, 'copy')
clearModals()
nav.safeNavigateAppend({name: 'fsRoot', params: {path: parentPath}})
nav.navigateAppend({name: 'fsRoot', params: {path: parentPath}})
}
: undefined
const onMoveHere = isMovable
? () => {
moveOrCopy(parentPath, 'move')
clearModals()
nav.safeNavigateAppend({name: 'fsRoot', params: {path: parentPath}})
nav.navigateAppend({name: 'fsRoot', params: {path: parentPath}})
}
: undefined
const onNewFolder =
Expand Down
6 changes: 3 additions & 3 deletions shared/fs/common/use-open.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as C from '@/constants'
import * as T from '@/constants/types'
import {useSafeNavigation} from '@/util/safe-navigation'
import {useRouteNavigation} from '@/constants/router'
import {useFSState} from '@/stores/fs'
import * as FS from '@/stores/fs'

Expand All @@ -16,10 +16,10 @@ export const useOpen = (props: Props) => {
return {destPicker: destinationPicker, pathItems}
})
)
const nav = useSafeNavigation()
const nav = useRouteNavigation()

if (typeof props.destinationPickerIndex !== 'number') {
return () => nav.safeNavigateAppend({name: 'fsRoot', params: {path: props.path}})
return () => nav.navigateAppend({name: 'fsRoot', params: {path: props.path}})
}

const isFolder =
Expand Down
6 changes: 3 additions & 3 deletions shared/fs/nav-header/title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react'
import * as T from '@/constants/types'
import * as Kb from '@/common-adapters'
import * as Kbfs from '../common'
import {useSafeNavigation} from '@/util/safe-navigation'
import {useRouteNavigation} from '@/constants/router'
import * as FS from '@/stores/fs'

type Props = {
Expand All @@ -20,11 +20,11 @@ const Breadcrumb = (props: Props) => {
.slice(1, -1)
.reduce((list, current) => [...list, T.FS.pathConcat(list.at(-1), current)], [FS.defaultPath])
const {inDestinationPicker} = props
const nav = useSafeNavigation()
const nav = useRouteNavigation()
const onOpenPath = (path: T.FS.Path) => {
inDestinationPicker
? FS.makeActionsForDestinationPickerOpen(0, path)
: nav.safeNavigateAppend({name: 'fsRoot', params: {path}})
: nav.navigateAppend({name: 'fsRoot', params: {path}})
}

const makePopup = (p: Kb.Popup2Parms) => {
Expand Down
6 changes: 3 additions & 3 deletions shared/fs/simple-screens/oops.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as T from '@/constants/types'
import * as C from '@/constants'
import * as Kb from '@/common-adapters'
import {useSafeNavigation} from '@/util/safe-navigation'
import {useRouteNavigation} from '@/constants/router'

type OwnProps = {
path: T.FS.Path
Expand Down Expand Up @@ -98,9 +98,9 @@ const NonExistent = (props: Props) => (
)

const Oops = (props: OwnProps) => {
const nav = useSafeNavigation()
const nav = useRouteNavigation()
const openParent = () =>
nav.safeNavigateAppend({name: 'fsRoot', params: {path: T.FS.getPathParent(props.path)}})
nav.navigateAppend({name: 'fsRoot', params: {path: T.FS.getPathParent(props.path)}})
switch (props.reason) {
case T.FS.SoftError.NoAccess:
return <NoAccess {...props} openParent={openParent} />
Expand Down
6 changes: 3 additions & 3 deletions shared/git/select-channel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Git from '@/stores/git'
import * as Teams from '@/stores/teams'
import {useSafeNavigation} from '@/util/safe-navigation'
import {useRouteNavigation} from '@/constants/router'
import * as Kb from '@/common-adapters'
import * as React from 'react'
import type * as T from '@/constants/types'
Expand All @@ -20,10 +20,10 @@ const SelectChannel = (ownProps: OwnProps) => {
const waiting = channelMetas.size === 0 // TODO fix this?
const channelNames = [...channelMetas.values()].map(info => info.channelname)
const [selected, setSelected] = React.useState(_selected)
const nav = useSafeNavigation()
const nav = useRouteNavigation()
const setTeamRepoSettings = Git.useGitState(s => s.dispatch.setTeamRepoSettings)
const onSubmit = (channelName: string) => setTeamRepoSettings(channelName, teamname, repoID, false)
const onCancel = () => nav.safeNavigateUp()
const onCancel = () => nav.navigateUp()

const submit = () => {
onSubmit(selected)
Expand Down
10 changes: 5 additions & 5 deletions shared/login/recover-password/prompt-reset-shared.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as C from '@/constants'
import * as AutoReset from '@/stores/autoreset'
import * as Kb from '@/common-adapters'
import {useSafeNavigation} from '@/util/safe-navigation'
import {useRouteNavigation} from '@/constants/router'
import * as T from '@/constants/types'
import {SignupScreen} from '@/signup/common'
import type {ButtonType} from '@/common-adapters/button'
Expand All @@ -12,7 +12,7 @@ export type Props = {
}

const PromptReset = (props: Props) => {
const nav = useSafeNavigation()
const nav = useRouteNavigation()
const skipPassword = AutoReset.useAutoResetState(s => s.skipPassword)
const error = AutoReset.useAutoResetState(s => s.error)
const resetAccount = AutoReset.useAutoResetState(s => s.dispatch.resetAccount)
Expand All @@ -25,7 +25,7 @@ const PromptReset = (props: Props) => {
const onContinue = () => {
// dont do this in preflight
if (C.androidIsTestDevice) {
nav.safeNavigateUp()
nav.navigateUp()
return
}
if (resetPassword) {
Expand All @@ -34,14 +34,14 @@ const PromptReset = (props: Props) => {
if (skipPassword) {
resetAccount()
} else {
nav.safeNavigateAppend('resetKnowPassword', true)
nav.navigateAppend('resetKnowPassword', true)
}
}
const onBack = () => {
if (skipPassword) {
startRecoverPassword({replaceRoute: true, username})
} else {
nav.safeNavigateUp()
nav.navigateUp()
}
}
const title = props.resetPassword ? 'Reset password' : skipPassword ? 'Recover password' : 'Account reset'
Expand Down
Loading