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.

♻️ refactor(acceptance): split the responsive review surfaces into files (#19371)

Arvin Xu2ad20b62f668
diff --git a/src/features/Acceptance/Viewer/Checks/CheckList.test.ts b/src/features/Acceptance/Viewer/Checks/CheckList.test.ts
index 9d27c66e4ef..8ca4fb971ed 100644
--- a/src/features/Acceptance/Viewer/Checks/CheckList.test.ts
+++ b/src/features/Acceptance/Viewer/Checks/CheckList.test.ts
@@ -1,16 +1,15 @@
import { describe, expect, it } from 'vitest';
import { hasAnnotatableEvidence, hasVisualEvidence } from '../Evidence/evidence';
+import { mergeRejectComments, serializeReviewAnnotations } from '../Review/rejectDraft';
import {
canDismissRejectModal,
CHECK_REJECT_MODAL_SIZE,
checkRejectModalShell,
checkRejectModalSize,
- mergeRejectComments,
rejectModalTitle,
- serializeReviewAnnotations,
TEXT_REJECT_MODAL_WIDTH,
-} from '../Review/CheckRejectModal';
+} from '../Review/rejectModalShell';
import {
checkFilterState,
focusedCheckStates,
diff --git a/src/features/Acceptance/Viewer/Evidence/DesktopEvidenceReview.tsx b/src/features/Acceptance/Viewer/Evidence/DesktopEvidenceReview.tsx
new file mode 100644
index 00000000000..3a381478649
--- /dev/null
+++ b/src/features/Acceptance/Viewer/Evidence/DesktopEvidenceReview.tsx
@@ -0,0 +1,254 @@
+'use client';
+
+import { Flexbox, TextArea } from '@lobehub/ui';
+import { ActionIcon, Button, Text } from '@lobehub/ui/base-ui';
+import { createStaticStyles, cssVar, cx } from 'antd-style';
+import { ZoomIn, ZoomOut } from 'lucide-react';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { ZOOM_STEPS } from '../Review/rejectDraft';
+import type { RejectReviewModel } from '../Review/useRejectReview';
+import { AttachmentStrip, AttachmentUploadButton } from './attachments';
+import { EvidenceStage } from './EvidenceStage';
+import { RegionNotes } from './RegionNotes';
+
+const styles = createStaticStyles(({ css }) => ({
+ body: css`
+ overflow: hidden;
+ display: flex;
+ flex: 1;
+ flex-direction: column;
+
+ min-height: 0;
+ `,
+ footer: css`
+ flex: none;
+ padding-block-start: 12px;
+ border-block-start: 1px solid ${cssVar.colorBorderSecondary};
+ `,
+ /** Stage and notes side by side β€” the pointer that circles a region is the
+ same one that types about it, so neither should scroll the other away. */
+ stageRow: css`
+ display: flex;
+ flex: 1;
+ gap: 16px;
+ min-height: 0;
+ `,
+ notes: css`
+ overflow-y: auto;
+ display: flex;
+ flex: none;
+ flex-direction: column;
+ gap: 12px;
+
+ width: 320px;
+ min-width: 0;
+ `,
+ thumb: css`
+ cursor: pointer;
+
+ overflow: hidden;
+
+ width: 72px;
+ height: 48px;
+ border: 2px solid transparent;
+ border-radius: ${cssVar.borderRadius};
+
+ img {
+ display: block;
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+ }
+ `,
+ thumbActive: css`
+ border-color: ${cssVar.colorPrimary};
+ `,
+ /** The zoom pill floats bottom-center over the stage β€” controls live with
+ the thing they control, not in a detached toolbar row. */
+ zoomBar: css`
+ position: absolute;
+ z-index: 5;
+ inset-block-end: 16px;
+ inset-inline-start: 50%;
+ transform: translateX(-50%);
+
+ display: flex;
+ gap: 4px;
+ align-items: center;
+
+ padding-block: 4px;
+ padding-inline: 8px;
+ border: 1px solid ${cssVar.colorBorderSecondary};
+ border-radius: 99px;
+
+ background: ${cssVar.colorBgElevated};
+ box-shadow: ${cssVar.boxShadowSecondary};
+ `,
+ zoomLabel: css`
+ min-width: 44px;
+
+ font-size: 12px;
+ font-variant-numeric: tabular-nums;
+ color: ${cssVar.colorTextSecondary};
+ text-align: center;
+ `,
+}));
+
+interface DesktopEvidenceReviewProps {
+ /** Names the check in the text-only reject, which has no evidence to point at. */
+ checkTitle: string;
+ model: RejectReviewModel;
+}
+
+/**
+ * Desktop reject: a wide stage with the region notes parked beside it, and the
+ * delivery-wide note plus the decision in a footer that never scrolls away.
+ */
+export const DesktopEvidenceReview = memo<DesktopEvidenceReviewProps>(({ checkTitle, model }) => {
+ const { t } = useTranslation('verify');
+ const {
+ activeAnnotations,
+ activeEvidence,
+ attachments,
+ canSubmit,
+ canvas,
+ close,
+ comment,
+ evidence,
+ failed,
+ handlePaste,
+ hasEvidence,
+ loading,
+ uploading,
+ zoom,
+ } = model;
+
+ return (
+ <div className={styles.body}>
+ {activeEvidence && (
+ <Flexbox flex={1} gap={12} style={{ minHeight: 0 }}>
+ <Flexbox gap={12} height={'100%'} style={{ minHeight: 0 }}>
+ {evidence.length > 1 && (
+ <Flexbox horizontal gap={8} style={{ overflowX: 'auto', flex: 'none' }}>
+ {evidence.map((item, index) => (
+ <button
+ aria-pressed={item.id === activeEvidence.id}
+ key={item.id}
+ style={{ flexShrink: 0 }}
+ type={'button'}
+ aria-label={t('acceptance.review.imageNumber', {
+ current: index + 1,
+ total: evidence.length,
+ })}
+ className={cx(
+ styles.thumb,
+ item.id === activeEvidence.id && styles.thumbActive,
+ )}
+ onClick={() => model.selectEvidence(index)}
+ >
+ <img alt={''} src={item.fileUrl} />
+ </button>
+ ))}
+ </Flexbox>
+ )}
+ <div className={styles.stageRow} style={{ position: 'relative' }}>
+ <EvidenceStage
+ drawing
+ annotations={activeAnnotations}
+ src={activeEvidence.fileUrl}
+ zoom={zoom}
+ onDraw={canvas.onDraw}
+ onRemove={canvas.onRemove}
+ onUpdate={canvas.onUpdate}
+ />
+ <div className={styles.zoomBar}>
+ <ActionIcon
+ disabled={zoom <= ZOOM_STEPS[0]}
+ icon={ZoomOut}
+ size={'small'}
+ title={t('acceptance.review.zoomOut')}
+ onClick={() => model.stepZoom(-1)}
+ />
+ <span className={styles.zoomLabel}>{Math.round(zoom * 100)}%</span>
+ <ActionIcon
+ disabled={zoom >= ZOOM_STEPS.at(-1)!}
+ icon={ZoomIn}
+ size={'small'}
+ title={t('acceptance.review.zoomIn')}
+ onClick={() => model.stepZoom(1)}
+ />
+ </div>
+ <div className={styles.notes}>
+ <Flexbox gap={2}>
+ <Text strong fontSize={13}>
+ {t('acceptance.review.regionComments')}
+ </Text>
+ <Text fontSize={12} type={'secondary'}>
+ {t('acceptance.review.annotateHint')}
+ </Text>
+ </Flexbox>
+ {activeAnnotations.length === 0 && (
+ <Text fontSize={12} type={'secondary'}>
+ {t('acceptance.review.regionCommentsEmpty')}
+ </Text>
+ )}
+ <RegionNotes
+ annotations={activeAnnotations}
+ onChange={model.editAnnotation}
+ onRemove={model.removeAnnotation}
+ />
+ </div>
+ </div>
+ </Flexbox>
+ </Flexbox>
+ )}
+ <div className={styles.footer}>
+ {failed && (
+ <Text role={'alert'} type={'danger'}>
+ {t('acceptance.review.submitFailed')}
+ </Text>
+ )}
+ <Flexbox gap={10} style={{ width: '100%' }}>
+ <Text fontSize={12} type={'secondary'}>
+ {hasEvidence
+ ? t('acceptance.review.supplement')
+ : t('acceptance.review.rejectDescription', { title: checkTitle })}
+ </Text>
+ <TextArea
+ autoSize={{ maxRows: 5, minRows: 2 }}
+ placeholder={t('acceptance.review.rejectPlaceholder')}
+ value={comment}
+ onChange={(event) => model.setComment(event.target.value)}
+ onPaste={handlePaste}
+ />
+ <Flexbox horizontal align={'flex-start'} gap={8}>
+ <Flexbox horizontal flex={1} gap={8}>
+ <AttachmentUploadButton disabled={loading} onFiles={model.uploadFiles} />
+ <AttachmentStrip
+ attachments={attachments}
+ disabled={loading}
+ uploading={uploading}
+ onRemove={model.removeAttachment}
+ />
+ </Flexbox>
+ <Button disabled={loading} onClick={close}>
+ {t('acceptance.actions.cancel')}
+ </Button>
+ <Button
+ disabled={!canSubmit}
+ loading={loading}
+ type={'primary'}
+ onClick={model.submitReject}
+ >
+ {t('acceptance.review.confirmReject')}
+ </Button>
+ </Flexbox>
+ </Flexbox>
+ </div>
+ </div>
+ );
+});
+
+DesktopEvidenceReview.displayName = 'AcceptanceDesktopEvidenceReview';
diff --git a/src/features/Acceptance/Viewer/Evidence/EvidenceStage.tsx b/src/features/Acceptance/Viewer/Evidence/EvidenceStage.tsx
new file mode 100644
index 00000000000..80d55f4fec6
--- /dev/null
+++ b/src/features/Acceptance/Viewer/Evidence/EvidenceStage.tsx
@@ -0,0 +1,115 @@
+'use client';
+
+import type { AcceptanceReviewAnnotation } from '@lobechat/types';
+import { createStaticStyles, cssVar } from 'antd-style';
+import { memo, useEffect, useRef } from 'react';
+
+import type { DraftAnnotation } from './Annotation';
+import { AnnotationCanvas } from './Annotation';
+import { useMeasuredWidth } from './useMeasuredWidth';
+
+type Rect = AcceptanceReviewAnnotation['rect'];
+
+const styles = createStaticStyles(({ css }) => ({
+ /** The zoom stage β€” its native scrolling doubles as panning. Flex plus the
+ inner frame's `margin: auto` keeps the image centered when it fits, and
+ scrolls from the edges once it grows past it. */
+ viewport: css`
+ overflow: auto;
+ overscroll-behavior: contain;
+ display: flex;
+ flex: 1;
+
+ min-width: 0;
+ min-height: 120px;
+ border: 1px solid ${cssVar.colorBorderSecondary};
+ border-radius: ${cssVar.borderRadiusLG};
+
+ background: ${cssVar.colorFillQuaternary};
+ `,
+ /** `margin: auto` absorbs the free space on both axes (centering) and
+ collapses to 0 on overflow. */
+ viewportInner: css`
+ margin: auto;
+ `,
+}));
+
+const SWIPE_MIN_PX = 60;
+/** A swipe has to be decisively horizontal, or vertical reading steals images. */
+const SWIPE_AXIS_RATIO = 1.5;
+
+interface EvidenceStageProps {
+ annotations: DraftAnnotation[];
+ /** Drags mark regions instead of panning. */
+ drawing: boolean;
+ onDraw: (rect: Rect) => void;
+ onRemove: (index: number) => void;
+ /** Step to the previous (-1) or next (1) image. Touch only. */
+ onSwipe?: (direction: 1 | -1) => void;
+ onUpdate: (index: number, rect: Rect) => void;
+ src: string;
+ /** Coarse pointer: allow page panning and swipe-to-switch at 1x. */
+ touch?: boolean;
+ zoom: number;
+}
+
+/**
+ * The evidence image at a zoom level, with its circled regions on top.
+ *
+ * It owns the scroll container because the container IS the pan surface and the
+ * width the zoom multiplies. Measuring lives here for the same reason: a host
+ * that measured a node it does not render ends up observing a detached element
+ * the moment the layout swaps (see useMeasuredWidth).
+ */
+export const EvidenceStage = memo<EvidenceStageProps>(
+ ({ annotations, drawing, onDraw, onRemove, onSwipe, onUpdate, src, touch, zoom }) => {
+ const { node, ref, width } = useMeasuredWidth<HTMLDivElement>();
+ const swipeStart = useRef<{ x: number; y: number } | null>(null);
+ const canSwipe = Boolean(touch && onSwipe) && !drawing && zoom === 1;
+
+ // A new image starts at the top-left; carrying the previous pan offset would
+ // open the next screenshot scrolled to nowhere in particular.
+ useEffect(() => {
+ node?.scrollTo(0, 0);
+ }, [node, src]);
+
+ return (
+ <div
+ className={styles.viewport}
+ ref={ref}
+ style={{ touchAction: canSwipe ? 'pan-y pinch-zoom' : undefined }}
+ onTouchEnd={(event) => {
+ const start = swipeStart.current;
+ swipeStart.current = null;
+ const point = event.changedTouches[0];
+ if (!start || !point) return;
+ const dx = point.clientX - start.x;
+ const dy = point.clientY - start.y;
+ if (Math.abs(dx) > SWIPE_MIN_PX && Math.abs(dx) > Math.abs(dy) * SWIPE_AXIS_RATIO)
+ onSwipe?.(dx < 0 ? 1 : -1);
+ }}
+ onTouchStart={(event) => {
+ const point = event.touches[0];
+ swipeStart.current =
+ canSwipe && event.touches.length === 1 ? { x: point.clientX, y: point.clientY } : null;
+ }}
+ >
+ <div className={styles.viewportInner}>
+ <AnnotationCanvas
+ annotations={annotations}
+ drawing={drawing}
+ // The border eats two pixels the image must not claim back, or the
+ // stage gains a scrollbar at exactly 100%.
+ imageWidth={width ? Math.max(width * zoom - 2, 0) : undefined}
+ src={src}
+ onDraw={onDraw}
+ onRemove={onRemove}
+ onUpdate={onUpdate}
+ />
+ </div>
+ </div>
+ );
+ },
+);
+
+EvidenceStage.displayName = 'AcceptanceEvidenceStage';
diff --git a/src/features/Acceptance/Viewer/Evidence/MobileEvidenceReview.tsx b/src/features/Acceptance/Viewer/Evidence/MobileEvidenceReview.tsx
index 5d28e326cc6..da981166495 100644
--- a/src/features/Acceptance/Viewer/Evidence/MobileEvidenceReview.tsx
+++ b/src/features/Acceptance/Viewer/Evidence/MobileEvidenceReview.tsx
@@ -1,13 +1,17 @@
'use client';
-import { Flexbox } from '@lobehub/ui';
+import { Flexbox, TextArea } from '@lobehub/ui';
import { ActionIcon, Button, Segmented, Text } from '@lobehub/ui/base-ui';
import { createStaticStyles, cssVar } from 'antd-style';
import { ChevronLeft, ChevronRight, ZoomIn, ZoomOut } from 'lucide-react';
-import type { ReactNode } from 'react';
+import { memo } from 'react';
import { useTranslation } from 'react-i18next';
-import type { MobileReviewEvent } from './mobileReviewFlow';
+import { ZOOM_STEPS } from '../Review/rejectDraft';
+import type { RejectReviewModel } from '../Review/useRejectReview';
+import { AttachmentStrip, AttachmentUploadButton } from './attachments';
+import { EvidenceStage } from './EvidenceStage';
+import { MobileRegionNotes } from './RegionNotes';
const styles = createStaticStyles(({ css }) => ({
body: css`
@@ -39,7 +43,11 @@ const styles = createStaticStyles(({ css }) => ({
min-height: 220px;
`,
editor: css`
+ display: flex;
flex: none;
+ flex-direction: column;
+ gap: 16px;
+
padding-block-start: 4px;
textarea {
@@ -61,79 +69,74 @@ const styles = createStaticStyles(({ css }) => ({
`,
}));
-interface MobileEvidenceReviewProps {
- /** Regions already drawn on the image on screen. */
- annotationCount: number;
- canSubmit: boolean;
- drawing: boolean;
- /** Region notes, the supplementary note and attachments β€” all under the image. */
- editor: ReactNode;
- failed: boolean;
- image: ReactNode;
- imageCount: number;
- imageIndex: number;
- loading: boolean;
- onConfirm: () => void;
- onImageChange: (index: number) => void;
- /** Move the browse / mark flow along β€” see mobileReviewFlow. */
- onStep: (event: MobileReviewEvent) => void;
- onZoom: (direction: 1 | -1) => void;
- zoom: number;
-}
-
/**
* Phone review on one page: look at the image, circle what is wrong, and write
* the note right where the circle landed.
*/
-export const MobileEvidenceReview = ({
- annotationCount,
- canSubmit,
- drawing,
- failed,
- editor,
- image,
- imageCount,
- imageIndex,
- loading,
- onConfirm,
- onImageChange,
- onStep,
- onZoom,
- zoom,
-}: MobileEvidenceReviewProps) => {
+export const MobileEvidenceReview = memo<{ model: RejectReviewModel }>(({ model }) => {
const { t } = useTranslation('verify');
+ const {
+ activeAnnotations,
+ activeEvidence,
+ activeIndex,
+ annotations,
+ attachments,
+ canSubmit,
+ canvas,
+ comment,
+ drawing,
+ evidence,
+ failed,
+ handlePaste,
+ loading,
+ uploading,
+ zoom,
+ } = model;
+
return (
<div className={styles.body}>
<div className={styles.scroll}>
- {imageCount > 0 && (
+ {activeEvidence && (
<>
<Flexbox horizontal align={'center'} gap={8} style={{ flex: 'none' }}>
<ActionIcon
aria-label={t('acceptance.review.previousImage')}
- disabled={imageIndex <= 0}
+ disabled={activeIndex <= 0}
icon={ChevronLeft}
size={{ blockSize: 44, size: 20 }}
- onClick={() => onImageChange(imageIndex - 1)}
+ onClick={() => model.selectEvidence(activeIndex - 1)}
/>
<Text aria-live={'polite'} style={{ flex: 1, textAlign: 'center' }}>
{t('acceptance.review.imageNumber', {
- current: imageIndex + 1,
- total: imageCount,
+ current: activeIndex + 1,
+ total: evidence.length,
})}
</Text>
<ActionIcon
aria-label={t('acceptance.review.nextImage')}
- disabled={imageIndex >= imageCount - 1}
+ disabled={activeIndex >= evidence.length - 1}
icon={ChevronRight}
size={{ blockSize: 44, size: 20 }}
- onClick={() => onImageChange(imageIndex + 1)}
+ onClick={() => model.selectEvidence(activeIndex + 1)}
/>
</Flexbox>
- <div className={styles.stage}>{image}</div>
+ <div className={styles.stage}>
+ <EvidenceStage
+ touch
+ annotations={activeAnnotations}
+ drawing={drawing}
+ src={activeEvidence.fileUrl}
+ zoom={zoom}
+ onDraw={canvas.onDraw}
+ onRemove={canvas.onRemove}
+ onSwipe={(direction) => model.selectEvidence(activeIndex + direction)}
+ onUpdate={canvas.onUpdate}
+ />
+ </div>
<Flexbox horizontal align={'center'} gap={8} style={{ flex: 'none' }}>
- {/* A mode switch, not an action button. The old single button was
- labelled with the mode it would LEAVE, so it read as a stray
- box whose 44px slab said nothing about which mode was on. */}
+ {/* A mode switch, not an action button. A single button labelled
+ with the mode it would LEAVE says nothing about which mode is
+ on, and its 44px slab sat oddly beside the small zoom icons. */}
<Segmented
size={'small'}
value={drawing ? 'draw' : 'browse'}
@@ -142,31 +145,31 @@ export const MobileEvidenceReview = ({
{ label: t('acceptance.review.drawRegion'), value: 'draw' },
]}
onChange={(value) => {
- if ((value === 'draw') !== drawing) onStep('toggle-draw');
+ if ((value === 'draw') !== drawing) model.advance('toggle-draw');
}}
/>
<Flexbox flex={1} />
<ActionIcon
aria-label={t('acceptance.review.zoomOut')}
- disabled={zoom <= 0.5}
+ disabled={zoom <= ZOOM_STEPS[0]}
icon={ZoomOut}
size={{ blockSize: 44, size: 20 }}
- onClick={() => onZoom(-1)}
+ onClick={() => model.stepZoom(-1)}
/>
<Text fontSize={12}>{Math.round(zoom * 100)}%</Text>
<ActionIcon
aria-label={t('acceptance.review.zoomIn')}
- disabled={zoom >= 4}
+ disabled={zoom >= ZOOM_STEPS.at(-1)!}
icon={ZoomIn}
size={{ blockSize: 44, size: 20 }}
- onClick={() => onZoom(1)}
+ onClick={() => model.stepZoom(1)}
/>
</Flexbox>
{/* The hint is the region's receipt: it says the box landed AND
that it is still editable, right above the note it belongs to. */}
<Text fontSize={12} style={{ flex: 'none' }} type={'secondary'}>
- {drawing && annotationCount > 0
- ? t('acceptance.review.mobileDrawnHint', { count: annotationCount })
+ {drawing && activeAnnotations.length > 0
+ ? t('acceptance.review.mobileDrawnHint', { count: activeAnnotations.length })
: t(
drawing
? 'acceptance.review.mobileDrawHint'
@@ -175,7 +178,40 @@ export const MobileEvidenceReview = ({
</Text>
</>
)}
- <div className={styles.editor}>{editor}</div>
+ <div className={styles.editor}>
+ {annotations.length > 0 && (
+ <>
+ <Text strong>{t('acceptance.review.regionComments')}</Text>
+ <MobileRegionNotes
+ annotations={annotations}
+ evidence={evidence}
+ onChange={model.editAnnotation}
+ onJump={model.jumpToRegion}
+ onRemove={model.removeAnnotation}
+ />
+ </>
+ )}
+ <Text strong>{t('acceptance.review.supplement')}</Text>
+ <TextArea
+ aria-label={t('acceptance.review.supplement')}
+ autoSize={{ maxRows: 10, minRows: 4 }}
+ placeholder={t('acceptance.review.rejectPlaceholder')}
+ style={{ fontSize: 16 }}
+ value={comment}
+ onChange={(event) => model.setComment(event.target.value)}
+ onPaste={handlePaste}
+ />
+ <AttachmentUploadButton disabled={loading} onFiles={model.uploadFiles} />
+ <AttachmentStrip
+ attachments={attachments}
+ disabled={loading}
+ uploading={uploading}
+ onRemove={model.removeAttachment}
+ />
+ <Text fontSize={12} type={'secondary'}>
+ {t('acceptance.review.draftSaved')}
+ </Text>
+ </div>
</div>
<div className={styles.footer}>
{failed && (
@@ -183,10 +219,17 @@ export const MobileEvidenceReview = ({
{t('acceptance.review.submitFailed')}
</Text>
)}
- <Button disabled={!canSubmit} loading={loading} type={'primary'} onClick={onConfirm}>
+ <Button
+ disabled={!canSubmit}
+ loading={loading}
+ type={'primary'}
+ onClick={model.submitReject}
+ >
{t('acceptance.review.confirmReject')}
</Button>
</div>
</div>
);
-};
+});
+
+MobileEvidenceReview.displayName = 'AcceptanceMobileEvidenceReview';
diff --git a/src/features/Acceptance/Viewer/Evidence/RegionNotes.tsx b/src/features/Acceptance/Viewer/Evidence/RegionNotes.tsx
new file mode 100644
index 00000000000..085079b57ad
--- /dev/null
+++ b/src/features/Acceptance/Viewer/Evidence/RegionNotes.tsx
@@ -0,0 +1,181 @@
+'use client';
+
+import { Flexbox, Icon, TextArea } from '@lobehub/ui';
+import { ActionIcon } from '@lobehub/ui/base-ui';
+import { createStaticStyles, cssVar } from 'antd-style';
+import { Crosshair, Trash2 } from 'lucide-react';
+import type { ReactNode } from 'react';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import type { DraftAnnotationEntry, RejectableEvidence } from '../Review/rejectDraft';
+
+const styles = createStaticStyles(({ css }) => ({
+ /** The badge that ties a note back to the numbered box on the image. */
+ index: css`
+ flex: none;
+
+ width: 18px;
+ height: 18px;
+ border-radius: 50%;
+
+ font-size: 11px;
+ font-weight: 600;
+ line-height: 18px;
+ color: #fff;
+ text-align: center;
+
+ background: ${cssVar.colorError};
+ `,
+ /** The phone caption: a link back to the box on the image, not a
+ button-shaped box. The tap target comes from padding around a compact
+ line, so a list of regions does not become a column of 44px slabs. */
+ jump: css`
+ cursor: pointer;
+
+ display: inline-flex;
+ gap: 5px;
+ align-items: center;
+ align-self: flex-start;
+
+ padding-block: 7px;
+ padding-inline: 2px;
+ border: none;
+
+ font-size: 13px;
+ color: ${cssVar.colorLink};
+
+ background: none;
+
+ &:active {
+ opacity: 0.6;
+ }
+ `,
+}));
+
+interface RegionNoteRowProps {
+ /** Rendered beside the field β€” the desktop's number badge. */
+ badge?: ReactNode;
+ /** Rendered above the field β€” the phone's jump-back link. */
+ caption?: ReactNode;
+ /** 16px on a phone, so focusing the field never zooms the page. */
+ fontSize?: number;
+ /** 1-based, for the accessible name and the remove label. */
+ index: number;
+ onChange: (comment: string) => void;
+ onRemove: () => void;
+ placeholder: string;
+ value: string;
+}
+
+const RegionNoteRow = memo<RegionNoteRowProps>(
+ ({ badge, caption, fontSize, index, placeholder, value, onChange, onRemove }) => {
+ const { t } = useTranslation('verify');
+
+ return (
+ <Flexbox gap={4}>
+ {caption}
+ <Flexbox horizontal align={'flex-start'} gap={8}>
+ {badge}
+ <TextArea
+ aria-label={t('acceptance.review.annotationPlaceholder', { index })}
+ autoSize={{ maxRows: 5, minRows: 1 }}
+ placeholder={placeholder}
+ style={{ flex: 1, fontSize }}
+ value={value}
+ onChange={(event) => onChange(event.target.value)}
+ />
+ <ActionIcon
+ aria-label={t('acceptance.review.removeRegion', { index })}
+ icon={Trash2}
+ size={{ blockSize: 44, size: 18 }}
+ onClick={onRemove}
+ />
+ </Flexbox>
+ </Flexbox>
+ );
+ },
+);
+
+RegionNoteRow.displayName = 'AcceptanceRegionNoteRow';
+
+interface RegionNotesProps {
+ annotations: DraftAnnotationEntry[];
+ onChange: (key: number, comment: string) => void;
+ onRemove: (key: number) => void;
+}
+
+/** Notes for the regions on the image currently on screen (desktop side panel). */
+export const RegionNotes = memo<RegionNotesProps>(({ annotations, onChange, onRemove }) => {
+ const { t } = useTranslation('verify');
+
+ return annotations.map((annotation, index) => (
+ <RegionNoteRow
+ index={index + 1}
+ key={annotation.key}
+ placeholder={t('acceptance.review.annotationPlaceholder', { index: index + 1 })}
+ value={annotation.comment}
+ badge={
+ <span className={styles.index} style={{ marginBlockStart: 6 }}>
+ {index + 1}
+ </span>
+ }
+ onChange={(comment) => onChange(annotation.key, comment)}
+ onRemove={() => onRemove(annotation.key)}
+ />
+ ));
+});
+
+RegionNotes.displayName = 'AcceptanceRegionNotes';
+
+interface MobileRegionNotesProps extends RegionNotesProps {
+ evidence: RejectableEvidence[];
+ /** Show the region's image and put the reviewer back in marking mode. */
+ onJump: (evidenceId: string) => void;
+}
+
+/**
+ * Every region across every image, in one list under the phone's stage.
+ *
+ * A phone has no side panel to park the other images' notes in, so each row
+ * says which image and region it belongs to and links back to it.
+ */
+export const MobileRegionNotes = memo<MobileRegionNotesProps>(
+ ({ annotations, evidence, onChange, onJump, onRemove }) => {
+ const { t } = useTranslation('verify');
+
+ return annotations.map((annotation, index) => {
+ const imageIndex = evidence.findIndex((item) => item.id === annotation.evidenceId);
+ const regionIndex = annotations
+ .filter((item) => item.evidenceId === annotation.evidenceId)
+ .findIndex((item) => item.key === annotation.key);
+
+ return (
+ <RegionNoteRow
+ fontSize={16}
+ index={index + 1}
+ key={annotation.key}
+ placeholder={t('acceptance.review.rejectPlaceholder')}
+ value={annotation.comment}
+ caption={
+ <button
+ className={styles.jump}
+ type={'button'}
+ onClick={() => onJump(annotation.evidenceId)}
+ >
+ <Icon icon={Crosshair} size={13} />
+ {t('acceptance.review.regionImage', {
+ image: imageIndex + 1,
+ region: regionIndex + 1,
+ })}
+ </button>
+ }
+ onChange={(comment) => onChange(annotation.key, comment)}
+ onRemove={() => onRemove(annotation.key)}
+ />
+ );
+ });
+ },
+);
+
+MobileRegionNotes.displayName = 'AcceptanceMobileRegionNotes';
diff --git a/src/features/Acceptance/Viewer/Focus/AcceptanceFocusReview.tsx b/src/features/Acceptance/Viewer/Focus/AcceptanceFocusReview.tsx
index 2384de1fcdc..1e6ab75dbd1 100644
--- a/src/features/Acceptance/Viewer/Focus/AcceptanceFocusReview.tsx
+++ b/src/features/Acceptance/Viewer/Focus/AcceptanceFocusReview.tsx
@@ -2,29 +2,12 @@
import type { AcceptanceChecklistItem } from '@lobechat/types';
import { Flexbox, Icon } from '@lobehub/ui';
-import { Button, Tag, Text } from '@lobehub/ui/base-ui';
+import { Button, Text } from '@lobehub/ui/base-ui';
import { createStaticStyles, cssVar, useResponsive } from 'antd-style';
-import {
- ArrowLeft,
- BadgeCheck,
- Ban,
- Check,
- ChevronDown,
- ChevronLeft,
- ChevronRight,
- CircleDashed,
- HelpCircle,
- PencilLine,
- Plus,
- RotateCcw,
- XCircle,
-} from 'lucide-react';
+import { ArrowLeft, ChevronDown, ChevronLeft, ChevronRight, Plus } from 'lucide-react';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
-import NavItem from '@/features/NavPanel/components/NavItem';
-
-import { checkFilterState, focusedCheckStates } from '../Checks/checkState';
import {
type AcceptanceCheck,
type CheckReviewInput,
@@ -32,7 +15,9 @@ import {
} from '../Checks/types';
import AcceptanceStatusPill from '../Header/AcceptanceStatusPill';
import { acceptanceFocusedLayout, acceptanceScrollLayout } from '../layout';
+import { FocusCheckHeading } from './FocusCheckHeading';
import { FocusedCheckDetails } from './FocusedCheckDetails';
+import { FocusOutline } from './FocusOutline';
const styles = createStaticStyles(({ css }) => ({
mobileNavigation: css`
@@ -158,7 +143,6 @@ const AcceptanceFocusReview = ({
const { t } = useTranslation('verify');
const { md = true } = useResponsive();
const [outlineOpen, setOutlineOpen] = useState(false);
- const focusedStates = focusedCheckStates(focusedCheck);
const currentIndex = orderedChecks.findIndex((check) => check.id === focusedCheck.id);
return (
@@ -207,120 +191,51 @@ const AcceptanceFocusReview = ({
{t('acceptance.checks.title')} Β· {currentIndex + 1} / {orderedChecks.length}
</Button>
)}
- <Flexbox gap={4} paddingInline={4} style={!md ? { display: 'none' } : undefined}>
- <Text strong style={{ fontSize: 15 }}>
- {subjectTitle}
- </Text>
- <Flexbox horizontal align={'center'} gap={6}>
- <AcceptanceStatusPill size={12} status={status} />
- <Text fontSize={11} type={'secondary'}>
- {t('acceptance.roundCount', { count: roundCount })}
+ {md && (
+ <Flexbox gap={4} paddingInline={4}>
+ <Text strong style={{ fontSize: 15 }}>
+ {subjectTitle}
</Text>
+ <Flexbox horizontal align={'center'} gap={6}>
+ <AcceptanceStatusPill size={12} status={status} />
+ <Text fontSize={11} type={'secondary'}>
+ {t('acceptance.roundCount', { count: roundCount })}
+ </Text>
+ </Flexbox>
</Flexbox>
- </Flexbox>
- <Flexbox
- horizontal
- align={'center'}
- gap={8}
- paddingInline={4}
- style={!md ? { display: 'none' } : undefined}
- >
- <Text strong style={{ fontSize: 13 }}>
- {t('acceptance.checks.title')}
- </Text>
- <span className={styles.countBadge}>{checks.length + standingChecks.length}</span>
- <Flexbox flex={1} />
- {onAddChecks && (
- <Button
- icon={<Icon icon={Plus} />}
- size={'small'}
- type={'text'}
- onClick={onAddChecks}
- >
- {t('acceptance.checkCreate.title')}
- </Button>
- )}
- </Flexbox>
+ )}
+ {md && (
+ <Flexbox horizontal align={'center'} gap={8} paddingInline={4}>
+ <Text strong style={{ fontSize: 13 }}>
+ {t('acceptance.checks.title')}
+ </Text>
+ <span className={styles.countBadge}>{checks.length + standingChecks.length}</span>
+ <Flexbox flex={1} />
+ {onAddChecks && (
+ <Button
+ icon={<Icon icon={Plus} />}
+ size={'small'}
+ type={'text'}
+ onClick={onAddChecks}
+ >
+ {t('acceptance.checkCreate.title')}
+ </Button>
+ )}
+ </Flexbox>
+ )}
</Flexbox>
{(md || outlineOpen) && (
<Flexbox className={styles.outlineList} flex={1}>
- {orderedChecks.map((check) => {
- const state = checkFilterState(check);
- const icon =
- state === 'accepted'
- ? BadgeCheck
- : state === 'needsFix'
- ? RotateCcw
- : state === 'ignored'
- ? Ban
- : CircleDashed;
- const color =
- state === 'accepted' ? 'success' : state === 'needsFix' ? 'error' : 'default';
-
- return (
- <NavItem
- active={check.id === focusedCheck.id}
- extra={<Icon color={cssVar.colorTextQuaternary} icon={ChevronRight} size={14} />}
- key={check.id}
- paddingBlock={acceptanceFocusedLayout.outlineItemPaddingBlock}
- paddingInline={acceptanceFocusedLayout.outlineItemPaddingInline}
- title={check.title}
- titleColor={cssVar.colorText}
- description={
- <Flexbox horizontal align={'center'} gap={8}>
- <Tag color={color} icon={<Icon icon={icon} />} size={'small'}>
- {t(`acceptance.focus.state.${state}`)}
- </Tag>
- <Text fontSize={12} type={'secondary'}>
- {t('acceptance.focus.evidenceCount', { count: check.evidence.length })}
- </Text>
- </Flexbox>
- }
- slots={{
- titlePrefix: (
- <Flexbox align={'center'} height={22} style={{ alignSelf: 'flex-start' }}>
- <Text
- style={{
- color: cssVar.colorTextQuaternary,
- fontFamily: cssVar.fontFamilyCode,
- fontSize: 11,
- }}
- >
- C{check.seq}
- </Text>
- </Flexbox>
- ),
- }}
- onClick={() => {
- onSelectCheck(check.id);
- setOutlineOpen(false);
- }}
- />
- );
- })}
- {standingChecks.length > 0 && onEditStandingCheck && (
- <Flexbox gap={4} paddingBlock={8} paddingInline={8}>
- <Text fontSize={11} type={'secondary'}>
- {t('acceptance.checkCreate.pendingGroup')}
- </Text>
- {standingChecks.map((item) => (
- <NavItem
- extra={<Icon color={cssVar.colorTextQuaternary} icon={PencilLine} />}
- key={item.id}
- paddingBlock={acceptanceFocusedLayout.outlineItemPaddingBlock}
- paddingInline={acceptanceFocusedLayout.outlineItemPaddingInline}
- title={item.name}
- titleColor={cssVar.colorText}
- description={
- <Text fontSize={12} type={'secondary'}>
- {item.method || t('acceptance.checkCreate.pendingDescription')}
- </Text>
- }
- onClick={() => onEditStandingCheck(item)}
- />
- ))}
- </Flexbox>
- )}
+ <FocusOutline
+ checks={orderedChecks}
+ focusedCheckId={focusedCheck.id}
+ standingChecks={standingChecks}
+ onEditStandingCheck={onEditStandingCheck}
+ onSelectCheck={(id) => {
+ onSelectCheck(id);
+ setOutlineOpen(false);
+ }}
+ />
</Flexbox>
)}
</Flexbox>
@@ -348,87 +263,11 @@ const AcceptanceFocusReview = ({
</Flexbox>
)}
<Flexbox className={styles.content} gap={16}>
- <Flexbox gap={acceptanceFocusedLayout.headerGap}>
- <Flexbox
- horizontal
- align={'center'}
- gap={5}
- style={{
- color:
- focusedStates.review === 'accepted'
- ? cssVar.colorSuccess
- : focusedStates.review === 'needsFix'
- ? cssVar.colorError
- : focusedStates.review === 'ignored'
- ? cssVar.colorTextQuaternary
- : cssVar.colorTextTertiary,
- fontSize: 12,
- }}
- >
- <Icon
- size={14}
- icon={
- focusedStates.review === 'accepted'
- ? BadgeCheck
- : focusedStates.review === 'needsFix'
- ? RotateCcw
- : focusedStates.review === 'ignored'
- ? Ban
- : CircleDashed
- }
- />
- {t(`acceptance.focus.state.${focusedStates.review}`)}
- <Text style={{ color: cssVar.colorTextQuaternary }}>Β·</Text>
- <Flexbox
- horizontal
- align={'center'}
- gap={5}
- style={{
- color:
- focusedStates.verifier === 'passed'
- ? cssVar.colorSuccess
- : focusedStates.verifier === 'failed'
- ? cssVar.colorError
- : focusedStates.verifier === 'uncertain'
- ? cssVar.colorWarning
- : cssVar.colorTextQuaternary,
- }}
- >
- <Icon
- size={14}
- icon={
- focusedStates.verifier === 'passed'
- ? Check
- : focusedStates.verifier === 'failed'
- ? XCircle
- : focusedStates.verifier === 'uncertain'
- ? HelpCircle
- : CircleDashed
- }
- />
- {t('acceptance.focus.judgeLabel')} Β·{' '}
- {t(`report.verdict.${focusedStates.verifierLabel}`)}
- </Flexbox>
- </Flexbox>
- <Flexbox horizontal align={'baseline'} gap={8}>
- <Text
- style={{
- color: cssVar.colorTextTertiary,
- flex: 'none',
- fontFamily: cssVar.fontFamilyCode,
- fontSize: 12,
- }}
- >
- C{focusedCheck.seq}
- </Text>
- <Text as={'h2'} style={{ fontSize: md ? 22 : 18, margin: 0 }}>
- {focusedCheck.title}
- </Text>
- </Flexbox>
- <Text fontSize={13} style={!md ? { display: 'none' } : undefined} type={'secondary'}>
- {t(`acceptance.focus.verifierDescription.${focusedStates.verifierLabel}`)}
- </Text>
- </Flexbox>
+ <FocusCheckHeading
+ check={focusedCheck}
+ showVerdictDescription={md}
+ titleSize={md ? 22 : 18}
+ />
<FocusedCheckDetails
canReview={canReview}
check={focusedCheck}
diff --git a/src/features/Acceptance/Viewer/Focus/FocusCheckHeading.tsx b/src/features/Acceptance/Viewer/Focus/FocusCheckHeading.tsx
new file mode 100644
index 00000000000..4db7e17604e
--- /dev/null
+++ b/src/features/Acceptance/Viewer/Focus/FocusCheckHeading.tsx
@@ -0,0 +1,103 @@
+'use client';
+
+import { Flexbox, Icon } from '@lobehub/ui';
+import { Text } from '@lobehub/ui/base-ui';
+import { cssVar } from 'antd-style';
+import { BadgeCheck, Ban, Check, CircleDashed, HelpCircle, RotateCcw, XCircle } from 'lucide-react';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { focusedCheckStates } from '../Checks/checkState';
+import type { AcceptanceCheck } from '../Checks/types';
+import { acceptanceFocusedLayout } from '../layout';
+
+const REVIEW_ICON = {
+ accepted: BadgeCheck,
+ ignored: Ban,
+ needsFix: RotateCcw,
+ pending: CircleDashed,
+} as const;
+
+const REVIEW_COLOR = {
+ accepted: cssVar.colorSuccess,
+ ignored: cssVar.colorTextQuaternary,
+ needsFix: cssVar.colorError,
+ pending: cssVar.colorTextTertiary,
+} as const;
+
+const VERDICT_ICON = {
+ failed: XCircle,
+ notExecuted: CircleDashed,
+ passed: Check,
+ uncertain: HelpCircle,
+} as const;
+
+const VERDICT_COLOR = {
+ failed: cssVar.colorError,
+ notExecuted: cssVar.colorTextQuaternary,
+ passed: cssVar.colorSuccess,
+ uncertain: cssVar.colorWarning,
+} as const;
+
+interface FocusCheckHeadingProps {
+ check: AcceptanceCheck;
+ /** The one-line explanation of the agent's verdict; desktop only. */
+ showVerdictDescription?: boolean;
+ titleSize?: number;
+}
+
+/**
+ * Who has ruled on this check, and what it claims.
+ *
+ * The two verdicts lead deliberately: the reviewer's own standing decision
+ * first, then the agent's, so the question the page asks ("do you agree?") is
+ * legible before the title explains what is being agreed with.
+ */
+export const FocusCheckHeading = memo<FocusCheckHeadingProps>(
+ ({ check, showVerdictDescription, titleSize = 22 }) => {
+ const { t } = useTranslation('verify');
+ const states = focusedCheckStates(check);
+ const verdict = states.verifierLabel as keyof typeof VERDICT_ICON;
+
+ return (
+ <Flexbox gap={acceptanceFocusedLayout.headerGap}>
+ <Flexbox
+ horizontal
+ align={'center'}
+ gap={5}
+ style={{ color: REVIEW_COLOR[states.review], fontSize: 12 }}
+ >
+ <Icon icon={REVIEW_ICON[states.review]} size={14} />
+ {t(`acceptance.focus.state.${states.review}`)}
+ <Text style={{ color: cssVar.colorTextQuaternary }}>Β·</Text>
+ <Flexbox horizontal align={'center'} gap={5} style={{ color: VERDICT_COLOR[verdict] }}>
+ <Icon icon={VERDICT_ICON[verdict]} size={14} />
+ {t('acceptance.focus.judgeLabel')} Β· {t(`report.verdict.${verdict}`)}
+ </Flexbox>
+ </Flexbox>
+ <Flexbox horizontal align={'baseline'} gap={8}>
+ <Text
+ style={{
+ color: cssVar.colorTextTertiary,
+ flex: 'none',
+ fontFamily: cssVar.fontFamilyCode,
+ fontSize: 12,
+ }}
+ >
+ C{check.seq}
+ </Text>
+ <Text as={'h2'} style={{ fontSize: titleSize, margin: 0 }}>
+ {check.title}
+ </Text>
+ </Flexbox>
+ {showVerdictDescription && (
+ <Text fontSize={13} type={'secondary'}>
+ {t(`acceptance.focus.verifierDescription.${verdict}`)}
+ </Text>
+ )}
+ </Flexbox>
+ );
+ },
+);
+
+FocusCheckHeading.displayName = 'AcceptanceFocusCheckHeading';
diff --git a/src/features/Acceptance/Viewer/Focus/FocusOutline.tsx b/src/features/Acceptance/Viewer/Focus/FocusOutline.tsx
new file mode 100644
index 00000000000..a2e243c0783
--- /dev/null
+++ b/src/features/Acceptance/Viewer/Focus/FocusOutline.tsx
@@ -0,0 +1,126 @@
+'use client';
+
+import type { AcceptanceChecklistItem } from '@lobechat/types';
+import { Flexbox, Icon } from '@lobehub/ui';
+import { Tag, Text } from '@lobehub/ui/base-ui';
+import { cssVar } from 'antd-style';
+import { BadgeCheck, Ban, ChevronRight, CircleDashed, PencilLine, RotateCcw } from 'lucide-react';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import NavItem from '@/features/NavPanel/components/NavItem';
+
+import { checkFilterState } from '../Checks/checkState';
+import type { AcceptanceCheck } from '../Checks/types';
+import { acceptanceFocusedLayout } from '../layout';
+
+const STATE_ICON = {
+ accepted: BadgeCheck,
+ ignored: Ban,
+ needsFix: RotateCcw,
+ pending: CircleDashed,
+} as const;
+
+const STATE_TAG_COLOR = {
+ accepted: 'success',
+ ignored: 'default',
+ needsFix: 'error',
+ pending: 'default',
+} as const;
+
+interface FocusOutlineProps {
+ checks: AcceptanceCheck[];
+ focusedCheckId: string;
+ /** Authoring is creator-only; without it the standing group stays hidden. */
+ onEditStandingCheck?: (item: AcceptanceChecklistItem) => void;
+ onSelectCheck: (id: string) => void;
+ /** Checklist items that no round has executed yet. */
+ standingChecks?: AcceptanceChecklistItem[];
+}
+
+/**
+ * The list of checks beside (desktop) or above (phone) the one being read.
+ *
+ * Each row carries its own verdict and evidence count, because the reviewer
+ * picks the next check by how much judging it still needs, not by its title.
+ */
+export const FocusOutline = memo<FocusOutlineProps>(
+ ({ checks, focusedCheckId, onEditStandingCheck, onSelectCheck, standingChecks = [] }) => {
+ const { t } = useTranslation('verify');
+
+ return (
+ <>
+ {checks.map((check) => {
+ const state = checkFilterState(check);
+
+ return (
+ <NavItem
+ active={check.id === focusedCheckId}
+ extra={<Icon color={cssVar.colorTextQuaternary} icon={ChevronRight} size={14} />}
+ key={check.id}
+ paddingBlock={acceptanceFocusedLayout.outlineItemPaddingBlock}
+ paddingInline={acceptanceFocusedLayout.outlineItemPaddingInline}
+ title={check.title}
+ titleColor={cssVar.colorText}
+ description={
+ <Flexbox horizontal align={'center'} gap={8}>
+ <Tag
+ color={STATE_TAG_COLOR[state]}
+ icon={<Icon icon={STATE_ICON[state]} />}
+ size={'small'}
+ >
+ {t(`acceptance.focus.state.${state}`)}
+ </Tag>
+ <Text fontSize={12} type={'secondary'}>
+ {t('acceptance.focus.evidenceCount', { count: check.evidence.length })}
+ </Text>
+ </Flexbox>
+ }
+ slots={{
+ titlePrefix: (
+ <Flexbox align={'center'} height={22} style={{ alignSelf: 'flex-start' }}>
+ <Text
+ style={{
+ color: cssVar.colorTextQuaternary,
+ fontFamily: cssVar.fontFamilyCode,
+ fontSize: 11,
+ }}
+ >
+ C{check.seq}
+ </Text>
+ </Flexbox>
+ ),
+ }}
+ onClick={() => onSelectCheck(check.id)}
+ />
+ );
+ })}
+ {standingChecks.length > 0 && onEditStandingCheck && (
+ <Flexbox gap={4} paddingBlock={8} paddingInline={8}>
+ <Text fontSize={11} type={'secondary'}>
+ {t('acceptance.checkCreate.pendingGroup')}
+ </Text>
+ {standingChecks.map((item) => (
+ <NavItem
+ extra={<Icon color={cssVar.colorTextQuaternary} icon={PencilLine} />}
+ key={item.id}
+ paddingBlock={acceptanceFocusedLayout.outlineItemPaddingBlock}
+ paddingInline={acceptanceFocusedLayout.outlineItemPaddingInline}
+ title={item.name}
+ titleColor={cssVar.colorText}
+ description={
+ <Text fontSize={12} type={'secondary'}>
+ {item.method || t('acceptance.checkCreate.pendingDescription')}
+ </Text>
+ }
+ onClick={() => onEditStandingCheck(item)}
+ />
+ ))}
+ </Flexbox>
+ )}
+ </>
+ );
+ },
+);
+
+FocusOutline.displayName = 'AcceptanceFocusOutline';
diff --git a/src/features/Acceptance/Viewer/Review/CheckRejectModal.tsx b/src/features/Acceptance/Viewer/Review/CheckRejectModal.tsx
index 6bb7e2be633..4ecaabd8680 100644
--- a/src/features/Acceptance/Viewer/Review/CheckRejectModal.tsx
+++ b/src/features/Acceptance/Viewer/Review/CheckRejectModal.tsx
@@ -1,776 +1,39 @@
'use client';
-import type { AcceptanceReviewAnnotation } from '@lobechat/types';
-import { Flexbox, Icon, TextArea } from '@lobehub/ui';
-import { ActionIcon, Button, createModal, Text, useModalContext } from '@lobehub/ui/base-ui';
-import { createStaticStyles, cssVar, cx, useResponsive } from 'antd-style';
-import { Crosshair, Trash2, ZoomIn, ZoomOut } from 'lucide-react';
-import { memo, useEffect, useRef, useState } from 'react';
-import { useTranslation } from 'react-i18next';
+import { Flexbox } from '@lobehub/ui';
+import { createModal, Text } from '@lobehub/ui/base-ui';
+import { useResponsive } from 'antd-style';
+import { memo } from 'react';
-import { AnnotationCanvas } from '../Evidence/Annotation';
-import type { PendingAttachment } from '../Evidence/attachments';
-import {
- AttachmentStrip,
- AttachmentUploadButton,
- useFeedbackAttachments,
-} from '../Evidence/attachments';
+import { DesktopEvidenceReview } from '../Evidence/DesktopEvidenceReview';
import { MobileEvidenceReview } from '../Evidence/MobileEvidenceReview';
-import type { MobileReviewEvent, MobileReviewStep } from '../Evidence/mobileReviewFlow';
-import { nextMobileReviewStep } from '../Evidence/mobileReviewFlow';
-import { useMeasuredWidth } from '../Evidence/useMeasuredWidth';
-import { frostedModalStyles } from './modals';
-import { useReviewSubmit } from './useReviewSubmit';
+import { checkRejectModalShell, rejectModalTitle } from './rejectModalShell';
+import type { RejectReviewInput } from './useRejectReview';
+import { useRejectReview } from './useRejectReview';
-export const CHECK_REJECT_MODAL_SIZE = { height: '98dvh', width: '98vw' } as const;
-export const TEXT_REJECT_MODAL_WIDTH = 'min(560px, calc(100vw - 32px))';
+export type { RejectableEvidence } from './rejectDraft';
-const styles = createStaticStyles(({ css }) => ({
- mobilePopup: css`
- @media (width <= 767px) {
- max-width: 100vw !important;
-
- > div {
- width: 100vw;
- max-width: 100vw;
- height: 100dvh;
- max-height: 100dvh;
- padding: 0;
- border-radius: 0;
- }
- }
- `,
- mobileClose: css`
- @media (width <= 767px) {
- inset-block-start: max(4px, env(safe-area-inset-top));
- inset-inline-end: 4px;
- width: 44px;
- height: 44px;
- }
- `,
- mobileHeader: css`
- @media (width <= 767px) {
- min-height: 56px;
- padding-block: max(12px, env(safe-area-inset-top)) 12px;
- padding-inline: 12px 52px;
- }
- `,
- mobileContent: css`
- @media (width <= 767px) {
- padding-block: 0 max(12px, env(safe-area-inset-bottom));
- padding-inline: 12px;
- }
- `,
- modalPopup: css`
- > div {
- display: flex;
- flex-direction: column;
- }
- `,
- modalPopupMedia: css`
- > div {
- width: ${CHECK_REJECT_MODAL_SIZE.width};
- max-width: ${CHECK_REJECT_MODAL_SIZE.width};
- height: ${CHECK_REJECT_MODAL_SIZE.height};
-
- @media (width <= 767px) {
- width: 100vw;
- max-width: 100vw;
- height: 100dvh;
- max-height: 100dvh;
- padding: 0;
- border-radius: 0;
- }
- }
- `,
- fullscreenBody: css`
- display: flex;
- flex: 1;
- gap: 16px;
- min-height: 0;
-
- @media (width <= 767px) {
- flex-direction: column;
- gap: 12px;
- }
- `,
- modalBody: css`
- overflow: hidden;
- display: flex;
- flex: 1;
- flex-direction: column;
-
- min-height: 0;
- `,
- modalFooter: css`
- flex: none;
- padding-block-start: 12px;
- border-block-start: 1px solid ${cssVar.colorBorderSecondary};
- `,
- /** The region caption on a phone: a link, not a button-shaped box. The tap
- target comes from padding around a compact line, so a list of regions
- does not turn into a column of 44px slabs. */
- regionJump: css`
- cursor: pointer;
-
- display: inline-flex;
- gap: 5px;
- align-items: center;
- align-self: flex-start;
-
- padding-block: 7px;
- padding-inline: 2px;
- border: none;
-
- font-size: 13px;
- color: ${cssVar.colorLink};
-
- background: none;
-
- &:active {
- opacity: 0.6;
- }
- `,
- regionIndex: css`
- flex: none;
-
- width: 18px;
- height: 18px;
- border-radius: 50%;
-
- font-size: 11px;
- font-weight: 600;
- line-height: 18px;
- color: #fff;
- text-align: center;
-
- background: ${cssVar.colorError};
- `,
- sidePanel: css`
- overflow-y: auto;
- display: flex;
- flex: none;
- flex-direction: column;
- gap: 12px;
-
- width: 320px;
- min-width: 0;
-
- @media (width <= 767px) {
- flex: 0 1 auto;
- width: 100%;
- max-height: none;
- }
- `,
- thumb: css`
- cursor: pointer;
-
- overflow: hidden;
-
- width: 72px;
- height: 48px;
- border: 2px solid transparent;
- border-radius: ${cssVar.borderRadius};
-
- img {
- display: block;
- width: 100%;
- height: 100%;
- object-fit: cover;
- }
- `,
- thumbActive: css`
- border-color: ${cssVar.colorPrimary};
- `,
- /** The fullscreen zoom stage β€” its native scrolling doubles as panning.
- Flex + the inner frame's `margin: auto` keeps the image centered when it
- fits the stage, and scrolls from the edges once it grows past it. */
- viewport: css`
- overflow: auto;
- overscroll-behavior: contain;
- display: flex;
- flex: 1;
-
- min-width: 0;
- min-height: 120px;
- border: 1px solid ${cssVar.colorBorderSecondary};
- border-radius: ${cssVar.borderRadiusLG};
-
- background: ${cssVar.colorFillQuaternary};
- `,
- /** The centered image frame inside the stage β€” `margin: auto` absorbs the
- free space on both axes (centering) and collapses to 0 on overflow. */
- viewportInner: css`
- margin: auto;
- `,
- /** The zoom pill floats bottom-center over the stage β€” controls live with
- the thing they control, not in a detached toolbar row. */
- zoomBar: css`
- position: absolute;
- z-index: 5;
- inset-block-end: 16px;
- inset-inline-start: 50%;
- transform: translateX(-50%);
-
- display: flex;
- gap: 4px;
- align-items: center;
-
- padding-block: 4px;
- padding-inline: 8px;
- border: 1px solid ${cssVar.colorBorderSecondary};
- border-radius: 99px;
-
- background: ${cssVar.colorBgElevated};
- box-shadow: ${cssVar.boxShadowSecondary};
-
- @media (width <= 767px) {
- position: static;
- transform: none;
- align-self: center;
- }
- `,
- zoomLabel: css`
- min-width: 44px;
-
- font-size: 12px;
- font-variant-numeric: tabular-nums;
- color: ${cssVar.colorTextSecondary};
- text-align: center;
- `,
-}));
-
-/** One annotatable evidence image (already filtered to visual, file-backed). */
-export interface RejectableEvidence {
- fileUrl: string;
- id: string;
-}
-
-interface DraftAnnotationEntry {
- comment: string;
- evidenceId: string;
- /** Stable identity β€” rapid move/resize updates must never key off object
- identity, which a stale render closure invalidates mid-gesture. */
- key: number;
- rect: AcceptanceReviewAnnotation['rect'];
-}
-
-let draftAnnotationSeq = 0;
-const nextAnnotationKey = () => ++draftAnnotationSeq;
-
-/** What survives a refresh β€” typed feedback is too costly to lose to one F5. */
-interface RejectDraft {
- annotations: DraftAnnotationEntry[];
- attachments?: PendingAttachment[];
- comment: string;
-}
-
-export const serializeReviewAnnotations = (
- annotations: DraftAnnotationEntry[],
-): AcceptanceReviewAnnotation[] =>
- annotations.map(({ comment, evidenceId, rect }) => ({
- comment: comment.trim() || undefined,
- evidenceId,
- rect,
- }));
-
-const draftStorageKey = (key: string) => `acceptance-reject-draft:${key}`;
-
-const readDraft = (key: string | undefined): RejectDraft | null => {
- if (!key) return null;
- try {
- const raw = localStorage.getItem(draftStorageKey(key));
- return raw ? (JSON.parse(raw) as RejectDraft) : null;
- } catch {
- return null;
- }
-};
-
-const ZOOM_STEPS = [0.5, 0.75, 1, 1.5, 2, 3, 4];
-
-export const checkRejectModalSize = (evidenceCount: number) =>
- evidenceCount > 0
- ? CHECK_REJECT_MODAL_SIZE
- : ({ height: 'auto', width: TEXT_REJECT_MODAL_WIDTH } as const);
-
-export const checkRejectModalShell = (evidenceCount: number) => {
- const modalSize = checkRejectModalSize(evidenceCount);
- return {
- classNames: {
- close: styles.mobileClose,
- content: styles.mobileContent,
- header: styles.mobileHeader,
- popup: cx(styles.modalPopup, styles.mobilePopup, evidenceCount > 0 && styles.modalPopupMedia),
- },
- styles: {
- ...frostedModalStyles,
- content: { display: 'flex', flex: 1, minHeight: 0, overflow: 'hidden' },
- },
- width: modalSize.width,
- };
-};
-
-export const rejectModalTitle = (title: string, description?: string) => ({
- description: description?.trim() || undefined,
- title,
-});
-
-export const canDismissRejectModal = (loading: boolean) => !loading;
-
-interface CheckRejectModalProps {
+interface CheckRejectModalProps extends RejectReviewInput {
checkDescription?: string;
checkTitle: string;
- /** Stable key (the check id) for the refresh-surviving draft cache. */
- draftKey?: string;
- evidence: RejectableEvidence[];
- /**
- * Regions to open with β€” set when confirming a model proposal, so the
- * reviewer edits the model's boxes instead of redrawing them. Any stored
- * draft is ignored in that case: the proposal is the newer starting point.
- */
- initialAnnotations?: AcceptanceReviewAnnotation[];
- /** Feedback already typed in the focused detail before opening annotation. */
- initialComment?: string;
- initialEvidenceId?: string;
- /** Perform the reject; resolve true to close, false to stay open. */
- onConfirm: (value: {
- annotations: AcceptanceReviewAnnotation[];
- comment: string;
- fileIds: string[];
- }) => Promise<boolean>;
- previousAnnotations?: AcceptanceReviewAnnotation[];
- previousAttachments?: PendingAttachment[];
- previousComment?: string;
}
-export const mergeRejectComments = (initialComment = '', storedComment = '') => {
- const initial = initialComment.trim();
- const stored = storedComment.trim();
- if (!initial) return stored;
- if (!stored || stored === initial) return initial;
- return `${initial}\n\n${stored}`;
-};
-
+/**
+ * The reject's state lives here; where it goes on screen does not.
+ *
+ * The phone and the desktop lay this out differently enough to be separate
+ * files, but they are the same review: one draft, one set of regions, one
+ * submit rule. This is the single place that picks between them.
+ */
export const CheckRejectModalContent = memo<CheckRejectModalProps>(
- ({
- checkTitle,
- draftKey,
- evidence,
- initialAnnotations,
- initialComment,
- initialEvidenceId,
- previousAnnotations,
- previousAttachments,
- previousComment,
- onConfirm,
- }) => {
- const { t: translate } = useTranslation('verify');
+ ({ checkDescription: _checkDescription, checkTitle, ...input }) => {
const { md = true } = useResponsive();
- // Marking or panning β€” the phone review has no second screen to be on,
- // so this is the only mode left. See mobileReviewFlow.
- const [step, setStep] = useState<MobileReviewStep>('browse');
- const advance = (event: MobileReviewEvent) =>
- setStep((current) => nextMobileReviewStep(current, event));
- const drawing = step === 'draw';
- const swipeStart = useRef<{ x: number; y: number } | null>(null);
- const { close, setCanDismissByClickOutside } = useModalContext();
- const [draft] = useState(() => readDraft(draftKey));
- const [comment, setComment] = useState(() =>
- // A proposal supersedes the stored draft rather than merging with it β€”
- // splicing the model's sentence into half-typed notes would produce
- // feedback neither party wrote.
- initialAnnotations?.length
- ? (initialComment ?? '')
- : mergeRejectComments(initialComment, draft?.comment ?? previousComment),
- );
- const { failed, loading, submit } = useReviewSubmit();
- const [activeEvidenceId, setActiveEvidenceId] = useState(initialEvidenceId ?? evidence[0]?.id);
- const [annotations, setAnnotations] = useState<DraftAnnotationEntry[]>(() => {
- const source = initialAnnotations?.length
- ? initialAnnotations
- : (draft?.annotations ?? previousAnnotations ?? []);
- return (
- source
- // Only restore regions whose evidence still exists β€” a new round may
- // have replaced the artifacts since the draft was written.
- .filter((entry) => evidence.some((item) => item.id === entry.evidenceId))
- .map((entry) => ({
- comment: entry.comment ?? '',
- evidenceId: entry.evidenceId,
- key: nextAnnotationKey(),
- rect: entry.rect,
- }))
- );
- });
-
- useEffect(() => {
- setCanDismissByClickOutside(canDismissRejectModal(loading));
- }, [loading, setCanDismissByClickOutside]);
-
- // Your own screenshots (paste or upload) β€” attached to the reject alongside
- // the note and any circled regions.
- const { attachments, fileIds, handlePaste, remove, uploadFiles, uploading } =
- useFeedbackAttachments(6, draft?.attachments ?? previousAttachments);
-
- const [zoom, setZoom] = useState(1);
- // The stage node is remounted by the responsive flip, so the measurement
- // follows the node rather than a ref captured once β€” see useMeasuredWidth.
- const {
- node: viewportNode,
- ref: viewportRef,
- width: viewportWidth,
- } = useMeasuredWidth<HTMLDivElement>();
-
- // Persist the draft as it is typed; an empty draft cleans the slot up.
- useEffect(() => {
- if (!draftKey) return;
- try {
- if (!comment && annotations.length === 0 && attachments.length === 0) {
- localStorage.removeItem(draftStorageKey(draftKey));
- } else {
- localStorage.setItem(
- draftStorageKey(draftKey),
- JSON.stringify({ annotations, attachments, comment } satisfies RejectDraft),
- );
- }
- } catch {
- /* quota/private mode β€” the draft is a convenience, never a blocker */
- }
- }, [annotations, attachments, comment, draftKey]);
-
- const activeIndex = evidence.findIndex((item) => item.id === activeEvidenceId);
- const selectEvidence = (index: number) => {
- if (!evidence[index]) return;
- setActiveEvidenceId(evidence[index].id);
- setZoom(1);
- viewportNode?.scrollTo(0, 0);
- };
- const activeEvidence = evidence.find((item) => item.id === activeEvidenceId);
- const activeAnnotations = annotations.filter((item) => item.evidenceId === activeEvidenceId);
-
- const stepZoom = (direction: 1 | -1) =>
- setZoom((current) => {
- const index = ZOOM_STEPS.findIndex((step) => Math.abs(step - current) < 0.001);
- const at = index === -1 ? 2 : index;
- return ZOOM_STEPS[Math.min(Math.max(at + direction, 0), ZOOM_STEPS.length - 1)];
- });
-
- // The reject IS its feedback β€” at least one note (global or per-region) or
- // an attached screenshot the next round can act on.
- const canSubmit =
- Boolean(comment.trim()) ||
- annotations.some((annotation) => annotation.comment.trim()) ||
- fileIds.length > 0;
+ const model = useRejectReview(input);
- const handleConfirm = async () => {
- const confirmed = await submit(() =>
- onConfirm({
- annotations: serializeReviewAnnotations(annotations),
- comment: comment.trim(),
- fileIds,
- }),
- );
- if (confirmed) {
- if (draftKey) localStorage.removeItem(draftStorageKey(draftKey));
- close();
- }
- };
-
- const hasEvidence = evidence.length > 0;
-
- const canvasHandlers = {
- onDraw: (rect: AcceptanceReviewAnnotation['rect']) => {
- setAnnotations((previous) => [
- ...previous,
- { comment: '', evidenceId: activeEvidence!.id, key: nextAnnotationKey(), rect },
- ]);
- advance('region-drawn');
- },
- onRemove: (index: number) => {
- const target = activeAnnotations[index];
- if (target)
- setAnnotations((previous) => previous.filter((item) => item.key !== target.key));
- },
- onUpdate: (index: number, rect: AcceptanceReviewAnnotation['rect']) => {
- const target = activeAnnotations[index];
- if (target)
- setAnnotations((previous) =>
- previous.map((item) => (item.key === target.key ? { ...item, rect } : item)),
- );
- },
- };
-
- const annotationInputs = (md ? activeAnnotations : annotations).map((annotation, index) => (
- <Flexbox gap={4} key={annotation.key}>
- {!md && (
- // A caption that jumps back to its box on the image. It reads as a
- // link β€” crosshair, link colour, hugging the note it labels β€” because
- // a full-height text Button looked like an inert boxed heading and
- // ate a 44px band per region.
- <button
- className={styles.regionJump}
- type={'button'}
- onClick={() => {
- selectEvidence(evidence.findIndex((item) => item.id === annotation.evidenceId));
- advance('edit-region');
- }}
- >
- <Icon icon={Crosshair} size={13} />
- {translate('acceptance.review.regionImage', {
- image: evidence.findIndex((item) => item.id === annotation.evidenceId) + 1,
- region:
- annotations
- .filter((item) => item.evidenceId === annotation.evidenceId)
- .findIndex((item) => item.key === annotation.key) + 1,
- })}
- </button>
- )}
- <Flexbox horizontal align={'flex-start'} gap={8}>
- <span
- className={styles.regionIndex}
- style={{ marginBlockStart: 6, display: md ? undefined : 'none' }}
- >
- {index + 1}
- </span>
- <TextArea
- aria-label={translate('acceptance.review.annotationPlaceholder', { index: index + 1 })}
- autoSize={{ maxRows: 5, minRows: 1 }}
- style={{ flex: 1, fontSize: md ? undefined : 16 }}
- value={annotation.comment}
- placeholder={translate(
- md
- ? 'acceptance.review.annotationPlaceholder'
- : 'acceptance.review.rejectPlaceholder',
- { index: index + 1 },
- )}
- onChange={(event) =>
- setAnnotations((previous) =>
- previous.map((item) =>
- item.key === annotation.key ? { ...item, comment: event.target.value } : item,
- ),
- )
- }
- />
- <ActionIcon
- aria-label={translate('acceptance.review.removeRegion', { index: index + 1 })}
- icon={Trash2}
- size={{ blockSize: 44, size: 18 }}
- onClick={() =>
- setAnnotations((previous) => previous.filter((item) => item.key !== annotation.key))
- }
- />
- </Flexbox>
- </Flexbox>
- ));
-
- const thumbnails = evidence.length > 1 && (
- <Flexbox horizontal gap={8} style={{ overflowX: 'auto', flex: 'none' }}>
- {evidence.map((item) => (
- <button
- aria-pressed={item.id === activeEvidenceId}
- className={cx(styles.thumb, item.id === activeEvidenceId && styles.thumbActive)}
- key={item.id}
- style={{ flexShrink: 0 }}
- type={'button'}
- aria-label={translate('acceptance.review.imageNumber', {
- current: evidence.indexOf(item) + 1,
- total: evidence.length,
- })}
- onClick={() => selectEvidence(evidence.indexOf(item))}
- >
- <img alt={''} src={item.fileUrl} />
- </button>
- ))}
- </Flexbox>
- );
-
- const footer = (
- <Flexbox gap={10} style={{ width: '100%' }}>
- <Text fontSize={12} type={'secondary'}>
- {hasEvidence
- ? translate('acceptance.review.supplement')
- : translate('acceptance.review.rejectDescription', { title: checkTitle })}
- </Text>
- <TextArea
- autoSize={{ maxRows: 5, minRows: 2 }}
- placeholder={translate('acceptance.review.rejectPlaceholder')}
- value={comment}
- onChange={(event) => setComment(event.target.value)}
- onPaste={handlePaste}
- />
- <Flexbox horizontal align={'flex-start'} gap={8}>
- <Flexbox horizontal flex={1} gap={8}>
- <AttachmentUploadButton disabled={loading} onFiles={uploadFiles} />
- <AttachmentStrip
- attachments={attachments}
- disabled={loading}
- uploading={uploading}
- onRemove={remove}
- />
- </Flexbox>
- <Button disabled={loading} style={{ minHeight: md ? undefined : 44 }} onClick={close}>
- {translate('acceptance.actions.cancel')}
- </Button>
- <Button
- disabled={!canSubmit || uploading}
- loading={loading}
- style={{ minHeight: md ? undefined : 44 }}
- type={'primary'}
- onClick={handleConfirm}
- >
- {translate('acceptance.review.confirmReject')}
- </Button>
- </Flexbox>
- </Flexbox>
- );
-
- const imageStage = activeEvidence && (
- <div
- className={styles.viewport}
- ref={viewportRef}
- style={{
- touchAction: !md && !drawing && zoom === 1 ? 'pan-y pinch-zoom' : undefined,
- }}
- onTouchEnd={(event) => {
- const start = swipeStart.current;
- swipeStart.current = null;
- const touch = event.changedTouches[0];
- if (!start || !touch) return;
- const dx = touch.clientX - start.x;
- const dy = touch.clientY - start.y;
- if (Math.abs(dx) > 60 && Math.abs(dx) > Math.abs(dy) * 1.5)
- selectEvidence(activeIndex + (dx < 0 ? 1 : -1));
- }}
- onTouchStart={(event) => {
- const touch = event.touches[0];
- swipeStart.current =
- !md && !drawing && zoom === 1 && event.touches.length === 1
- ? { x: touch.clientX, y: touch.clientY }
- : null;
- }}
- >
- <div className={styles.viewportInner}>
- <AnnotationCanvas
- annotations={activeAnnotations}
- drawing={md || drawing}
- imageWidth={viewportWidth ? Math.max(viewportWidth * zoom - 2, 0) : undefined}
- src={activeEvidence!.fileUrl}
- {...canvasHandlers}
- />
- </div>
- </div>
- );
-
- if (!md)
- return (
- <MobileEvidenceReview
- annotationCount={activeAnnotations.length}
- canSubmit={canSubmit && !uploading}
- drawing={drawing}
- failed={failed}
- image={imageStage}
- imageCount={evidence.length}
- imageIndex={activeIndex}
- loading={loading}
- zoom={zoom}
- editor={
- <Flexbox gap={16}>
- {annotations.length > 0 && (
- <>
- <Text strong>{translate('acceptance.review.regionComments')}</Text>
- {annotationInputs}
- </>
- )}
- <Text strong>{translate('acceptance.review.supplement')}</Text>
- <TextArea
- aria-label={translate('acceptance.review.supplement')}
- autoSize={{ minRows: 4, maxRows: 10 }}
- placeholder={translate('acceptance.review.rejectPlaceholder')}
- style={{ fontSize: 16 }}
- value={comment}
- onChange={(event) => setComment(event.target.value)}
- onPaste={handlePaste}
- />
- <AttachmentUploadButton disabled={loading} onFiles={uploadFiles} />
- <AttachmentStrip
- attachments={attachments}
- disabled={loading}
- uploading={uploading}
- onRemove={remove}
- />
- <Text fontSize={12} type={'secondary'}>
- {translate('acceptance.review.draftSaved')}
- </Text>
- </Flexbox>
- }
- onConfirm={handleConfirm}
- onImageChange={selectEvidence}
- onStep={advance}
- onZoom={stepZoom}
- />
- );
-
- return (
- <div className={styles.modalBody}>
- {activeEvidence && (
- <Flexbox flex={1} gap={12} style={{ minHeight: 0 }}>
- <Flexbox gap={12} height={'100%'} style={{ minHeight: 0 }}>
- {md && thumbnails}
- <div className={styles.fullscreenBody} style={{ position: 'relative' }}>
- {imageStage}
- <div className={styles.zoomBar}>
- <ActionIcon
- disabled={zoom <= ZOOM_STEPS[0]}
- icon={ZoomOut}
- size={md ? 'small' : { blockSize: 44, size: 20 }}
- title={translate('acceptance.review.zoomOut')}
- onClick={() => stepZoom(-1)}
- />
- <span className={styles.zoomLabel}>{Math.round(zoom * 100)}%</span>
- <ActionIcon
- disabled={zoom >= ZOOM_STEPS.at(-1)!}
- icon={ZoomIn}
- size={md ? 'small' : { blockSize: 44, size: 20 }}
- title={translate('acceptance.review.zoomIn')}
- onClick={() => stepZoom(1)}
- />
- </div>
- <div
- className={styles.sidePanel}
- style={
- !md && !drawing && activeAnnotations.length === 0
- ? { display: 'none' }
- : undefined
- }
- >
- <Flexbox gap={2}>
- <Text strong fontSize={13}>
- {translate('acceptance.review.regionComments')}
- </Text>
- <Text fontSize={12} type={'secondary'}>
- {translate('acceptance.review.annotateHint')}
- </Text>
- </Flexbox>
- {activeAnnotations.length === 0 && (
- <Text fontSize={12} type={'secondary'}>
- {translate('acceptance.review.regionCommentsEmpty')}
- </Text>
- )}
- {annotationInputs}
- </div>
- </div>
- </Flexbox>
- </Flexbox>
- )}
- <div className={styles.modalFooter}>
- {failed && (
- <Text role={'alert'} type={'danger'}>
- {translate('acceptance.review.submitFailed')}
- </Text>
- )}
- {footer}
- </div>
- </div>
+ return md ? (
+ <DesktopEvidenceReview checkTitle={checkTitle} model={model} />
+ ) : (
+ <MobileEvidenceReview model={model} />
);
},
);
diff --git a/src/features/Acceptance/Viewer/Review/rejectDraft.ts b/src/features/Acceptance/Viewer/Review/rejectDraft.ts
new file mode 100644
index 00000000000..25cec7949e2
--- /dev/null
+++ b/src/features/Acceptance/Viewer/Review/rejectDraft.ts
@@ -0,0 +1,112 @@
+import type { AcceptanceReviewAnnotation } from '@lobechat/types';
+
+import type { PendingAttachment } from '../Evidence/attachments';
+
+/** One annotatable evidence image (already filtered to visual, file-backed). */
+export interface RejectableEvidence {
+ fileUrl: string;
+ id: string;
+}
+
+export interface DraftAnnotationEntry {
+ comment: string;
+ evidenceId: string;
+ /** Stable identity β€” rapid move/resize updates must never key off object
+ identity, which a stale render closure invalidates mid-gesture. */
+ key: number;
+ rect: AcceptanceReviewAnnotation['rect'];
+}
+
+/** What survives a refresh β€” typed feedback is too costly to lose to one F5. */
+export interface RejectDraft {
+ annotations: DraftAnnotationEntry[];
+ attachments?: PendingAttachment[];
+ comment: string;
+}
+
+let draftAnnotationSeq = 0;
+
+export const nextAnnotationKey = () => ++draftAnnotationSeq;
+
+export const serializeReviewAnnotations = (
+ annotations: DraftAnnotationEntry[],
+): AcceptanceReviewAnnotation[] =>
+ annotations.map(({ comment, evidenceId, rect }) => ({
+ comment: comment.trim() || undefined,
+ evidenceId,
+ rect,
+ }));
+
+/**
+ * Regions to open the modal with, keyed for editing.
+ *
+ * Only regions whose evidence still exists are restored β€” a new round may have
+ * replaced the artifacts since the draft was written, and a rect normalized
+ * against an image that is gone would land on whatever took its place.
+ */
+export const restoreDraftAnnotations = (
+ source: AcceptanceReviewAnnotation[],
+ evidence: RejectableEvidence[],
+): DraftAnnotationEntry[] =>
+ source
+ .filter((entry) => evidence.some((item) => item.id === entry.evidenceId))
+ .map((entry) => ({
+ comment: entry.comment ?? '',
+ evidenceId: entry.evidenceId,
+ key: nextAnnotationKey(),
+ rect: entry.rect,
+ }));
+
+const draftStorageKey = (key: string) => `acceptance-reject-draft:${key}`;
+
+export const readDraft = (key: string | undefined): RejectDraft | null => {
+ if (!key) return null;
+ try {
+ const raw = localStorage.getItem(draftStorageKey(key));
+ return raw ? (JSON.parse(raw) as RejectDraft) : null;
+ } catch {
+ return null;
+ }
+};
+
+/** An empty draft cleans its slot up rather than persisting a blank record. */
+export const writeDraft = (key: string, draft: RejectDraft) => {
+ try {
+ if (
+ !draft.comment &&
+ draft.annotations.length === 0 &&
+ (draft.attachments?.length ?? 0) === 0
+ ) {
+ localStorage.removeItem(draftStorageKey(key));
+ } else {
+ localStorage.setItem(draftStorageKey(key), JSON.stringify(draft));
+ }
+ } catch {
+ /* quota/private mode β€” the draft is a convenience, never a blocker */
+ }
+};
+
+export const clearDraft = (key: string) => {
+ try {
+ localStorage.removeItem(draftStorageKey(key));
+ } catch {
+ /* see writeDraft */
+ }
+};
+
+export const mergeRejectComments = (initialComment = '', storedComment = '') => {
+ const initial = initialComment.trim();
+ const stored = storedComment.trim();
+ if (!initial) return stored;
+ if (!stored || stored === initial) return initial;
+ return `${initial}\n\n${stored}`;
+};
+
+export const ZOOM_STEPS = [0.5, 0.75, 1, 1.5, 2, 3, 4];
+
+/** Step one notch along ZOOM_STEPS, clamped at both ends. */
+export const nextZoom = (current: number, direction: 1 | -1) => {
+ const index = ZOOM_STEPS.findIndex((step) => Math.abs(step - current) < 0.001);
+ const at = index === -1 ? 2 : index;
+ return ZOOM_STEPS[Math.min(Math.max(at + direction, 0), ZOOM_STEPS.length - 1)];
+};
diff --git a/src/features/Acceptance/Viewer/Review/rejectModalShell.ts b/src/features/Acceptance/Viewer/Review/rejectModalShell.ts
new file mode 100644
index 00000000000..d54a8643c45
--- /dev/null
+++ b/src/features/Acceptance/Viewer/Review/rejectModalShell.ts
@@ -0,0 +1,102 @@
+import { createStaticStyles, cx } from 'antd-style';
+
+import { frostedModalStyles } from './modals';
+
+export const CHECK_REJECT_MODAL_SIZE = { height: '98dvh', width: '98vw' } as const;
+export const TEXT_REJECT_MODAL_WIDTH = 'min(560px, calc(100vw - 32px))';
+
+/**
+ * The modal chrome, not its contents. These classes ride on the popup element
+ * that `createModal` owns, so they stay media-query driven: the shell has to
+ * answer for both breakpoints in one node, unlike the body, which mounts one
+ * presentation or the other.
+ */
+const styles = createStaticStyles(({ css }) => ({
+ mobileClose: css`
+ @media (width <= 767px) {
+ inset-block-start: max(4px, env(safe-area-inset-top));
+ inset-inline-end: 4px;
+ width: 44px;
+ height: 44px;
+ }
+ `,
+ mobileContent: css`
+ @media (width <= 767px) {
+ padding-block: 0 max(12px, env(safe-area-inset-bottom));
+ padding-inline: 12px;
+ }
+ `,
+ mobileHeader: css`
+ @media (width <= 767px) {
+ min-height: 56px;
+ padding-block: max(12px, env(safe-area-inset-top)) 12px;
+ padding-inline: 12px 52px;
+ }
+ `,
+ mobilePopup: css`
+ @media (width <= 767px) {
+ max-width: 100vw !important;
+
+ > div {
+ width: 100vw;
+ max-width: 100vw;
+ height: 100dvh;
+ max-height: 100dvh;
+ padding: 0;
+ border-radius: 0;
+ }
+ }
+ `,
+ modalPopup: css`
+ > div {
+ display: flex;
+ flex-direction: column;
+ }
+ `,
+ modalPopupMedia: css`
+ > div {
+ width: ${CHECK_REJECT_MODAL_SIZE.width};
+ max-width: ${CHECK_REJECT_MODAL_SIZE.width};
+ height: ${CHECK_REJECT_MODAL_SIZE.height};
+
+ @media (width <= 767px) {
+ width: 100vw;
+ max-width: 100vw;
+ height: 100dvh;
+ max-height: 100dvh;
+ padding: 0;
+ border-radius: 0;
+ }
+ }
+ `,
+}));
+
+/** Evidence earns a near-fullscreen stage; a text-only reject stays a dialog. */
+export const checkRejectModalSize = (evidenceCount: number) =>
+ evidenceCount > 0
+ ? CHECK_REJECT_MODAL_SIZE
+ : ({ height: 'auto', width: TEXT_REJECT_MODAL_WIDTH } as const);
+
+export const checkRejectModalShell = (evidenceCount: number) => {
+ const modalSize = checkRejectModalSize(evidenceCount);
+ return {
+ classNames: {
+ close: styles.mobileClose,
+ content: styles.mobileContent,
+ header: styles.mobileHeader,
+ popup: cx(styles.modalPopup, styles.mobilePopup, evidenceCount > 0 && styles.modalPopupMedia),
+ },
+ styles: {
+ ...frostedModalStyles,
+ content: { display: 'flex', flex: 1, minHeight: 0, overflow: 'hidden' },
+ },
+ width: modalSize.width,
+ };
+};
+
+export const rejectModalTitle = (title: string, description?: string) => ({
+ description: description?.trim() || undefined,
+ title,
+});
+
+export const canDismissRejectModal = (loading: boolean) => !loading;
diff --git a/src/features/Acceptance/Viewer/Review/useRejectReview.ts b/src/features/Acceptance/Viewer/Review/useRejectReview.ts
new file mode 100644
index 00000000000..e10552cca4e
--- /dev/null
+++ b/src/features/Acceptance/Viewer/Review/useRejectReview.ts
@@ -0,0 +1,201 @@
+'use client';
+
+import type { AcceptanceReviewAnnotation } from '@lobechat/types';
+import { useModalContext } from '@lobehub/ui/base-ui';
+import { useEffect, useState } from 'react';
+
+import type { PendingAttachment } from '../Evidence/attachments';
+import { useFeedbackAttachments } from '../Evidence/attachments';
+import type { MobileReviewEvent, MobileReviewStep } from '../Evidence/mobileReviewFlow';
+import { nextMobileReviewStep } from '../Evidence/mobileReviewFlow';
+import type { DraftAnnotationEntry, RejectableEvidence } from './rejectDraft';
+import {
+ clearDraft,
+ mergeRejectComments,
+ nextAnnotationKey,
+ nextZoom,
+ readDraft,
+ restoreDraftAnnotations,
+ serializeReviewAnnotations,
+ writeDraft,
+} from './rejectDraft';
+import { canDismissRejectModal } from './rejectModalShell';
+import { useReviewSubmit } from './useReviewSubmit';
+
+const MAX_ATTACHMENTS = 6;
+
+export interface RejectReviewInput {
+ /** Stable key (the check id) for the refresh-surviving draft cache. */
+ draftKey?: string;
+ evidence: RejectableEvidence[];
+ /**
+ * Regions to open with β€” set when confirming a model proposal, so the
+ * reviewer edits the model's boxes instead of redrawing them. Any stored
+ * draft is ignored in that case: the proposal is the newer starting point.
+ */
+ initialAnnotations?: AcceptanceReviewAnnotation[];
+ /** Feedback already typed in the focused detail before opening annotation. */
+ initialComment?: string;
+ initialEvidenceId?: string;
+ /** Perform the reject; resolve true to close, false to stay open. */
+ onConfirm: (value: {
+ annotations: AcceptanceReviewAnnotation[];
+ comment: string;
+ fileIds: string[];
+ }) => Promise<boolean>;
+ previousAnnotations?: AcceptanceReviewAnnotation[];
+ previousAttachments?: PendingAttachment[];
+ previousComment?: string;
+}
+
+/**
+ * Everything a reject is made of, independent of how it is laid out.
+ *
+ * The phone and the desktop draw this review very differently, but they must
+ * never disagree about what a submittable reject IS β€” so the draft, the
+ * regions, the attachments and the submit rule live here, once, and each
+ * presentation only decides where to put them.
+ */
+export const useRejectReview = ({
+ draftKey,
+ evidence,
+ initialAnnotations,
+ initialComment,
+ initialEvidenceId,
+ onConfirm,
+ previousAnnotations,
+ previousAttachments,
+ previousComment,
+}: RejectReviewInput) => {
+ const { close, setCanDismissByClickOutside } = useModalContext();
+ const [draft] = useState(() => readDraft(draftKey));
+ const { failed, loading, submit } = useReviewSubmit();
+
+ // Marking or panning β€” the phone review has no second screen to be on.
+ const [step, setStep] = useState<MobileReviewStep>('browse');
+ const advance = (event: MobileReviewEvent) =>
+ setStep((current) => nextMobileReviewStep(current, event));
+
+ const [comment, setComment] = useState(() =>
+ // A proposal supersedes the stored draft rather than merging with it β€”
+ // splicing the model's sentence into half-typed notes would produce
+ // feedback neither party wrote.
+ initialAnnotations?.length
+ ? (initialComment ?? '')
+ : mergeRejectComments(initialComment, draft?.comment ?? previousComment),
+ );
+ const [activeEvidenceId, setActiveEvidenceId] = useState(initialEvidenceId ?? evidence[0]?.id);
+ const [annotations, setAnnotations] = useState<DraftAnnotationEntry[]>(() =>
+ restoreDraftAnnotations(
+ initialAnnotations?.length
+ ? initialAnnotations
+ : (draft?.annotations ?? previousAnnotations ?? []),
+ evidence,
+ ),
+ );
+ const [zoom, setZoom] = useState(1);
+
+ // Your own screenshots (paste or upload) β€” attached to the reject alongside
+ // the note and any circled regions.
+ const { attachments, fileIds, handlePaste, remove, uploadFiles, uploading } =
+ useFeedbackAttachments(MAX_ATTACHMENTS, draft?.attachments ?? previousAttachments);
+
+ useEffect(() => {
+ setCanDismissByClickOutside(canDismissRejectModal(loading));
+ }, [loading, setCanDismissByClickOutside]);
+
+ useEffect(() => {
+ if (draftKey) writeDraft(draftKey, { annotations, attachments, comment });
+ }, [annotations, attachments, comment, draftKey]);
+
+ const activeIndex = evidence.findIndex((item) => item.id === activeEvidenceId);
+ const activeEvidence = evidence.find((item) => item.id === activeEvidenceId);
+ const activeAnnotations = annotations.filter((item) => item.evidenceId === activeEvidenceId);
+
+ const selectEvidence = (index: number) => {
+ if (!evidence[index]) return;
+ setActiveEvidenceId(evidence[index].id);
+ setZoom(1);
+ };
+
+ // The reject IS its feedback β€” at least one note (global or per-region) or
+ // an attached screenshot the next round can act on.
+ const canSubmit =
+ Boolean(comment.trim()) ||
+ annotations.some((annotation) => annotation.comment.trim()) ||
+ fileIds.length > 0;
+
+ return {
+ activeAnnotations,
+ activeEvidence,
+ activeIndex,
+ advance,
+ annotations,
+ attachments,
+ canSubmit: canSubmit && !uploading,
+ close,
+ comment,
+ drawing: step === 'draw',
+ evidence,
+ failed,
+ hasEvidence: evidence.length > 0,
+ loading,
+ uploading,
+ zoom,
+
+ canvas: {
+ onDraw: (rect: AcceptanceReviewAnnotation['rect']) => {
+ setAnnotations((previous) => [
+ ...previous,
+ { comment: '', evidenceId: activeEvidence!.id, key: nextAnnotationKey(), rect },
+ ]);
+ advance('region-drawn');
+ },
+ /** The canvas indexes within the ACTIVE image; the store keys by region. */
+ onRemove: (index: number) => {
+ const target = activeAnnotations[index];
+ if (target)
+ setAnnotations((previous) => previous.filter((item) => item.key !== target.key));
+ },
+ onUpdate: (index: number, rect: AcceptanceReviewAnnotation['rect']) => {
+ const target = activeAnnotations[index];
+ if (target)
+ setAnnotations((previous) =>
+ previous.map((item) => (item.key === target.key ? { ...item, rect } : item)),
+ );
+ },
+ },
+
+ editAnnotation: (key: number, value: string) =>
+ setAnnotations((previous) =>
+ previous.map((item) => (item.key === key ? { ...item, comment: value } : item)),
+ ),
+ handlePaste,
+ jumpToRegion: (evidenceId: string) => {
+ selectEvidence(evidence.findIndex((item) => item.id === evidenceId));
+ advance('edit-region');
+ },
+ removeAnnotation: (key: number) =>
+ setAnnotations((previous) => previous.filter((item) => item.key !== key)),
+ removeAttachment: remove,
+ selectEvidence,
+ setComment,
+ stepZoom: (direction: 1 | -1) => setZoom((current) => nextZoom(current, direction)),
+ submitReject: async () => {
+ const confirmed = await submit(() =>
+ onConfirm({
+ annotations: serializeReviewAnnotations(annotations),
+ comment: comment.trim(),
+ fileIds,
+ }),
+ );
+ if (confirmed) {
+ if (draftKey) clearDraft(draftKey);
+ close();
+ }
+ },
+ uploadFiles,
+ };
+};
+
+export type RejectReviewModel = ReturnType<typeof useRejectReview>;