Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

6.4 KB
Raw Blame
import { ActivityIndicator, Pressable, ScrollView, Text, View } from 'react-native'
import { MessageSquare } from 'lucide-react-native'
import { useMobileTranslation } from '../i18n/use-mobile-translation'
import type { MobileOnboardingStep } from './mobile-onboarding-plan'
import { mobileOnboardingStyles as styles } from './mobile-onboarding-styles'
import { NotificationOnboardingPreview } from './NotificationOnboardingPreview'
import type { MobileSessionView } from '../storage/session-view-preferences'
import { colors } from '../theme/mobile-theme'
import { useMobileColorScheme } from '../theme/use-mobile-color-scheme'

export type NotificationOnboardingChoice = 'enable' | 'skip'
export type MobileOnboardingBusyChoice = MobileSessionView | NotificationOnboardingChoice | null

type Props = {
  step: MobileOnboardingStep
  width: number
  active: boolean
  busyChoice: MobileOnboardingBusyChoice
  error: string | null
  onSessionChoice: (view: MobileSessionView) => void
  onNotificationChoice: (choice: NotificationOnboardingChoice) => void
}

export function MobileOnboardingPage({
  step,
  width,
  active,
  busyChoice,
  error,
  onSessionChoice,
  onNotificationChoice
}: Props) {
  const t = useMobileTranslation()
  useMobileColorScheme()
  const busy = busyChoice !== null
  const isSessionView = step === 'session-view'

  return (
    <ScrollView
      style={[styles.page, { width }]}
      contentContainerStyle={styles.pageContent}
      showsVerticalScrollIndicator={false}
      accessibilityElementsHidden={!active}
      importantForAccessibility={active ? 'auto' : 'no-hide-descendants'}
    >
      <View style={[styles.content, !isSessionView && styles.notificationContent]}>
        {isSessionView ? (
          <View style={styles.iconSurface}>
            <MessageSquare size={30} color={colors.textPrimary} />
          </View>
        ) : (
          <NotificationOnboardingPreview active={active} />
        )}
        <Text style={styles.title}>
          {isSessionView
            ? t('onboarding.onboardingPage.sessionViewTitle', 'How should sessions open?')
            : t(
                'onboarding.onboardingPage.notificationsTitle',
                'Don’t miss when an agent needs you'
              )}
        </Text>
        <Text style={styles.body}>
          {isSessionView
            ? t(
                'onboarding.onboardingPage.sessionViewDescription',
                'Choose whether supported agent sessions open in the terminal or Chat UI on this device. Press and hold a session tab to switch its view, or change the default later in Settings.'
              )
            : t(
                'onboarding.onboardingPage.notificationsDescription',
                'Get a notification on this phone when an agent finishes or is waiting — even if you aren’t using the app.'
              )}
        </Text>
      </View>

      <View style={styles.footer}>
        {!isSessionView ? (
          <Text style={styles.disclosure}>
            {t(
              'onboarding.onboardingPage.notificationsDisclosure',
              'Delivered through Orca’s push service after your desktop has been idle for 3 minutes. Change this anytime in Settings.'
            )}
          </Text>
        ) : null}
        {error ? (
          <Text style={styles.error} accessibilityRole="alert">
            {error}
          </Text>
        ) : null}
        {isSessionView ? (
          <SessionViewChoices busyChoice={busyChoice} disabled={busy} onChoice={onSessionChoice} />
        ) : (
          <NotificationChoices
            busyChoice={busyChoice}
            disabled={busy}
            onChoice={onNotificationChoice}
          />
        )}
      </View>
    </ScrollView>
  )
}

function SessionViewChoices({
  busyChoice,
  disabled,
  onChoice
}: {
  busyChoice: MobileOnboardingBusyChoice
  disabled: boolean
  onChoice: (view: MobileSessionView) => void
}) {
  const t = useMobileTranslation()
  return (
    <>
      <ChoiceButton
        label={t('onboarding.onboardingPage.useChatUi', 'Use Chat UI')}
        accessibilityLabel={t('onboarding.onboardingPage.openInChatUi', 'Open sessions in Chat UI')}
        primary
        busy={busyChoice === 'chat'}
        disabled={disabled}
        onPress={() => onChoice('chat')}
      />
      <ChoiceButton
        label={t('onboarding.onboardingPage.keepTerminal', 'Keep terminal')}
        accessibilityLabel={t(
          'onboarding.onboardingPage.openInTerminal',
          'Open sessions in the terminal'
        )}
        busy={busyChoice === 'terminal'}
        disabled={disabled}
        onPress={() => onChoice('terminal')}
      />
    </>
  )
}

function NotificationChoices({
  busyChoice,
  disabled,
  onChoice
}: {
  busyChoice: MobileOnboardingBusyChoice
  disabled: boolean
  onChoice: (choice: NotificationOnboardingChoice) => void
}) {
  const t = useMobileTranslation()
  return (
    <>
      <ChoiceButton
        label={t('onboarding.onboardingPage.enableNotifications', 'Enable notifications')}
        accessibilityLabel={t(
          'onboarding.onboardingPage.enableAgentNotifications',
          'Enable agent notifications'
        )}
        primary
        busy={busyChoice === 'enable'}
        disabled={disabled}
        onPress={() => onChoice('enable')}
      />
      <ChoiceButton
        label={t('onboarding.onboardingPage.notNow', 'Not now')}
        accessibilityLabel={t(
          'onboarding.onboardingPage.skipNotifications',
          'Skip notifications for now'
        )}
        busy={busyChoice === 'skip'}
        disabled={disabled}
        onPress={() => onChoice('skip')}
      />
    </>
  )
}

function ChoiceButton({
  label,
  accessibilityLabel,
  primary = false,
  busy,
  disabled,
  onPress
}: {
  label: string
  accessibilityLabel?: string
  primary?: boolean
  busy: boolean
  disabled: boolean
  onPress: () => void
}) {
  useMobileColorScheme()
  return (
    <Pressable
      accessibilityRole="button"
      accessibilityLabel={accessibilityLabel}
      disabled={disabled}
      style={({ pressed }) => [
        primary ? styles.primaryButton : styles.secondaryButton,
        pressed && styles.buttonPressed,
        disabled && styles.buttonDisabled
      ]}
      onPress={onPress}
    >
      {busy ? (
        <ActivityIndicator color={primary ? colors.bgBase : colors.textSecondary} />
      ) : (
        <Text style={primary ? styles.primaryButtonText : styles.secondaryButtonText}>{label}</Text>
      )}
    </Pressable>
  )
}