Import apps/android/src/screens/bot-sidebar-section.tsx

This commit is contained in:
QQ 2026-11-17 08:27:21 +08:00
parent 1accc4d2b3
commit c950c0225a
1 changed files with 51 additions and 38 deletions

View File

@ -1,7 +1,6 @@
import { useEffect, useMemo, useState } from 'react'
import {
ActivityIndicator,
Alert,
Modal,
Pressable,
ScrollView,
@ -35,6 +34,7 @@ import {
Users,
X,
} from 'lucide-react-native'
import { isVisibleSession } from '../lib/session-visibility'
import { strings as s } from '../locales/i18n'
import { browseScope } from '../services/browse-memory'
import {
@ -56,6 +56,7 @@ import { useTheme, type ThemeColors } from '../ui/theme-context'
import { useResponsiveLayout } from '../ui/responsive'
import { useThemedStyles } from '../ui/use-themed-styles'
import { ModalSurface } from './chat/modal'
import { ConfirmDialog } from './chat/confirm-dialog'
import { resolveSessionDisplayTitle } from './session-title'
import { BotAgentBadge, engineOfModel } from './bot/agent-badge'
import { BotAvatar, BotAvatarWithBadge } from './bot/avatar'
@ -148,7 +149,7 @@ function formatBotListTimestamp(updatedAt?: number): string {
return `${hh}:${mm}`
}
if (date.getFullYear() === now.getFullYear()) {
return `${date.getMonth() + 1}月${date.getDate()}日`
return date.toLocaleDateString(s.time.locale, { month: 'short', day: 'numeric' })
}
return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`
}
@ -554,8 +555,9 @@ export function BotSidebarSection({
{state !== undefined && showAgents && agents.map(agent =>
agent.sessions
.filter(sid => {
if (!query) return true
const matched = sessionMap.get(sid)
if (matched && !isVisibleSession(matched, selectedId, query)) return false
if (!query) return true
const title = (matched ? resolveSessionDisplayTitle(matched) : undefined) ?? s.sessions.untitled
return title.toLocaleLowerCase().includes(query)
})
@ -661,16 +663,8 @@ export function BotModalsHost() {
const performAdapter: BotPerform = (operation, payload) => perform(operation, payload)
const confirmDelete = (kind: 'bot' | 'room', id: string) => {
Alert.alert(s.bots.delete, s.bots.deleteHint, [
{ text: s.bots.cancel, style: 'cancel' },
{
text: s.bots.delete,
style: 'destructive',
onPress: () => void perform(kind === 'bot' ? 'delete-bot' : 'delete-room', { id }),
},
])
}
const [deleteConfirm, setDeleteConfirm] = useState<{ kind: 'bot' | 'room'; id: string } | undefined>()
const confirmDelete = (kind: 'bot' | 'room', id: string) => setDeleteConfirm({ kind, id })
const menuBot = contextMenu?.kind === 'bot' ? state?.bots.find(b => b.id === contextMenu.id) : undefined
const menuRoom = contextMenu?.kind === 'room' ? state?.rooms.find(r => r.id === contextMenu.id) : undefined
@ -773,6 +767,31 @@ export function BotModalsHost() {
return (
<>
<BotFloatingPopover
visible={contextMenu !== undefined && contextActions.length > 0}
actions={contextActions}
onClose={() => setContextMenu(undefined)}
anchor="top-right"
topOffset={120}
/>
{state !== undefined && (
<BotProfilePage
visible={detailsOpen && Boolean(detailBot || detailRoom)}
covered={editor !== undefined}
bot={detailBot}
room={detailRoom}
state={state}
client={clientInstance}
busy={busy}
error={visibleError}
runStats={runStats}
onClose={() => setDetailsOpen(false)}
onEdit={() => setEditor({ kind: detailBot ? 'bot' : 'room', id: (detailBot ?? detailRoom)?.id ?? selectedId })}
perform={performAdapter}
/>
)}
{editor !== undefined && state !== undefined && clientInstance !== undefined && (
<BotEditor
key={`${editor.kind}:${editor.id ?? 'new'}`}
@ -788,30 +807,6 @@ export function BotModalsHost() {
/>
)}
<BotFloatingPopover
visible={contextMenu !== undefined && contextActions.length > 0}
actions={contextActions}
onClose={() => setContextMenu(undefined)}
anchor="top-right"
topOffset={120}
/>
{state !== undefined && (
<BotProfilePage
visible={detailsOpen && Boolean(detailBot || detailRoom)}
bot={detailBot}
room={detailRoom}
state={state}
client={clientInstance}
busy={busy}
error={visibleError}
runStats={runStats}
onClose={() => setDetailsOpen(false)}
onEdit={() => setEditor({ kind: detailBot ? 'bot' : 'room', id: selectedId })}
perform={performAdapter}
/>
)}
{report !== undefined && (
<Modal
transparent
@ -831,6 +826,24 @@ export function BotModalsHost() {
</ModalSurface>
</Modal>
)}
<ConfirmDialog
visible={deleteConfirm !== undefined}
title={s.bots.delete}
message={s.bots.deleteHint}
onClose={() => setDeleteConfirm(undefined)}
buttons={[
{ label: s.bots.cancel },
{
label: s.bots.delete,
danger: true,
onPress: () => {
if (!deleteConfirm) return
void perform(deleteConfirm.kind === 'bot' ? 'delete-bot' : 'delete-room', { id: deleteConfirm.id })
},
},
]}
/>
</>
)
}
@ -889,7 +902,7 @@ export function DsBotInstallCard({ error, loading = false, onRetry }: { error?:
const rows = [
{ label: s.plugins.installDesktop, value: 'ds-bot' },
{ label: s.plugins.installCli, value: 'dsh plugin --profile web add -w ds-bot' },
{ label: 'GitHub 安装地址(无法连接 npm 时填入)', value: 'github:Fei2411/DS-Bot#main&path:/ds-bot' },
{ label: s.plugins.installGithub, value: 'github:Fei2411/DS-Bot#main&path:/ds-bot' },
]
return (
<View style={styles.sectionBlock}>