mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
* refactor(mobile): give relay and encryption concrete owners * refactor(mobile): organize session and review feature owners * refactor(mobile): organize RPC and host ownership * test(mobile): point render fixtures at concrete owners * refactor(mobile): use explicit type-only owner imports
110 lines
3.8 KiB
TypeScript
110 lines
3.8 KiB
TypeScript
import { Fragment, useCallback } from 'react'
|
|
import { DetailCardFocusBoundary } from '../components/detail-card-host'
|
|
import { Platform, Pressable, StyleSheet, Text, type View } from 'react-native'
|
|
import type { SessionTitleCard } from './tabs/use-session-title-card'
|
|
import { StatusDot } from '../components/StatusDot'
|
|
import type { ConnectionState } from '../transport/connection/connection-state'
|
|
import { styles } from './mobile-session-styles'
|
|
import { useMobileTranslation } from '../i18n/use-mobile-translation'
|
|
import { pressedStyle } from '../theme/mobile-theme'
|
|
import { useKeyboardPersistingTaps } from '../platform/keyboard-persisting-taps'
|
|
|
|
/** The session's title and status line. A tap opens a card with the full name, where it lives
|
|
* and its host, as desktop's tab card does, because a sideways phone cuts the title short. */
|
|
export function MobileSessionTitleBlock({
|
|
title,
|
|
connState,
|
|
details,
|
|
meta,
|
|
centered = false,
|
|
showConnectionRetry,
|
|
onRetry
|
|
}: {
|
|
title: string
|
|
connState: ConnectionState
|
|
details: SessionTitleCard
|
|
meta: string
|
|
/** Sits in NavBar's centre slot rather than beside the tabs. */
|
|
centered?: boolean
|
|
showConnectionRetry: boolean
|
|
onRetry: () => void
|
|
}): React.JSX.Element {
|
|
const t = useMobileTranslation()
|
|
// Why: opening the card must keep a focused field's keyboard. 'always' because the whole block
|
|
// is one button; 'handled' would let its own text through.
|
|
const titleKeepsKeyboard = useKeyboardPersistingTaps('always')
|
|
const { openerRef } = details
|
|
const attachOpener = useCallback(
|
|
(view: View | null) => {
|
|
openerRef.current = view
|
|
titleKeepsKeyboard(view)
|
|
},
|
|
[openerRef, titleKeepsKeyboard]
|
|
)
|
|
return (
|
|
<>
|
|
<DetailCardFocusBoundary refs={details.boundaryRefs} index={0} active={details.active} />
|
|
<Fragment key="title">
|
|
<Pressable
|
|
style={({ pressed }) => [
|
|
centered
|
|
? centeredStyles.block
|
|
: [
|
|
styles.sessionTitleBlock,
|
|
details.besideTabs && styles.sessionTitleBlockBesideTabs
|
|
],
|
|
pressed && pressedStyle
|
|
]}
|
|
ref={attachOpener}
|
|
onLayout={details.onAnchorLayout}
|
|
onPress={details.toggle}
|
|
aria-expanded={details.requestedOpen}
|
|
accessibilityRole="button"
|
|
accessibilityHint={t(
|
|
'session.header.workspaceDetailsHint',
|
|
'Shows the full workspace name and where it is'
|
|
)}
|
|
>
|
|
<Text
|
|
ref={details.titleRef}
|
|
onLayout={details.onAnchorLayout}
|
|
onPress={Platform.OS === 'web' ? details.toggle : undefined}
|
|
style={[styles.sessionTitle, centered && centeredStyles.title]}
|
|
numberOfLines={1}
|
|
>
|
|
{title}
|
|
</Text>
|
|
<Pressable
|
|
style={({ pressed }) => [styles.sessionMetaRow, pressed && pressedStyle]}
|
|
disabled={!showConnectionRetry}
|
|
onPress={onRetry}
|
|
accessibilityRole={showConnectionRetry ? 'button' : undefined}
|
|
accessibilityLabel={
|
|
showConnectionRetry
|
|
? t('session.header.reconnectToDesktop', 'Reconnect to desktop')
|
|
: undefined
|
|
}
|
|
>
|
|
<StatusDot state={connState} />
|
|
<Text style={styles.sessionMetaText} numberOfLines={1}>
|
|
{meta}
|
|
</Text>
|
|
</Pressable>
|
|
</Pressable>
|
|
</Fragment>
|
|
<DetailCardFocusBoundary refs={details.boundaryRefs} index={1} active={details.active} />
|
|
</>
|
|
)
|
|
}
|
|
|
|
const centeredStyles = StyleSheet.create({
|
|
block: {
|
|
maxWidth: '100%',
|
|
alignItems: 'center'
|
|
},
|
|
// NavBar's title size, so the session bar reads like every other screen's.
|
|
title: {
|
|
fontSize: 16
|
|
}
|
|
})
|