1+ import type { ComponentChildren } from 'preact' ;
12import { useEffect , useRef , useState } from 'preact/hooks' ;
23import type { CreatedFeedResult } from '../api/contracts' ;
34import type { WorkflowState } from './AppPanels' ;
45import { DominantField } from './DominantField' ;
6+ import { ResultHero } from './ResultHero' ;
57
68interface ResultDisplayProperties {
79 result : CreatedFeedResult ;
@@ -10,14 +12,31 @@ interface ResultDisplayProperties {
1012 onRetryPreview : ( ) => void ;
1113}
1214
15+ interface PreviewSectionProperties {
16+ ariaLabel : string ;
17+ intro ?: string ;
18+ children : ComponentChildren ;
19+ }
20+
21+ function PreviewSection ( { ariaLabel, intro, children } : PreviewSectionProperties ) {
22+ return (
23+ < section class = "result-preview layout-rail-reading layout-stack" aria-label = { ariaLabel } >
24+ < div class = "result-preview__header layout-stack layout-stack--tight" >
25+ < p class = "result-preview__label ui-eyebrow" > Preview</ p >
26+ { intro && < p class = "result-preview__intro" > { intro } </ p > }
27+ </ div >
28+ { children }
29+ </ section >
30+ ) ;
31+ }
32+
1333export function ResultDisplay ( {
1434 result,
1535 workflowState,
1636 onCreateAnother,
1737 onRetryPreview,
1838} : ResultDisplayProperties ) {
1939 const [ copyNotice , setCopyNotice ] = useState ( '' ) ;
20- const [ showAllPreviewItems , setShowAllPreviewItems ] = useState ( false ) ;
2140 const copyResetReference = useRef < ReturnType < typeof globalThis . setTimeout > | undefined > ( undefined ) ;
2241 const { feed, preview, workflowState : previewWorkflowState , warnings } = result ;
2342
@@ -32,8 +51,6 @@ export function ResultDisplay({
3251 const canManuallyRetryPreview =
3352 previewWorkflowState === 'preview_failed' && warnings . some ( ( warning ) => warning . retryable ) ;
3453 const isPreviewCheckInProgress = preview . isLoading ;
35- const previewItems = showAllPreviewItems ? preview . items : preview . items . slice ( 0 , 3 ) ;
36- const hasMorePreviewItems = preview . items . length > 3 ;
3754 const statusTitle = {
3855 created : 'Feed created' ,
3956 preview_loading : 'Checking preview' ,
@@ -63,10 +80,6 @@ export function ResultDisplay({
6380 } ;
6481 } , [ ] ) ;
6582
66- useEffect ( ( ) => {
67- setShowAllPreviewItems ( false ) ;
68- } , [ feed . feed_token ] ) ;
69-
7083 const copyToClipboard = async ( text : string ) => {
7184 try {
7285 await navigator . clipboard . writeText ( text ) ;
@@ -80,25 +93,19 @@ export function ResultDisplay({
8093
8194 return (
8295 < section class = "result-shell layout-stack" aria-live = "polite" data-state = { workflowState } >
83- < header
84- class = "result-hero ui-card ui-card--roomy ui-hero layout-rail-reading layout-stack"
85- style = { { '--stack-gap' : 'var(--space-3)' } }
86- >
87- < div class = "result-hero__masthead ui-hero__masthead" >
88- < div class = "result-hero__icon-wrap ui-hero__icon-wrap" aria-hidden = "true" >
89- < img class = "result-hero__icon ui-hero__icon" src = "/feed.svg" alt = "" />
90- </ div >
91- < div class = "layout-stack layout-stack--tight" >
92- < h1 class = "result-title ui-display-title" > { statusTitle } </ h1 >
96+ < ResultHero
97+ title = { statusTitle }
98+ body = {
99+ < >
93100 < p class = "result-meta layout-rail-copy" > { feed . name } </ p >
94101 { statusMessage && < p class = "field-help" > { statusMessage } </ p > }
95102 { showResultStatusNote && (
96103 < p class = "result-status-note field-help field-help--warning" > { previewMessage } </ p >
97104 ) }
98- </ div >
99- </ div >
100- < div class = "result-hero__actions ui-hero__actions" >
101- { canManuallyRetryPreview && (
105+ </ >
106+ }
107+ actions = {
108+ canManuallyRetryPreview && (
102109 < button
103110 type = "button"
104111 class = "btn btn--primary"
@@ -108,9 +115,9 @@ export function ResultDisplay({
108115 >
109116 { isPreviewCheckInProgress ? 'Checking...' : 'Check preview again' }
110117 </ button >
111- ) }
112- </ div >
113- </ header >
118+ )
119+ }
120+ / >
114121
115122 < DominantField
116123 className = "layout-rail-reading"
@@ -146,22 +153,15 @@ export function ResultDisplay({
146153 </ div >
147154
148155 { preview . isLoading && (
149- < section class = "result-preview layout-rail-reading layout-stack" aria-label = "Feed preview status" >
150- < div class = "result-preview__header layout-stack layout-stack--tight" >
151- < p class = "result-preview__label ui-eyebrow" > Preview</ p >
152- </ div >
156+ < PreviewSection ariaLabel = "Feed preview status" >
153157 < p class = "field-help" > { previewMessage } </ p >
154- </ section >
158+ </ PreviewSection >
155159 ) }
156160
157161 { ! preview . isLoading && hasPreviewItems && (
158- < section class = "result-preview layout-rail-reading layout-stack" aria-label = "Feed preview" >
159- < div class = "result-preview__header layout-stack layout-stack--tight" >
160- < p class = "result-preview__label ui-eyebrow" > Preview</ p >
161- < p class = "result-preview__intro" > Latest items from this feed</ p >
162- </ div >
162+ < PreviewSection ariaLabel = "Feed preview" intro = "Latest items from this feed" >
163163 < ul class = "result-preview__list" role = "list" >
164- { previewItems . map ( ( item ) => (
164+ { preview . items . map ( ( item ) => (
165165 < li key = { `${ item . title } -${ item . publishedLabel || 'undated' } ` } >
166166 < article class = "preview-card ui-card layout-stack layout-stack--tight" >
167167 < h2 class = "preview-card__title" > { item . title } </ h2 >
@@ -178,31 +178,13 @@ export function ResultDisplay({
178178 </ li >
179179 ) ) }
180180 </ ul >
181- { hasMorePreviewItems && (
182- < button
183- type = "button"
184- class = "btn btn--quiet btn--linkish"
185- onClick = { ( ) => setShowAllPreviewItems ( ( current ) => ! current ) }
186- >
187- { showAllPreviewItems ? 'Show fewer items' : `Show all ${ preview . items . length } items` }
188- </ button >
189- ) }
190- </ section >
181+ </ PreviewSection >
191182 ) }
192183
193184 { showPreviewStatusOnly && (
194- < section class = "result-preview layout-rail-reading layout-stack" aria-label = "Feed preview status" >
195- < div class = "result-preview__header layout-stack layout-stack--tight" >
196- < p class = "result-preview__label ui-eyebrow" > Preview</ p >
197- </ div >
198- < p
199- class = {
200- previewWorkflowState === 'preview_failed' ? 'field-help field-help--warning' : 'field-help'
201- }
202- >
203- { previewMessage }
204- </ p >
205- </ section >
185+ < PreviewSection ariaLabel = "Feed preview status" >
186+ < p class = "field-help field-help--warning" > { previewMessage } </ p >
187+ </ PreviewSection >
206188 ) }
207189
208190 { copyNotice && (
0 commit comments