🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
💄 style(chat-input): show one upload spinner on image cards (#23096)
YuTengjing385e8f453a8b
diff --git a/src/features/ChatInput/Desktop/ContextContainer/ContextItem/ImageCard.tsx b/src/features/ChatInput/Desktop/ContextContainer/ContextItem/ImageCard.tsxindex b8cff22b7fd..32a2b5e8c4f 100644--- a/src/features/ChatInput/Desktop/ContextContainer/ContextItem/ImageCard.tsx+++ b/src/features/ChatInput/Desktop/ContextContainer/ContextItem/ImageCard.tsx@@ -1,7 +1,7 @@-import { ActionIcon, Icon, Progress, Tooltip } from '@lobehub/ui';+import { ActionIcon, Icon, Tooltip } from '@lobehub/ui';import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';import * as stylex from '@stylexjs/stylex';-import { CircleAlertIcon, Loader2Icon, RotateCwIcon, XIcon } from 'lucide-react';+import { CircleAlertIcon, RotateCwIcon, XIcon } from 'lucide-react';import { memo } from 'react';import { useTranslation } from 'react-i18next';@@ -12,6 +12,7 @@ import { useFileStore } from '@/store/file';import { type UploadFileItem } from '@/types/files/upload';import { openFilePreviewModal } from './FilePreviewModal.loader';+import UploadIndicator from './UploadIndicator';import UploadTooltipContent from './UploadTooltipContent';import { getUploadChipState } from './utils';@@ -112,12 +113,12 @@ interface ImageCardProps extends UploadFileItem {}const ImageCard = memo<ImageCardProps>(({ number, ...item }) => {- const { errorCode, file, id, previewUrl, status } = item;+ const { errorCode, file, id, previewUrl } = item;const { t } = useTranslation(['chat', 'common']);const contextKey = useChatInputUploadKey();const removeChatUploadFile = useFileStore((s) => s.removeChatUploadFile);const retryChatUploadFile = useFileStore((s) => s.retryChatUploadFile);- const { busy, canRetry, indicator, progress } = getUploadChipState(item);+ const { busy, canRetry, indicator } = getUploadChipState(item);const src = previewUrl || item.fileUrl || item.base64Url;const handlePreview = useEventCallback(() => {@@ -144,35 +145,8 @@ const ImageCard = memo<ImageCardProps>(({ number, ...item }) => {</Tooltip>{(busy || canRetry) && (<div {...stylex.props(styles.overlay)}>- {indicator === 'progress' ? (- <span- aria-label={t('upload.preview.status.uploading')}- aria-valuemax={100}- aria-valuemin={0}- aria-valuenow={progress}- role={'progressbar'}- >- <Progress- percent={progress ?? 0}- showInfo={false}- size={24}- status={'normal'}- type={'circle'}- />- </span>- ) : indicator === 'loading' ? (- <Icon- spin- icon={Loader2Icon}- size={20}- aria-label={t(- status === 'processing'- ? 'upload.preview.status.processing'- : status === 'pending'- ? 'upload.preview.status.pending'- : 'upload.preview.status.uploading',- )}- />+ {indicator === 'busy' ? (+ <UploadIndicator label={t('upload.preview.status.uploading')} size={24} />) : (<><Icondiff --git a/src/features/ChatInput/Desktop/ContextContainer/ContextItem/UploadIndicator.tsx b/src/features/ChatInput/Desktop/ContextContainer/ContextItem/UploadIndicator.tsxnew file mode 100644index 00000000000..620162be32a--- /dev/null+++ b/src/features/ChatInput/Desktop/ContextContainer/ContextItem/UploadIndicator.tsx@@ -0,0 +1,53 @@+import { Progress } from '@lobehub/ui';+import * as stylex from '@stylexjs/stylex';++import { sx } from '@/styles/sx';++/** Arc length of the spinning ring. */+const ARC_PERCENT = 25;++const spin = stylex.keyframes({+ from: { transform: 'rotate(0deg)' },+ to: { transform: 'rotate(360deg)' },+});++const styles = stylex.create({+ root: {+ display: 'inline-flex',+ flexShrink: 0,+ alignItems: 'center',+ justifyContent: 'center',+ animationName: spin,+ animationDuration: '0.9s',+ animationTimingFunction: 'linear',+ animationIterationCount: 'infinite',+ },+});++interface UploadIndicatorProps {+ label: string;+ size: number;+}++/**+ * One spinning ring for the whole upload. Users do not need the internal steps (hashing,+ * transfer, server processing); switching between a progress ring and a separate spinner icon+ * per step made the indicator change size and shape mid-upload.+ */+const UploadIndicator = ({ label, size }: UploadIndicatorProps) => (+ <span {...sx(styles.root, { height: size, width: size })}>+ <Progress+ aria-label={label}+ // The arc is decorative: announce the upload, not a fake 25%.+ aria-valuenow={undefined}+ aria-valuetext={label}+ percent={ARC_PERCENT}+ showInfo={false}+ size={size}+ status={'normal'}+ type={'circle'}+ />+ </span>+);++export default UploadIndicator;diff --git a/src/features/ChatInput/Desktop/ContextContainer/ContextItem/index.tsx b/src/features/ChatInput/Desktop/ContextContainer/ContextItem/index.tsxindex 40926c428cf..de26700e5de 100644--- a/src/features/ChatInput/Desktop/ContextContainer/ContextItem/index.tsx+++ b/src/features/ChatInput/Desktop/ContextContainer/ContextItem/index.tsx@@ -1,7 +1,7 @@-import { ActionIcon, Flexbox, Icon, Progress, Tag, Tooltip } from '@lobehub/ui';+import { ActionIcon, Flexbox, Icon, Tag, Tooltip } from '@lobehub/ui';import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';import * as stylex from '@stylexjs/stylex';-import { CircleAlertIcon, CircleCheckIcon, Loader2Icon, RotateCwIcon } from 'lucide-react';+import { CircleAlertIcon, CircleCheckIcon, RotateCwIcon } from 'lucide-react';import { memo } from 'react';import { useTranslation } from 'react-i18next';@@ -13,6 +13,7 @@ import { type UploadFileItem } from '@/types/files/upload';import Content from './Content';import { openFilePreviewModal } from './FilePreviewModal.loader';+import UploadIndicator from './UploadIndicator';import UploadTooltipContent from './UploadTooltipContent';import { useUploadCompletion } from './useUploadCompletion';import { getFileBasename, getUploadChipSize, getUploadChipState } from './utils';@@ -55,7 +56,7 @@ const ContextItem = memo<FileItemProps>((props) => {const contextKey = useChatInputUploadKey();const removeChatUploadFile = useFileStore((s) => s.removeChatUploadFile);const retryChatUploadFile = useFileStore((s) => s.retryChatUploadFile);- const { busy, canPreview, canRetry, indicator, progress } = getUploadChipState(props);+ const { busy, canPreview, canRetry, indicator } = getUploadChipState(props);const basename = getFileBasename(file.name);const sizeLabel = getUploadChipSize(props);const showCompletion = useUploadCompletion(status);@@ -93,36 +94,8 @@ const ContextItem = memo<FileItemProps>((props) => {size={12}style={{ color: cssVar.colorSuccess }}/>- ) : indicator === 'loading' ? (- <Icon- spin- icon={Loader2Icon}- size={12}- aria-label={t(- status === 'processing'- ? 'upload.preview.status.processing'- : status === 'pending'- ? 'upload.preview.status.pending'- : 'upload.preview.status.uploading',- )}- />- ) : indicator === 'progress' ? (- <span- aria-label={t('upload.preview.status.uploading')}- aria-valuemax={100}- aria-valuemin={0}- aria-valuenow={progress}- {...stylex.props(styles.statusIcon)}- role={'progressbar'}- >- <Progress- percent={progress ?? 0}- showInfo={false}- size={12}- status={'normal'}- type={'circle'}- />- </span>+ ) : indicator === 'busy' ? (+ <UploadIndicator label={t('upload.preview.status.uploading')} size={12} />) : (<Icon icon={CircleAlertIcon} size={12} style={{ color: cssVar.colorError }} />)}diff --git a/src/features/ChatInput/Desktop/ContextContainer/ContextItem/utils.test.ts b/src/features/ChatInput/Desktop/ContextContainer/ContextItem/utils.test.tsindex 36c65a2bdf1..3484fc2d9b0 100644--- a/src/features/ChatInput/Desktop/ContextContainer/ContextItem/utils.test.ts+++ b/src/features/ChatInput/Desktop/ContextContainer/ContextItem/utils.test.ts@@ -7,24 +7,21 @@ import { getUploadChipSize, getUploadChipState } from './utils';const uploadState = (progress: number) => ({ progress, restTime: 0, speed: 0 });describe('getUploadChipState', () => {- it.each(['pending', 'processing'] as const)(- 'shows an indeterminate indicator for %s',- (status) => {- expect(getUploadChipState({ status, uploadState: uploadState(100) })).toMatchObject({- busy: true,- canPreview: false,- canRetry: false,- indicator: 'loading',- });- },- );+ it.each(['pending', 'processing'] as const)('shows the busy indicator for %s', (status) => {+ expect(getUploadChipState({ status, uploadState: uploadState(100) })).toMatchObject({+ busy: true,+ canPreview: false,+ canRetry: false,+ indicator: 'busy',+ });+ });- it('shows upload progress, then marks the upload complete', () => {+ it('tracks upload progress, then marks the upload complete', () => {expect(getUploadChipState({ status: 'uploading', uploadState: uploadState(42) })).toMatchObject({busy: true,canPreview: false,- indicator: 'progress',+ indicator: 'busy',progress: 42,},);@@ -49,17 +46,28 @@ describe('getUploadChipState', () => {);it.each([undefined, Number.NaN, Number.POSITIVE_INFINITY])(- 'uses indeterminate feedback when progress is unavailable (%s)',+ 'drops unmeasurable progress (%s)',(progress) => {expect(getUploadChipState({status: 'uploading',uploadState: progress === undefined ? undefined : uploadState(progress),- }).indicator,- ).toBe('loading');+ }),+ ).toMatchObject({ indicator: 'busy', progress: undefined });},);+ it('keeps one busy indicator from pending through processing', () => {+ // A separate spinner for pending/processing made the indicator shrink and change shape mid-upload.+ const steps = [+ getUploadChipState({ status: 'pending', uploadState: uploadState(0) }),+ getUploadChipState({ status: 'uploading', uploadState: uploadState(42) }),+ getUploadChipState({ status: 'processing', uploadState: uploadState(100) }),+ ];++ expect(steps.map((step) => step.indicator)).toEqual(['busy', 'busy', 'busy']);+ });+it.each([[-10, 0],[0, 0],diff --git a/src/features/ChatInput/Desktop/ContextContainer/ContextItem/utils.ts b/src/features/ChatInput/Desktop/ContextContainer/ContextItem/utils.tsindex 686347d6bc1..b4b9be617bb 100644--- a/src/features/ChatInput/Desktop/ContextContainer/ContextItem/utils.ts+++ b/src/features/ChatInput/Desktop/ContextContainer/ContextItem/utils.ts@@ -47,19 +47,15 @@ export const getUploadChipState = ({typeof rawProgress === 'number' && Number.isFinite(rawProgress)? Math.min(100, Math.max(0, rawProgress)): undefined;+ const indicator: 'busy' | 'error' | 'file' =+ status === 'error' || status === 'cancelled' ? 'error' : busy ? 'busy' : 'file';return {busy,canPreview: status === 'success',canRetry: status === 'error' || status === 'cancelled',- indicator:- status === 'error' || status === 'cancelled'- ? 'error'- : status === 'uploading' && progress !== undefined- ? 'progress'- : busy- ? 'loading'- : 'file',+ /** Every busy step shares one `busy` indicator, so users see a single spinner throughout. */+ indicator,progress,};};