Skip to content

🤯 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.

💄 style(chat-input): remove the position number from image cards (#23118)

YuTengjing79d33dd430cb
diff --git a/src/features/ChatInput/Desktop/ContextContainer/ContextItem/ImageCard.tsx b/src/features/ChatInput/Desktop/ContextContainer/ContextItem/ImageCard.tsx
index 32a2b5e8c4f..1507c14d5f9 100644
--- a/src/features/ChatInput/Desktop/ContextContainer/ContextItem/ImageCard.tsx
+++ b/src/features/ChatInput/Desktop/ContextContainer/ContextItem/ImageCard.tsx
@@ -57,20 +57,6 @@ const styles = stylex.create({
borderWidth: 0,
backgroundColor: 'transparent',
},
- badge: {
- pointerEvents: 'none',
- position: 'absolute',
- insetBlockStart: '4px',
- insetInlineStart: '4px',
- paddingInline: '4px',
- borderRadius: cssVar.borderRadiusSM,
- fontSize: '11px',
- fontVariantNumeric: 'tabular-nums',
- fontWeight: 500,
- lineHeight: '16px',
- color: cssVar.colorText,
- backgroundColor: `color-mix(in srgb, ${cssVar.colorBgContainer} 85%, transparent)`,
- },
close: {
cursor: 'pointer',
position: 'absolute',
@@ -107,12 +93,7 @@ const styles = stylex.create({
overlayActions: { pointerEvents: 'auto' },
});
-interface ImageCardProps extends UploadFileItem {
- /** Position among the draft's images; matches the inline `[Image #N]` references. */
- number?: number;
-}
-
-const ImageCard = memo<ImageCardProps>(({ number, ...item }) => {
+const ImageCard = memo<UploadFileItem>((item) => {
const { errorCode, file, id, previewUrl } = item;
const { t } = useTranslation(['chat', 'common']);
const contextKey = useChatInputUploadKey();
@@ -171,7 +152,6 @@ const ImageCard = memo<ImageCardProps>(({ number, ...item }) => {
)}
</div>
)}
- {number !== undefined && <span {...stylex.props(styles.badge)}>#{number}</span>}
<button
aria-label={t('upload.image.remove', { name: file.name })}
type={'button'}
diff --git a/src/features/ChatInput/Desktop/ContextContainer/ContextList.tsx b/src/features/ChatInput/Desktop/ContextContainer/ContextList.tsx
index aaaa67ebe23..f3b2c5ac7c7 100644
--- a/src/features/ChatInput/Desktop/ContextContainer/ContextList.tsx
+++ b/src/features/ChatInput/Desktop/ContextContainer/ContextList.tsx
@@ -1,10 +1,10 @@
import { Flexbox, ScrollShadow } from '@lobehub/ui';
import * as stylex from '@stylexjs/stylex';
-import { memo, useMemo } from 'react';
+import { memo } from 'react';
import { useChatInputUploadKey } from '@/features/ChatInput/hooks/useChatInputUpload';
import { useChatInputStore } from '@/features/ChatInput/store';
-import { getImageUploadNumbers, isImageUpload } from '@/features/ChatInput/utils/imageUploads';
+import { isImageUpload } from '@/features/ChatInput/utils/imageUploads';
import { fileChatSelectors, useFileStore } from '@/store/file';
import ContextItem from './ContextItem';
@@ -32,7 +32,6 @@ const ContextList = memo(() => {
);
const hasSelections = showSelectionList && selectionList.length > 0;
- const imageNumbers = useMemo(() => getImageUploadNumbers(inputFilesList), [inputFilesList]);
if (!showFileList && !showSelectionList) return null;
if (inputFilesList.length === 0 && !hasSelections) return null;
@@ -60,13 +59,13 @@ const ContextList = memo(() => {
<SelectionItem key={item.id} {...item} />
),
)}
- {inputFilesList.map((item, index) => {
+ {inputFilesList.map((item) => {
// Keyed by the preview URL when there is one: the id changes from the file name to
// the server id once the upload finishes, which would remount the card.
const key = item.previewUrl ?? item.id;
return isImageUpload(item) ? (
- <ImageCard key={key} number={imageNumbers[index]} {...item} />
+ <ImageCard key={key} {...item} />
) : (
<ContextItem key={key} {...item} />
);
diff --git a/src/features/ChatInput/InputEditor/ImageRefTag/ImageRefTagNode.ts b/src/features/ChatInput/InputEditor/ImageRefTag/ImageRefTagNode.ts
index 0da89807b90..9497f60da89 100644
--- a/src/features/ChatInput/InputEditor/ImageRefTag/ImageRefTagNode.ts
+++ b/src/features/ChatInput/InputEditor/ImageRefTag/ImageRefTagNode.ts
@@ -30,8 +30,9 @@ export const formatImageRef = (number: number) => `[Image #${number}]`;
*
* `src` is the upload's local preview URL, which identifies the upload for its whole
* lifetime. `number` is the image's position among the draft's images; it is kept in sync
- * with the attachment list, so the chip, the thumbnail badge and the `[Image #N]` text the
- * model receives always agree.
+ * with the attachment list, so the chip and the `[Image #N]` text the model receives always
+ * agree. The image cards themselves show no number: a sent message's images are read back
+ * without an order, so a number there would promise a position the message cannot keep.
*
* `fileId` is the uploaded file's id, recorded once the upload finishes. It survives in the
* sent message's editor data, so a reference restored into the composer, whose image now has
diff --git a/src/features/ChatInput/InputEditor/ImageRefTag/useImageRefTagSync.ts b/src/features/ChatInput/InputEditor/ImageRefTag/useImageRefTagSync.ts
index e82a212ea58..3a9c8121d96 100644
--- a/src/features/ChatInput/InputEditor/ImageRefTag/useImageRefTagSync.ts
+++ b/src/features/ChatInput/InputEditor/ImageRefTag/useImageRefTagSync.ts
@@ -44,7 +44,7 @@ export const planImageRefSync = (
* Keeps inline image references already in the draft (from editor data saved before new
* references stopped being inserted) in step with the draft's image uploads: a removed image
* takes its references with it, and the remaining references follow the images' new numbers.
- * Attaching an image adds no reference; the numbered image cards identify it.
+ * Attaching an image adds no reference.
*/
export const useImageRefTagSync = (editor: IEditor | undefined) => {
const key = useChatInputUploadKey();
diff --git a/src/features/ChatInput/utils/imageUploads.ts b/src/features/ChatInput/utils/imageUploads.ts
index 1e5f0a74dbd..3d6c6c667cb 100644
--- a/src/features/ChatInput/utils/imageUploads.ts
+++ b/src/features/ChatInput/utils/imageUploads.ts
@@ -11,11 +11,11 @@ const isSendableImageUpload = (item: Pick<UploadFileItem, 'file' | 'status'>): b
* 1-based position of each upload among the draft's image uploads, aligned with `files`
* (`undefined` for non-image uploads and for images that failed to upload).
*
- * The number shown on the thumbnail badge and on inline `[Image #N]` references is the
- * image's position in the message's image list, so the model can match a reference with
- * the N-th image it receives. Removing an image renumbers the rest, and the badges and
- * references follow together. Positions are used instead of ids because an upload's id is
- * its file name until the upload finishes, and pasted images often share one.
+ * The number on inline `[Image #N]` references (only in editor data saved before new
+ * references stopped being inserted) is the image's position in the message's image list,
+ * so the model can match a reference with the N-th image it receives. Removing an image
+ * renumbers the rest, and the references follow. Positions are used instead of ids because
+ * an upload's id is its file name until the upload finishes, and pasted images often share one.
*/
export const getImageUploadNumbers = (files: UploadFileItem[]): (number | undefined)[] => {
let count = 0;