refactor(ui): 合入 B2 —— 侧边对话附件与图片状态接入统一组件层

This commit is contained in:
Menghuan1918 committed 2026-11-25 01:00:09 +08:00
commit 09e9e046ae
3 files changed
+15 -40

No files matched your search

+2 -32
View File
@@ -927,42 +927,12 @@
background: var(--dsw-alias-bg-base);
}
/* A declined read is a reader-visible fact, not a broken image: one quiet
* line in the chip's own typography. */
.sidechatAttachmentFailed {
font-size: var(--dsh-content-font-size-secondary, 13px);
line-height: calc(18px + var(--dsh-content-font-delta-secondary, 0px));
font-family: var(--dsw-font-family);
color: var(--dsw-alias-label-tertiary);
}
/* The main conversation's file card: type glyph, name, size. */
/* A file attachment is the shared list row now; this wrapper only keeps the
* chip's width bounds and the hover tooltip the row's ellipsis needs. */
.sidechatAttachmentFile {
display: inline-flex;
align-items: center;
gap: 6px;
min-width: 0;
max-width: 100%;
padding: 3px 6px;
border: 1px solid var(--dsw-alias-border-l2);
border-radius: 6px;
font-size: var(--dsh-content-font-size-secondary, 13px);
line-height: calc(18px + var(--dsh-content-font-delta-secondary, 0px));
font-family: var(--dsw-font-family);
color: var(--dsw-alias-label-secondary);
}
.sidechatAttachmentName {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: var(--dsw-alias-label-primary);
}
.sidechatAttachmentSize {
flex: none;
color: var(--dsw-alias-label-tertiary);
}
@keyframes sidechatRowIn {
+9 -5
View File
@@ -27,6 +27,7 @@ import type {
SidechatImageAttachment,
} from './sidechat-transcript.ts'
import { t } from './locales.ts'
import { ListRow, StatusLine } from './ui/index.ts'
import css from './SideChatView.module.css'
/** What one attachment read is currently worth rendering. */
@@ -180,7 +181,7 @@ function AttachmentThumbnail(props: {
const { ctx, sessionId, image } = props
const state = useAttachmentImage(ctx, sessionId, image)
if (state.status === 'failed') {
return <span className={css.sidechatAttachmentFailed}>{t('sideChatAttachmentImageFailed')}</span>
return <StatusLine plain text={t('sideChatAttachmentImageFailed')} />
}
if (state.status !== 'ready') return null
return (
@@ -192,14 +193,17 @@ function AttachmentThumbnail(props: {
)
}
/** One non-image file: the host's name + size chip, with no byte read. */
/** One non-image file: the host's name + size row, with no byte read. The
* wrapper keeps the chip's hover tooltip, which the row's own ellipsis needs. */
function FileChip({ file }: { file: SidechatFileAttachment }): React.ReactNode {
const size = file.bytes === undefined ? '' : fileSizeText(file.bytes)
return (
<span className={css.sidechatAttachmentFile} title={file.name}>
<FileTypeIcon path={file.name} size={16} />
<span className={css.sidechatAttachmentName}>{file.name}</span>
{size === '' ? null : <span className={css.sidechatAttachmentSize}>{size}</span>}
<ListRow
leading={<FileTypeIcon path={file.name} size={16} />}
title={file.name}
{...(size === '' ? {} : { meta: size })}
/>
</span>
)
}
+4 -3
View File
@@ -2,6 +2,7 @@ import { useEffect, useState } from 'react'
import type { SidechatImageOccurrence } from '../sidechat-images.ts'
import { hostRouteUrl } from './host-route-url.ts'
import { t } from './locales.ts'
import { Notice, StatusLine } from './ui/index.ts'
import css from './SideChatView.module.css'
function SavedImage({ childId, messageId, image, visible }: { childId: string; messageId: string; image: SidechatImageOccurrence; visible: boolean }): React.ReactNode {
@@ -22,14 +23,14 @@ function SavedImage({ childId, messageId, image, visible }: { childId: string; m
}).catch(() => { if (!controller.signal.aborted) setState({ unavailable: true }) })
return () => { controller.abort(); if (url !== undefined) URL.revokeObjectURL(url) }
}, [childId, messageId, image.blockIndex, visible])
if (state === null) return <span>{t('sideChatImageLoading')}</span>
if ('unavailable' in state) return <span role="status">{t('sideChatImageUnavailable')}</span>
if (state === null) return <Notice kind="loading" tone="inline">{t('sideChatImageLoading')}</Notice>
if ('unavailable' in state) return <StatusLine plain role="status" text={t('sideChatImageUnavailable')} />
return <a href={state.url} target="_blank" rel="noreferrer"><img className={css.sidechatImage} src={state.url} alt={image.name ?? t('sideChatImage')} onError={() => { setState({ unavailable: true }) }} /></a>
}
export function SidechatImages({ childId, messageId, images, visible }: { childId?: string; messageId?: string; images?: readonly SidechatImageOccurrence[]; visible: boolean }): React.ReactNode {
if (images === undefined || images.length === 0) return null
return <div className={css.sidechatImages}>{images.map(image => childId === undefined || messageId === undefined
? <span key={image.blockIndex}>{t('sideChatImageUnavailable')}</span>
? <StatusLine key={image.blockIndex} plain text={t('sideChatImageUnavailable')} />
: <SavedImage key={`${messageId}:${image.blockIndex}`} childId={childId} messageId={messageId} image={image} visible={visible} />)}</div>
}