From f6dd52b690a4bf5bd74bc04b81b1a9a23737cd20 Mon Sep 17 00:00:00 2001 From: QQ Date: Sat, 14 Nov 2026 14:14:58 +0800 Subject: [PATCH] Import apps/android/src/screens/chat/task-progress-checklist.tsx --- .../screens/chat/task-progress-checklist.tsx | 349 ++++++++++++++++++ 1 file changed, 349 insertions(+) create mode 100644 apps/android/src/screens/chat/task-progress-checklist.tsx diff --git a/apps/android/src/screens/chat/task-progress-checklist.tsx b/apps/android/src/screens/chat/task-progress-checklist.tsx new file mode 100644 index 0000000..43d1a42 --- /dev/null +++ b/apps/android/src/screens/chat/task-progress-checklist.tsx @@ -0,0 +1,349 @@ +import React, { memo, useEffect, useMemo, useRef, useState } from 'react' +import { + Animated, + Easing, + Platform, + Pressable, + ScrollView, + StyleSheet, + Text, + useWindowDimensions, + View, +} from 'react-native' +import Svg, { Circle, Path } from 'react-native-svg' +import { ChevronDown, ChevronUp } from 'lucide-react-native' +import { IconChecklistOutline } from '../../ui/dsh-icons' +import { strings } from '../../locales/i18n' +import { radius, spacing, type as typography, type ThemeColors } from '../../ui/theme' +import { useTheme } from '../../ui/theme-context' +import { useThemedStyles } from '../../ui/use-themed-styles' + +export type TodoStatus = 'pending' | 'in_progress' | 'completed' + +export interface TodoItem { + content: string + status: TodoStatus +} + +export type TaskGlyphKind = 'hollow-circle' | 'blue-circle' | 'checkmark' + +/** Map status to glyph visual semantic */ +export function taskStatusGlyphKind(status: TodoStatus): TaskGlyphKind { + switch (status) { + case 'completed': return 'checkmark' + case 'in_progress': return 'blue-circle' + case 'pending': return 'hollow-circle' + } +} + +/** Pure progress derivation for task checklist */ +export function formatTaskProgress(todos: readonly TodoItem[]): { + done: number + total: number + progressText: string + activeItem: TodoItem | null +} { + const done = todos.filter(t => t.status === 'completed').length + const total = todos.length + const activeItem = todos.find(t => t.status === 'in_progress') ?? null + return { + done, + total, + progressText: `${done}/${total}`, + activeItem, + } +} + +/** Localized status label matching sessionActivity dictionary */ +export function taskStatusLabel( + status: TodoStatus, + copy: typeof strings.sessionActivity, +): string { + switch (status) { + case 'completed': return copy.complete + case 'in_progress': return copy.active + case 'pending': return copy.pending + } +} + +export interface TaskProgressChecklistProps { + todos: readonly TodoItem[] + expanded?: boolean + onToggle?: () => void + defaultExpanded?: boolean + maxHeight?: number + testID?: string +} + +/** + * Task status glyph matching DeepSeek Harness StateDot appearance="step": + * - pending: hollow circle (空心圆) + * - in_progress: blue circle with animated rotating spinner (蓝色圆圈) + * - completed: green circular badge with checkmark (完成后显示勾选) + */ +export const TaskStatusGlyph = memo(function TaskStatusGlyph({ + status, + colors, + size = 16, +}: { + status: TodoStatus + colors: ThemeColors + size?: number +}) { + const spinAnim = useRef(new Animated.Value(0)).current + + useEffect(() => { + if (status !== 'in_progress') return + const animation = Animated.loop( + Animated.timing(spinAnim, { + toValue: 1, + duration: 1500, + easing: Easing.linear, + useNativeDriver: Platform.OS !== 'web', + isInteraction: false, + }), + ) + animation.start() + return () => animation.stop() + }, [status, spinAnim]) + + if (status === 'completed') { + return ( + + + + + + + ) + } + + if (status === 'in_progress') { + const spin = spinAnim.interpolate({ + inputRange: [0, 1], + outputRange: ['0deg', '360deg'], + }) + return ( + + + + + + + ) + } + + // pending: hollow circle + return ( + + + + + + ) +}) + +/** + * 1:1 DeepSeek Harness Task Progress Checklist (TodoPanel) for mobile: + * - Task list: displays the steps planned by AI + * - Task status: hollow circle (pending), blue circle (in_progress), checkmark (completed) + * - Progress stats: 0/n indicating 0 out of n completed + * - Real-time updates: dynamic reactive rendering on session projection changes + * - Collapsible / expandable: user can fold or expand to view detailed tasks + */ +export const TaskProgressChecklist = memo(function TaskProgressChecklist({ + todos, + expanded, + onToggle, + defaultExpanded = false, + maxHeight, + testID = 'task-progress-checklist', +}: TaskProgressChecklistProps) { + const { colors } = useTheme() + const styles = useThemedStyles(createStyles) + const copy = strings.sessionActivity + const { height } = useWindowDimensions() + const [internalOpen, setInternalOpen] = useState(defaultExpanded) + + const isControlled = expanded !== undefined + const isOpen = isControlled ? expanded : internalOpen + + const handleToggle = () => { + if (!isControlled) { + setInternalOpen(prev => !prev) + } + onToggle?.() + } + + if (!todos || todos.length === 0) return null + + const { done: completed, total, progressText } = useMemo(() => formatTaskProgress(todos), [todos]) + const listMaxHeight = maxHeight ?? Math.min(220, height * 0.28) + + const statusLabel = (status: TodoStatus) => { + switch (status) { + case 'completed': return copy.complete + case 'in_progress': return copy.active + case 'pending': return copy.pending + } + } + + return ( + + [styles.header, pressed && styles.pressed]} + testID={`${testID}-header`} + > + + + + + {copy.taskChecklist || copy.todos} + + + + {progressText} + + + + {isOpen ? ( + + ) : ( + + )} + + + + {isOpen && ( + + + + {todos.map((todo, index) => ( + + + + + + {todo.content} + + + ))} + + + )} + + ) +}) + +const createStyles = (colors: ThemeColors) => + StyleSheet.create({ + card: { + borderRadius: radius.xl, + backgroundColor: colors.card, + borderWidth: 1, + borderColor: colors.border, + overflow: 'hidden', + }, + header: { + minHeight: 44, + paddingHorizontal: spacing.sm, + paddingVertical: spacing.xs, + flexDirection: 'row', + alignItems: 'center', + gap: spacing.xs, + }, + pressed: { + backgroundColor: colors.surfaceStrong, + }, + leadIcon: { + width: 20, + height: 20, + alignItems: 'center', + justifyContent: 'center', + }, + title: { + ...typography.smallStrong, + color: colors.ink, + flexShrink: 1, + }, + progressContainer: { + flex: 1, + alignItems: 'flex-start', + paddingLeft: spacing.xxs, + }, + progress: { + ...typography.small, + color: colors.muted, + fontVariant: ['tabular-nums'], + }, + chevron: { + width: 20, + height: 20, + alignItems: 'center', + justifyContent: 'center', + }, + contentWrap: { + paddingBottom: spacing.xs, + }, + divider: { + height: StyleSheet.hairlineWidth, + backgroundColor: colors.separator, + marginHorizontal: spacing.sm, + marginBottom: spacing.xs, + }, + list: { + paddingHorizontal: spacing.sm, + }, + item: { + flexDirection: 'row', + alignItems: 'flex-start', + gap: spacing.xs, + paddingVertical: spacing.xs, + minHeight: 32, + }, + glyphWrap: { + width: 20, + height: 20, + alignItems: 'center', + justifyContent: 'center', + marginTop: 1, + }, + itemContent: { + ...typography.small, + color: colors.ink, + flex: 1, + lineHeight: 20, + }, + })