From 69a8463852b6cac6815fd92007dd92b4d8bb8b4d Mon Sep 17 00:00:00 2001 From: QQ Date: Sat, 14 Nov 2026 14:13:23 +0800 Subject: [PATCH] Import apps/android/src/screens/bot/reference-chat-modal.tsx --- .../src/screens/bot/reference-chat-modal.tsx | 457 ++++++++++++++++++ 1 file changed, 457 insertions(+) create mode 100644 apps/android/src/screens/bot/reference-chat-modal.tsx diff --git a/apps/android/src/screens/bot/reference-chat-modal.tsx b/apps/android/src/screens/bot/reference-chat-modal.tsx new file mode 100644 index 0000000..4a6badd --- /dev/null +++ b/apps/android/src/screens/bot/reference-chat-modal.tsx @@ -0,0 +1,457 @@ +import { useEffect, useMemo, useState } from 'react' +import { Modal, Pressable, ScrollView, StyleSheet, Text, TextInput, View } from 'react-native' +import * as Haptics from 'expo-haptics' +import { CalendarDays, MessageSquare, Search, X } from 'lucide-react-native' +import { strings } from '../../locales/i18n' +import type { BotState } from '../../services/bot-catalog' +import { useAppStore } from '../../state/store' +import { useBotTeamStore } from '../../state/bot-store' +import { GroupCard, GroupRow, IconButton } from '../../ui/components' +import { OfficialMenuIcons } from '../../ui/official-menu-icons' +import { useResponsiveLayout } from '../../ui/responsive' +import { radius, spacing, type } from '../../ui/theme' +import { useTheme, type ThemeColors } from '../../ui/theme-context' +import { useThemedStyles } from '../../ui/use-themed-styles' +import { ModalSurface } from '../chat/modal' +import { relativeTime } from '../chat/presentation' +import { buildReferenceChatGroups, type ReferenceChatCandidate } from './at-menu' +import { BotAvatar } from './avatar' + +export function BotPlusMenuModal({ + visible, + onClose, + onReferenceChat, + onOpenSchedules, +}: { + visible: boolean + onClose: () => void + onReferenceChat: () => void + onOpenSchedules?: () => void +}) { + const styles = useThemedStyles(createStyles) + return ( + + + + {strings.chat.moreActions} + + + + + { + onClose() + onReferenceChat() + }} + /> + {onOpenSchedules !== undefined && ( + { + onClose() + onOpenSchedules() + }} + /> + )} + + + + + ) +} + +export function ReferenceChatModal({ + visible, + currentSessionId, + currentBotId, + botState: propBotState, + onClose, + onPick, +}: { + visible: boolean + currentSessionId?: string + currentBotId?: string + botState?: BotState + onClose: () => void + onPick: (mentionText: string, candidate: ReferenceChatCandidate) => void +}) { + const { colors } = useTheme() + const styles = useThemedStyles(createStyles) + const { sheetMaxHeight } = useResponsiveLayout() + const sessions = useAppStore(state => state.sessions) + const workspaces = useAppStore(state => state.workspaces) + const archivedSessionIds = useAppStore(state => state.archivedSessionIds) + const storeBotState = useBotTeamStore(state => state.state) + const refreshBotState = useBotTeamStore(state => state.refresh) + const effectiveBotState = propBotState ?? storeBotState + + const [query, setQuery] = useState('') + + useEffect(() => { + if (!visible) { + setQuery('') + return + } + if (effectiveBotState === undefined) { + void refreshBotState(false) + } + }, [visible, effectiveBotState, refreshBotState]) + + const groups = useMemo( + () => + buildReferenceChatGroups({ + state: effectiveBotState, + sessions, + workspaces, + currentSessionId, + currentBotId, + archivedSessionIds, + query, + }), + [effectiveBotState, sessions, workspaces, currentSessionId, currentBotId, archivedSessionIds, query], + ) + + const isEmpty = groups.bots.length === 0 && groups.conversations.length === 0 + + const handleSelect = (item: ReferenceChatCandidate) => { + void Haptics.selectionAsync().catch(() => undefined) + onPick(item.mentionText, item) + onClose() + } + + return ( + + + + + 引用对话 + 选择一段其他 Bot 对话或 DSH 会话作为上下文 + + + + + + + + {query.length > 0 && ( + setQuery('')} + > + + + )} + + + + {isEmpty && ( + + + {strings.mention.noMatches} + + + )} + + {groups.bots.length > 0 && ( + + {strings.bots.title} + + {groups.bots.map((item, index) => ( + handleSelect(item)} + style={({ pressed }) => [ + styles.candidateRow, + index > 0 && styles.rowDivider, + pressed && styles.rowPressed, + ]} + > + {item.bot ? ( + + ) : ( + + + + )} + + + + {item.mentionLabel} + + {item.updatedAt !== undefined && ( + {relativeTime(item.updatedAt)} + )} + + {item.description !== undefined && ( + + {item.description} + + )} + + + ))} + + + )} + + {groups.conversations.length > 0 && ( + + {strings.mention.sessionSection} + + {groups.conversations.map((item, index) => ( + handleSelect(item)} + style={({ pressed }) => [ + styles.candidateRow, + index > 0 && styles.rowDivider, + pressed && styles.rowPressed, + ]} + > + + + + + + + {item.title} + + {item.updatedAt !== undefined && ( + {relativeTime(item.updatedAt)} + )} + + {item.description !== undefined && ( + + {item.description} + + )} + + + ))} + + + )} + + + + ) +} + +export function ReferencedChatPills({ + items, + onRemove, +}: { + items: readonly ReferenceChatCandidate[] + onRemove: (sessionId: string) => void +}) { + const { colors } = useTheme() + const styles = useThemedStyles(createStyles) + if (items.length === 0) return null + return ( + + + {items.map(item => ( + + {item.bot ? ( + + ) : ( + + )} + + 引用:{item.mentionLabel} + + onRemove(item.sessionId)} + style={styles.referencePillRemove} + > + + + + ))} + + + ) +} + +function createStyles(colors: ThemeColors) { + return StyleSheet.create({ + header: { + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'space-between', + gap: spacing.sm, + paddingBottom: spacing.xs, + }, + grow: { flex: 1, minWidth: 0 }, + title: { + ...type.heading, + fontSize: 18, + fontWeight: '700', + color: colors.ink, + }, + subtitle: { + ...type.caption, + color: colors.muted, + marginTop: 2, + }, + sheetBody: { + paddingBottom: spacing.md, + }, + searchBar: { + flexDirection: 'row', + alignItems: 'center', + gap: spacing.xs, + paddingHorizontal: spacing.md, + height: 42, + borderRadius: radius.pill, + backgroundColor: colors.surfaceStrong, + marginBottom: spacing.xs, + }, + searchInput: { + flex: 1, + ...type.body, + fontSize: 15, + color: colors.ink, + paddingVertical: 0, + }, + scrollContent: { + gap: spacing.sm, + paddingBottom: spacing.lg, + }, + sectionBlock: { + gap: 6, + }, + sectionHeading: { + ...type.smallStrong, + fontSize: 13, + color: colors.muted, + paddingHorizontal: spacing.xs, + }, + candidateRow: { + flexDirection: 'row', + alignItems: 'center', + gap: spacing.sm, + paddingHorizontal: spacing.md, + paddingVertical: 10, + minHeight: 54, + }, + rowDivider: { + borderTopWidth: StyleSheet.hairlineWidth, + borderTopColor: colors.separator, + }, + rowPressed: { + backgroundColor: colors.surfaceStrong, + }, + sessionIconWrap: { + width: 34, + height: 34, + borderRadius: radius.md, + backgroundColor: colors.primarySoft, + alignItems: 'center', + justifyContent: 'center', + }, + candidateBody: { + flex: 1, + minWidth: 0, + gap: 2, + }, + candidateTitleRow: { + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'space-between', + gap: spacing.xs, + }, + candidateTitle: { + ...type.bodyStrong, + fontSize: 15, + color: colors.ink, + flex: 1, + }, + candidateTime: { + ...type.caption, + color: colors.subtle, + }, + candidateDesc: { + ...type.caption, + fontSize: 12.5, + color: colors.muted, + }, + emptyWrap: { + paddingVertical: spacing.lg, + alignItems: 'center', + }, + emptyText: { + ...type.small, + color: colors.muted, + }, + pillsContainer: { + flexGrow: 0, + flexShrink: 0, + }, + pillsScroll: { + flexGrow: 0, + }, + pillsRow: { + flexDirection: 'row', + alignItems: 'center', + gap: 6, + paddingHorizontal: 4, + paddingTop: 2, + paddingBottom: 2, + }, + referencePill: { + flexDirection: 'row', + alignItems: 'center', + gap: 6, + maxWidth: 260, + paddingLeft: 10, + paddingRight: 8, + paddingVertical: 5, + borderRadius: radius.pill, + backgroundColor: colors.primarySoft, + borderWidth: StyleSheet.hairlineWidth, + borderColor: colors.primary, + }, + referencePillText: { + ...type.smallStrong, + fontSize: 13, + color: colors.primary, + flexShrink: 1, + }, + referencePillRemove: { + padding: 2, + }, + }) +}