Send files directly between devices over the internet - no cloud storage, no size limits.
TypeScript cross-platformdata-transferdecentralizedfile-sharingfile-transferhole-punchingopen-sourcep2ppeer-to-peerprivacyprivacy-tools
Add leave session confirm dialog
Denis Lupookov677142ec5e87
diff --git a/apps/mobile/app/_layout.tsx b/apps/mobile/app/_layout.tsxindex 1365865..848b65f 100644--- a/apps/mobile/app/_layout.tsx+++ b/apps/mobile/app/_layout.tsx@@ -90,7 +90,11 @@ function getHeaderOptions(theme: Theme) {}function getFlowScreenOptions(theme: Theme) {- return { ...getHeaderOptions(theme), headerTitle: '' } as const+ return {+ ...getHeaderOptions(theme),+ headerTitle: '',+ headerBackButtonMenuEnabled: false+ } as const}function getTitledScreenOptions(theme: Theme, fontFamilyName?: string) {@@ -159,16 +163,10 @@ function ThemedStack() {name='report'options={{ ...titledScreenOptions, title: t('feedback:title') }}/>- <Stack.Screen- name='send/preparing'- options={{ ...flowScreenOptions, gestureEnabled: false }}- />- <Stack.Screen name='send/share' options={{ ...flowScreenOptions, gestureEnabled: false }} />+ <Stack.Screen name='send/preparing' options={flowScreenOptions} />+ <Stack.Screen name='send/share' options={flowScreenOptions} /><Stack.Screen name='receive/scan' options={flowScreenOptions} />- <Stack.Screen- name='receive/incoming'- options={{ ...flowScreenOptions, gestureEnabled: false }}- />+ <Stack.Screen name='receive/incoming' options={flowScreenOptions} /><Stack.Screenname='receive/complete'options={{diff --git a/apps/mobile/app/receive/incoming.tsx b/apps/mobile/app/receive/incoming.tsxindex 1f57761..ae4f2e7 100644--- a/apps/mobile/app/receive/incoming.tsx+++ b/apps/mobile/app/receive/incoming.tsx@@ -4,10 +4,10 @@ import { Paths } from 'expo-file-system'import { Button, useTheme } from '@altersend/components'import { DownloadIcon, InfoIcon, PlayIcon } from '@altersend/components/icons'import { useTranslation } from '@altersend/locales'-import { useNavigation, useRouter } from 'expo-router'+import { useRouter } from 'expo-router'import { uriToPath } from '@/src/api/mobileApi'-import { Layout, IllustrationLayout } from '@/src/components'-import { IconButton } from '@/src/components/IconButton'+import { ConfirmDialog, Layout, IllustrationLayout } from '@/src/components'+import { useLeaveSessionConfirm } from '@/src/hooks/useLeaveSessionConfirm'import { ReceiveIncomingView, ReceiveReconnectingView } from '@/src/transfer/receive'import { useErrorToast } from '@/src/transfer/receive/utils/useErrorToast'import { exitToReceiveTab } from '@/src/transfer/receive/utils/exitToReceiveTab'@@ -27,7 +27,6 @@ import { Text } from '@/src/components/ThemedText'export default function ReceiveIncomingScreen() {const { t } = useTranslation(['receive', 'common', 'errors'])const { theme } = useTheme()- const navigation = useNavigation()const router = useRouter()const incomingFileOffers = useTransferStore((s) => s.incomingFileOffers)const downloads = useReceiveDownloads()@@ -62,15 +61,7 @@ export default function ReceiveIncomingScreen() {void clearSession()exitToReceiveTab(router)}, [router])-- useEffect(() => {- navigation.setOptions({- headerBackVisible: false,- headerLeft: () => (- <IconButton icon='back' label={t('common:actions.back')} onPress={handleEndSession} />- )- })- }, [navigation, handleEndSession, t, theme.colors.colorTextPrimary])+ const { leaveDialog } = useLeaveSessionConfirm(handleEndSession)const totalBytes = totals.totalBytesconst textCount = incomingFileOffers.length - downloadableFileCount@@ -101,38 +92,6 @@ export default function ReceiveIncomingScreen() {</Button>)- if (isReconnectingStep) {- return (- <ReceiveReconnectingView- title={title}- description={description}- footer={endSessionButton}- hasNativeHeader- />- )- }-- if (step === 'completed') {- return null- }-- if (step !== 'incoming_transfer') {- return (- <IllustrationLayout- title={t('receive:page.sessionEnded.title')}- description={t('receive:page.sessionEnded.description')}- hasNativeHeader- illustration={<ConnectionLostSvg width='100%' height='100%' />}- aspectRatio={800 / 430}- footer={- <Button onClick={handleEndSession} size='lg' variant='primary' width='full'>- {t('receive:actions.backToHome')}- </Button>- }- />- )- }-const isRelay = connectionType === 'relay'const badge = isRelay ? (<Pressable@@ -159,41 +118,82 @@ export default function ReceiveIncomingScreen() {</View>)- return (- <Layout- title={title}- description={description}- badge={badge}- hasNativeHeader- footer={- <View style={styles.footerStack}>- {downloads.primaryAction ? (- <Button- icon={- downloads.primaryAction === 'resume-all' ? (- <PlayIcon size={18} />- ) : (- <DownloadIcon size={18} />- )- }- loading={downloads.primaryAction === 'downloading'}- onClick={() => void handlePrimaryAction()}- size='lg'- variant='light'- width='full'- >- {getPrimaryDownloadLabel(t, downloads.primaryAction, {- percent: totals.percent,- totalBytes- })}+ const renderBody = () => {+ if (isReconnectingStep) {+ return (+ <ReceiveReconnectingView+ title={title}+ description={description}+ footer={endSessionButton}+ hasNativeHeader+ />+ )+ }++ if (step === 'completed') {+ return null+ }++ if (step !== 'incoming_transfer') {+ return (+ <IllustrationLayout+ title={t('receive:page.sessionEnded.title')}+ description={t('receive:page.sessionEnded.description')}+ hasNativeHeader+ illustration={<ConnectionLostSvg width='100%' height='100%' />}+ aspectRatio={800 / 430}+ footer={+ <Button onClick={handleEndSession} size='lg' variant='primary' width='full'>+ {t('receive:actions.backToHome')}</Button>- ) : null}- {endSessionButton}- </View>- }- >- <ReceiveIncomingView />- </Layout>+ }+ />+ )+ }++ return (+ <Layout+ title={title}+ description={description}+ badge={badge}+ hasNativeHeader+ footer={+ <View style={styles.footerStack}>+ {downloads.primaryAction ? (+ <Button+ icon={+ downloads.primaryAction === 'resume-all' ? (+ <PlayIcon size={18} />+ ) : (+ <DownloadIcon size={18} />+ )+ }+ loading={downloads.primaryAction === 'downloading'}+ onClick={() => void handlePrimaryAction()}+ size='lg'+ variant='light'+ width='full'+ >+ {getPrimaryDownloadLabel(t, downloads.primaryAction, {+ percent: totals.percent,+ totalBytes+ })}+ </Button>+ ) : null}+ {endSessionButton}+ </View>+ }+ >+ <ReceiveIncomingView />+ </Layout>+ )+ }++ return (+ <>+ {renderBody()}+ <ConfirmDialog {...leaveDialog} />+ </>)}diff --git a/apps/mobile/app/receive/scan.tsx b/apps/mobile/app/receive/scan.tsxindex fcef884..0e5f91f 100644--- a/apps/mobile/app/receive/scan.tsx+++ b/apps/mobile/app/receive/scan.tsx@@ -10,18 +10,16 @@ import * as ImagePicker from 'expo-image-picker'import { Button, useTheme, withAlpha } from '@altersend/components'import { QrCodeIcon } from '@altersend/components/icons'import { useTranslation } from '@altersend/locales'-import { useNavigation, useRouter } from 'expo-router'+import { useRouter } from 'expo-router'import { extractJoinCode, useTransferStore } from '@altersend/domain'import { joinSession } from '@altersend/domain'import { Layout } from '@/src/components'-import { IconButton } from '@/src/components/IconButton'import { useToast } from '@/src/components/Toast'import { Text } from '@/src/components/ThemedText'export default function ReceiveScanScreen() {const { t } = useTranslation(['receive', 'common'])const { theme } = useTheme()- const navigation = useNavigation()const router = useRouter()const toast = useToast()const role = useTransferStore((s) => s.role)@@ -44,13 +42,6 @@ export default function ReceiveScanScreen() {router.replace('/receive')}, [router])- useEffect(() => {- navigation.setOptions({- headerBackVisible: false,- headerLeft: () => <IconButton icon='back' label={t('common:actions.back')} onPress={goBack} />- })- }, [goBack, navigation, t, theme.colors.colorTextPrimary])-useEffect(() => {if (!permission) {void requestPermission()diff --git a/apps/mobile/app/send/preparing.tsx b/apps/mobile/app/send/preparing.tsxindex 87ecd9f..e0f4c90 100644--- a/apps/mobile/app/send/preparing.tsx+++ b/apps/mobile/app/send/preparing.tsx@@ -1,20 +1,15 @@import { useCallback, useEffect } from 'react'-import { useTheme } from '@altersend/components'import { getSendStep, isShareStep, useTransferStore } from '@altersend/domain'import { clearSenderFlow } from '@altersend/domain'-import { useTranslation } from '@altersend/locales'-import { Layout } from '@/src/components'-import { IconButton } from '@/src/components/IconButton'+import { ConfirmDialog, Layout } from '@/src/components'+import { useLeaveSessionConfirm } from '@/src/hooks/useLeaveSessionConfirm'import { PreparingView } from '@/src/transfer/send'-import { useNavigation, useRouter } from 'expo-router'+import { useRouter } from 'expo-router'export default function SendPreparingScreen() {- const { t } = useTranslation(['send', 'common'])- const { theme } = useTheme()const draftPhase = useTransferStore((s) => s.draftPhase)const connectionState = useTransferStore((s) => s.connectionState)const step = getSendStep({ draftPhase, isPeerConnected: connectionState === 'peer-connected' })- const navigation = useNavigation()const router = useRouter()useEffect(() => {@@ -24,19 +19,12 @@ export default function SendPreparingScreen() {const handleBack = useCallback(() => {clearSenderFlow()}, [])-- useEffect(() => {- navigation.setOptions({- headerBackVisible: false,- headerLeft: () => (- <IconButton icon='back' label={t('common:actions.back')} onPress={handleBack} />- )- })- }, [navigation, handleBack, t, theme.colors.colorTextPrimary])+ const { leaveDialog } = useLeaveSessionConfirm(handleBack)return (<Layout hasNativeHeader><PreparingView />+ <ConfirmDialog {...leaveDialog} /></Layout>)}diff --git a/apps/mobile/app/send/share.tsx b/apps/mobile/app/send/share.tsxindex 0cea437..c60e948 100644--- a/apps/mobile/app/send/share.tsx+++ b/apps/mobile/app/send/share.tsx@@ -1,35 +1,24 @@-import { useCallback, useEffect } from 'react'+import { useCallback } from 'react'import { Platform, View } from 'react-native'-import { Button, useTheme } from '@altersend/components'+import { Button } from '@altersend/components'import { clearSenderFlow, getSendPageCopy, getSendStep, useTransferStore } from '@altersend/domain'import { useTranslation } from '@altersend/locales'-import { Layout } from '@/src/components'-import { IconButton } from '@/src/components/IconButton'+import { ConfirmDialog, Layout } from '@/src/components'+import { useLeaveSessionConfirm } from '@/src/hooks/useLeaveSessionConfirm'import { ShareView } from '@/src/transfer/send'-import { useNavigation } from 'expo-router'export default function SendShareScreen() {const { t } = useTranslation(['send', 'common'])- const { theme } = useTheme()const draftPhase = useTransferStore((s) => s.draftPhase)const connectionState = useTransferStore((s) => s.connectionState)const step = getSendStep({ draftPhase, isPeerConnected: connectionState === 'peer-connected' })const copy = getSendPageCopy(t, step)const description = step === 'receiver_connected' ? t('send:hints.keepOpen') : copy.description- const navigation = useNavigation()const handleBack = useCallback(() => {clearSenderFlow()}, [])-- useEffect(() => {- navigation.setOptions({- headerBackVisible: false,- headerLeft: () => (- <IconButton icon='back' label={t('common:actions.back')} onPress={handleBack} />- )- })- }, [navigation, handleBack, t, theme.colors.colorTextPrimary])+ const { leaveDialog } = useLeaveSessionConfirm(handleBack)return (<Layout@@ -46,6 +35,7 @@ export default function SendShareScreen() {}><ShareView />+ <ConfirmDialog {...leaveDialog} /></Layout>)}diff --git a/apps/mobile/src/hooks/useLeaveSessionConfirm.ts b/apps/mobile/src/hooks/useLeaveSessionConfirm.tsnew file mode 100644index 0000000..a81c86c--- /dev/null+++ b/apps/mobile/src/hooks/useLeaveSessionConfirm.ts@@ -0,0 +1,50 @@+import { useState } from 'react'+import { useNavigation } from 'expo-router'+import { usePreventRemove } from 'expo-router/react-navigation'+import { useTransferStore } from '@altersend/domain'+import { useTranslation } from '@altersend/locales'+import type { ConfirmDialogProps } from '@/src/components/ConfirmDialog'++const USER_BACK_ACTIONS = new Set(['GO_BACK', 'POP'])++export function useLeaveSessionConfirm(onLeave: () => void) {+ const { t } = useTranslation(['common'])+ const navigation = useNavigation()+ const role = useTransferStore((s) => s.role)+ const [message, setMessage] = useState('')+ const [open, setOpen] = useState(false)++ usePreventRemove(true, ({ data }) => {+ if (!USER_BACK_ACTIONS.has(data.action.type)) {+ navigation.dispatch(data.action)+ return+ }++ if (role === null) {+ onLeave()+ return+ }++ setMessage(+ role === 'sender'+ ? t('common:confirm.leaveShareSession')+ : t('common:confirm.leaveReceiveSession')+ )+ setOpen(true)+ })++ const leaveDialog: ConfirmDialogProps = {+ open,+ title: t('common:actions.endSession'),+ message,+ confirmLabel: t('common:actions.continue'),+ cancelLabel: t('common:actions.cancel'),+ onConfirm: () => {+ setOpen(false)+ onLeave()+ },+ onCancel: () => setOpen(false)+ }++ return { leaveDialog }+}