Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

3.7 KB
Raw Blame
import { Button, HStack, Spacer, ProgressView, Text, TextField } from '@expo/ui/swift-ui';
import { accessibilityLabel, buttonStyle, contentShape, shapes, disabled, font, foregroundStyle, frame } from '@expo/ui/swift-ui/modifiers';
import { useTranslation } from 'react-i18next';
import { useTheme } from '@/theme';
import { ComposerSheet } from './ComposerSheet';
import { ComposerNativeSection as Section } from './ComposerNativeSection';
import { CompanionPortraitPicker } from './CompanionPortraitPicker';
import { CompanionNativeContent } from './CompanionNativeContent.ios';
import type { CompanionCreateNativeViewProps } from './CompanionCreateNativeView';
import { useNativeTextDraft } from './nativeTextDraft';

export function CompanionCreateNativeView(p: CompanionCreateNativeViewProps) {
  const { t } = useTranslation(); const { colors } = useTheme();
  const name = typeof p.values.name === 'string' ? p.values.name : '';
  const nameField = useNativeTextDraft(name, next => p.onChange({ ...p.values, name: next }));
  const tr = (key: string) => t(`devices.companionProfile.${key}`, { deviceName: p.deviceName });
  return <ComposerSheet visible={p.visible} onClose={p.onClose} onClosed={p.onClosed} title={tr('create')} nativeContent preventDismiss={p.dirty || p.busy}>
    {!p.online || p.error || p.duplicate ? <Section><Text modifiers={[font({ textStyle: 'footnote' }), foregroundStyle(colors.textSecondary)]}>{tr(!p.online ? 'offline' : p.duplicate || p.nameTaken ? 'nameTaken' : 'createFailed')}</Text></Section> : null}
    {p.loading ? <Section><ProgressView /></Section> : null}
    {p.panel ? <>
      <Section title={tr('name')}><TextField text={nameField.text} onTextChange={nameField.onTextChange} maxLength={200} testID="companionCreate.name" modifiers={[accessibilityLabel(tr('name')), disabled(p.busy || !p.online || !!p.locked)]} /></Section>
      <Section title={tr('avatar')}><CompanionNativeContent><CompanionPortraitPicker value={String(p.values.avatarImageBase64 ?? '')} onChange={avatarImageBase64 => p.onChange({ ...p.values, avatarImageBase64 })} disabled={p.busy || !p.online || !!p.locked} /></CompanionNativeContent></Section>
      {p.models ? <Section><CompanionNativeContent>{p.models}</CompanionNativeContent></Section> : null}
    </> : null}
    <Section>{!p.panel && !p.loading && p.online ? <Button onPress={p.onRetry} modifiers={[buttonStyle('plain'), disabled(p.busy), frame({ minHeight: 44 })]}><HStack modifiers={[frame({ maxWidth: Infinity, minHeight: 44 }), contentShape(shapes.rectangle())]}><Text>{t('devices.resources.retry')}</Text><Spacer /></HStack></Button> : null}
      {p.onImport ? <Button onPress={p.onImport} modifiers={[buttonStyle('plain'), frame({ minHeight: 44 }), disabled(p.busy || !p.online || !!p.locked)]}><HStack modifiers={[frame({ maxWidth: Infinity, minHeight: 44 }), contentShape(shapes.rectangle())]}><Text>{t('devices.companionImport.entry')}</Text><Spacer /></HStack></Button> : null}
      <Button onPress={p.onSubmit} testID="companionCreate.submit" modifiers={[buttonStyle('plain'), frame({ minHeight: 44 }), disabled(p.busy || !p.online || !p.panel?.action || p.panel.action.disabled || !name.trim() || !p.values.avatarImageBase64 || !!p.duplicate || !!p.modelMissing)]}><HStack modifiers={[frame({ maxWidth: Infinity, minHeight: 44 }), contentShape(shapes.rectangle())]}><Text>{tr('create')}</Text><Spacer /></HStack></Button>
      <Button onPress={p.onClose} modifiers={[buttonStyle('plain'), frame({ minHeight: 44 }), disabled(p.busy)]}><HStack modifiers={[frame({ maxWidth: Infinity, minHeight: 44 }), contentShape(shapes.rectangle())]}><Text>{t('devices.common.cancel')}</Text><Spacer /></HStack></Button>
    </Section>
  </ComposerSheet>;
}