Skip to content

Commit 3cb9df7

Browse files
authored
Merge pull request #76 from filecoin-project/bp/publishing-badge
[UXIT-3480] Refactor upload progress logic and add “Publishing” badge state
2 parents 7cf4269 + 4d08f4d commit 3cb9df7

21 files changed

+366
-275
lines changed

src/components/layout/content.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { useState } from 'react'
22
import { Alert } from '@/components/ui/alert.tsx'
3-
import type { Progress } from '@/types/upload-progress.ts'
43
import { useUploadHistory } from '../../context/upload-history-context.tsx'
54
import { useFilecoinPinContext } from '../../hooks/use-filecoin-pin-context.ts'
65
import { useUploadExpansion } from '../../hooks/use-upload-expansion.ts'
76
import { useUploadOrchestration } from '../../hooks/use-upload-orchestration.ts'
87
import { useUploadUI } from '../../hooks/use-upload-ui.ts'
8+
import type { StepState } from '../../types/upload/step.ts'
99
import { formatFileSize } from '../../utils/format-file-size.ts'
1010
import { Heading } from '../ui/heading.tsx'
1111
import { LoadingState } from '../ui/loading-state.tsx'
@@ -15,7 +15,7 @@ import { UploadError } from '../upload/upload-error.tsx'
1515
import { UploadStatus } from '../upload/upload-status.tsx'
1616

1717
// Completed state for displaying upload history
18-
const COMPLETED_PROGRESS: Progress[] = [
18+
const COMPLETED_PROGRESS: StepState[] = [
1919
{ step: 'creating-car', status: 'completed', progress: 100 },
2020
{ step: 'checking-readiness', status: 'completed', progress: 100 },
2121
{ step: 'uploading-car', status: 'completed', progress: 100 },
@@ -99,7 +99,7 @@ export default function Content() {
9999
isExpanded={activeUploadExpanded}
100100
onToggleExpanded={() => setActiveUploadExpanded(!activeUploadExpanded)}
101101
pieceCid={activeUpload.pieceCid ?? ''}
102-
progresses={activeUpload.progress}
102+
stepStates={activeUpload.stepStates}
103103
transactionHash={activeUpload.transactionHash ?? ''}
104104
/>
105105
</div>
@@ -124,7 +124,7 @@ export default function Content() {
124124
key={upload.id}
125125
onToggleExpanded={() => toggleExpansion(upload.id)}
126126
pieceCid={upload.pieceCid}
127-
progresses={COMPLETED_PROGRESS}
127+
stepStates={COMPLETED_PROGRESS}
128128
transactionHash={upload.transactionHash}
129129
/>
130130
))}

src/components/ui/badge-status.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { cva, type VariantProps } from 'class-variance-authority'
22
import { CircleCheck, LoaderCircle } from 'lucide-react'
3-
import type { Progress } from '../../types/upload-progress.ts'
3+
import type { StepState } from '../../types/upload/step.ts'
44
import { cn } from '../../utils/cn.ts'
55

6-
export type Status = Progress['status'] | 'pinned'
6+
export type Status = StepState['status'] | 'pinned' | 'published'
77

88
type BadgeStatusProps = VariantProps<typeof badgeVariants> & {
99
status: Status
@@ -15,6 +15,7 @@ const badgeVariants = cva('inline-flex items-center gap-1 pl-1.5 pr-2 py-0.5 rou
1515
'in-progress': 'bg-badge-in-progress text-badge-in-progress-text border border-badge-in-progress-border',
1616
completed: 'bg-brand-950 text-brand-700 border border-brand-900',
1717
pinned: 'bg-brand-950 text-brand-700 border border-brand-900',
18+
published: 'bg-yellow-600/30 border border-yellow-400/20 text-yellow-200',
1819
error: null,
1920
pending: 'bg-zinc-800 border border-zinc-700 text-zinc-300',
2021
},
@@ -28,6 +29,7 @@ const statusIcons: Record<Status, React.ReactNode> = {
2829
'in-progress': <LoaderCircle className="animate-spin" size={12} />,
2930
completed: <CircleCheck size={12} />,
3031
pinned: <CircleCheck size={12} />,
32+
published: null,
3133
error: null,
3234
pending: null,
3335
}
@@ -36,6 +38,7 @@ const statusLabels: Record<Status, string | null> = {
3638
'in-progress': 'In progress',
3739
completed: 'Complete',
3840
pinned: 'Pinned',
41+
published: 'Published',
3942
error: null,
4043
pending: 'Pending',
4144
}

src/components/ui/card.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Progress } from '../../types/upload-progress.ts'
1+
import type { StepState } from '../../types/upload/step.ts'
22
import { BadgeStatus } from './badge-status.tsx'
33
import { Heading } from './heading.tsx'
44
import { Spinner } from './spinner.tsx'
@@ -9,7 +9,7 @@ type CardWrapperProps = {
99

1010
type CardHeaderProps = {
1111
title: string
12-
status: Progress['status']
12+
status: StepState['status']
1313
estimatedTime?: string
1414
withSpinner?: boolean
1515
}
Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { getIpfsGatewayDownloadLink, getIpfsGatewayRenderLink } from '@/utils/links.ts'
2-
import { COMBINED_STEPS } from '../../constants/upload-status.tsx'
32
import { INPI_ERROR_MESSAGE } from '../../hooks/use-filecoin-upload.ts'
3+
import { useStepStates } from '../../hooks/use-step-states.ts'
44
import { useUploadProgress } from '../../hooks/use-upload-progress.ts'
5-
import type { Progress } from '../../types/upload-progress.ts'
5+
import type { StepState } from '../../types/upload/step.ts'
66
import { Alert } from '../ui/alert.tsx'
77
import { Card } from '../ui/card.tsx'
88
import { DownloadButton } from '../ui/download-button.tsx'
@@ -11,7 +11,7 @@ import { ProgressCard } from './progress-card.tsx'
1111
import { ProgressCardCombined } from './progress-card-combined.tsx'
1212

1313
interface CarUploadAndIpniCardProps {
14-
progresses: Progress[]
14+
stepStates: StepState[]
1515
cid?: string
1616
fileName: string
1717
}
@@ -22,50 +22,45 @@ interface CarUploadAndIpniCardProps {
2222
* It will shrink to a single card if the uploading-car and announcing-cids steps are completed.
2323
* Otherwise, it will display the progress of the uploading-car and announcing-cids steps.
2424
*/
25-
export const CarUploadAndIpniCard = ({ progresses, cid, fileName }: CarUploadAndIpniCardProps) => {
25+
export const CarUploadAndIpniCard = ({ stepStates, cid, fileName }: CarUploadAndIpniCardProps) => {
2626
// Use the upload progress hook to calculate all progress-related values
27-
const { getCombinedFirstStageProgress, getCombinedFirstStageStatus, hasIpniFailure } = useUploadProgress(
28-
progresses,
29-
cid
30-
)
31-
const uploadingStep = progresses.find((p) => p.step === 'uploading-car')
32-
const announcingStep = progresses.find((p) => p.step === 'announcing-cids')
27+
const { uploadOutcome } = useUploadProgress({
28+
stepStates,
29+
cid,
30+
})
31+
32+
const { hasIpniAnnounceFailure } = uploadOutcome
33+
34+
const { announcingCidsStep, uploadingCarStep } = useStepStates(stepStates)
3335

3436
const shouldShowCidCard =
35-
uploadingStep?.status === 'completed' &&
36-
(announcingStep?.status === 'completed' || announcingStep?.status === 'error') &&
37+
uploadingCarStep?.status === 'completed' &&
38+
(announcingCidsStep?.status === 'completed' || announcingCidsStep?.status === 'error') &&
3739
cid
3840

3941
if (shouldShowCidCard) {
4042
return (
4143
<Card.Wrapper>
42-
{hasIpniFailure && <Alert message={INPI_ERROR_MESSAGE} variant="warning" />}
44+
{hasIpniAnnounceFailure && <Alert message={INPI_ERROR_MESSAGE} variant="warning" />}
4345
<Card.InfoRow
4446
subtitle={
4547
<TextWithCopyToClipboard
4648
text={cid}
47-
{...(!hasIpniFailure && { href: getIpfsGatewayRenderLink(cid, fileName) })}
49+
{...(!hasIpniAnnounceFailure && { href: getIpfsGatewayRenderLink(cid, fileName) })}
4850
/>
4951
}
5052
title="IPFS Root CID"
5153
>
52-
{!hasIpniFailure && <DownloadButton href={getIpfsGatewayDownloadLink(cid, fileName)} />}
54+
{!hasIpniAnnounceFailure && <DownloadButton href={getIpfsGatewayDownloadLink(cid, fileName)} />}
5355
</Card.InfoRow>
5456
</Card.Wrapper>
5557
)
5658
}
5759

58-
// Filter progresses to only include the combined steps for ProgressCardCombined
59-
const combinedProgresses = progresses.filter((p) => COMBINED_STEPS.includes(p.step))
60-
6160
return (
6261
<>
63-
<ProgressCardCombined
64-
getCombinedFirstStageProgress={getCombinedFirstStageProgress}
65-
getCombinedFirstStageStatus={getCombinedFirstStageStatus}
66-
progresses={combinedProgresses}
67-
/>
68-
{announcingStep && <ProgressCard progress={announcingStep} />}
62+
<ProgressCardCombined stepStates={stepStates} />
63+
{announcingCidsStep && <ProgressCard stepState={announcingCidsStep} />}
6964
</>
7065
)
7166
}

src/components/upload/progress-card-combined.tsx

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
1-
import type { Progress } from '../../types/upload-progress.ts'
2-
import { getEstimatedTime, getStepLabel } from '../../utils/upload-status.ts'
1+
import { useFirstStageState } from '@/hooks/use-first-stage-state.ts'
2+
import { useStepStates } from '@/hooks/use-step-states.ts'
3+
import type { StepState } from '../../types/upload/step.ts'
4+
import { getStepEstimatedTime, getStepLabel } from '../../utils/upload/step-utils.ts'
35
import { Card } from '../ui/card.tsx'
46
import { ProgressBar } from '../ui/progress-bar.tsx'
57

68
interface ProgressCardCombinedProps {
7-
progresses: Array<Progress>
8-
getCombinedFirstStageStatus: () => Progress['status']
9-
getCombinedFirstStageProgress: () => number
9+
stepStates: Array<StepState>
1010
}
1111

12-
function ProgressCardCombined({
13-
progresses,
14-
getCombinedFirstStageStatus,
15-
getCombinedFirstStageProgress,
16-
}: ProgressCardCombinedProps) {
17-
const hasCreatingCarStep = progresses.find((progress) => progress.step === 'creating-car')
12+
function ProgressCardCombined({ stepStates }: ProgressCardCombinedProps) {
13+
const { creatingCarStep } = useStepStates(stepStates)
14+
const { progress, status } = useFirstStageState(stepStates)
1815

19-
const firstStagestatus = getCombinedFirstStageStatus()
20-
const firstStageProgress = getCombinedFirstStageProgress()
21-
22-
if (!hasCreatingCarStep) return null
16+
if (!creatingCarStep) return null
2317

2418
return (
2519
<Card.Wrapper>
2620
<Card.Header
27-
estimatedTime={getEstimatedTime('creating-car')}
28-
status={firstStagestatus}
21+
estimatedTime={getStepEstimatedTime('creating-car')}
22+
status={status}
2923
title={getStepLabel('creating-car')}
3024
/>
31-
{firstStagestatus === 'in-progress' && <ProgressBar progress={firstStageProgress} />}
25+
{status === 'in-progress' && <ProgressBar progress={progress} />}
3226
</Card.Wrapper>
3327
)
3428
}

src/components/upload/progress-card.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
import type { Progress } from '@/types/upload-progress.ts'
2-
import { getEstimatedTime, getStepLabel } from '../../utils/upload-status.ts'
1+
import type { StepState } from '../../types/upload/step.ts'
2+
import { getStepEstimatedTime, getStepLabel } from '../../utils/upload/step-utils.ts'
33
import { Alert } from '../ui/alert.tsx'
44
import { Card } from '../ui/card.tsx'
55
import { TextWithCopyToClipboard } from '../ui/text-with-copy-to-clipboard.tsx'
66

77
interface ProgressCardProps {
8-
progress: Progress
8+
stepState: StepState
99
transactionHash?: string
1010
}
1111

12-
function ProgressCard({ progress, transactionHash }: ProgressCardProps) {
12+
function ProgressCard({ stepState, transactionHash }: ProgressCardProps) {
1313
return (
1414
<Card.Wrapper>
1515
<Card.Header
16-
estimatedTime={getEstimatedTime(progress.step)}
17-
status={progress.status}
18-
title={getStepLabel(progress.step)}
16+
estimatedTime={getStepEstimatedTime(stepState.step)}
17+
status={stepState.status}
18+
title={getStepLabel(stepState.step)}
1919
withSpinner
2020
/>
2121

22-
{progress.error && (
23-
<Alert message={progress.error} variant={progress.step === 'announcing-cids' ? 'warning' : 'error'} />
22+
{stepState.error && (
23+
<Alert message={stepState.error} variant={stepState.step === 'announcing-cids' ? 'warning' : 'error'} />
2424
)}
2525

26-
{progress.step === 'finalizing-transaction' && transactionHash && (
26+
{stepState.step === 'finalizing-transaction' && transactionHash && (
2727
<Card.Content>
2828
<TextWithCopyToClipboard
2929
href={`https://filecoin-testnet.blockscout.com/tx/${transactionHash}`}

src/components/upload/upload-progress.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import type { Progress } from '../../types/upload-progress.ts'
1+
import type { StepState } from '../../types/upload/step.ts'
22
import { CarUploadAndIpniCard } from './car-upload-and-ipni-card.tsx'
33
import { ProgressCard } from './progress-card.tsx'
44
import type { UploadStatusProps } from './upload-status.tsx'
55

66
interface UploadProgressProps {
7-
progresses: Array<Progress>
7+
stepStates: Array<StepState>
88
transactionHash?: UploadStatusProps['transactionHash']
99
cid?: string
1010
fileName: string
1111
}
12-
function UploadProgress({ progresses, transactionHash, cid, fileName }: UploadProgressProps) {
13-
const finalizingStep = progresses.find((p) => p.step === 'finalizing-transaction')
12+
function UploadProgress({ stepStates, transactionHash, cid, fileName }: UploadProgressProps) {
13+
const finalizingStep = stepStates.find((stepState) => stepState.step === 'finalizing-transaction')
1414
return (
1515
<>
16-
<CarUploadAndIpniCard cid={cid} fileName={fileName} progresses={progresses} />
17-
{finalizingStep && <ProgressCard progress={finalizingStep} transactionHash={transactionHash} />}
16+
<CarUploadAndIpniCard cid={cid} fileName={fileName} stepStates={stepStates} />
17+
{finalizingStep && <ProgressCard stepState={finalizingStep} transactionHash={transactionHash} />}
1818
</>
1919
)
2020
}

src/components/upload/upload-status.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { DatasetPiece } from '../../hooks/use-dataset-pieces.ts'
22
import { useUploadProgress } from '../../hooks/use-upload-progress.ts'
3-
import type { Progress } from '../../types/upload-progress.ts'
3+
import type { StepState } from '../../types/upload/step.ts'
44
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '../ui/accordion.tsx'
55
import { FileInfo } from '../ui/file-info.tsx'
66
import { UploadCompleted } from './upload-completed.tsx'
@@ -9,7 +9,7 @@ import { UploadProgress } from './upload-progress.tsx'
99
export interface UploadStatusProps {
1010
fileName: DatasetPiece['fileName']
1111
fileSize: DatasetPiece['fileSize']
12-
progresses: Array<Progress>
12+
stepStates: Array<StepState>
1313
isExpanded?: boolean
1414
onToggleExpanded?: () => void
1515
cid?: DatasetPiece['cid']
@@ -22,7 +22,7 @@ export interface UploadStatusProps {
2222
function UploadStatus({
2323
fileName,
2424
fileSize,
25-
progresses,
25+
stepStates,
2626
isExpanded = true,
2727
onToggleExpanded,
2828
cid,
@@ -31,7 +31,9 @@ function UploadStatus({
3131
transactionHash,
3232
}: UploadStatusProps) {
3333
// Use the upload progress hook to calculate all progress-related values
34-
const { isCompleted, badgeStatus } = useUploadProgress(progresses, cid)
34+
const { uploadOutcome, uploadBadgeStatus } = useUploadProgress({ stepStates, cid })
35+
36+
const { isUploadSuccessful } = uploadOutcome
3537

3638
return (
3739
<Accordion
@@ -42,15 +44,15 @@ function UploadStatus({
4244
value={isExpanded ? 'file-card' : ''}
4345
>
4446
<AccordionItem value="file-card">
45-
<FileInfo badgeStatus={badgeStatus} fileName={fileName} fileSize={fileSize}>
47+
<FileInfo badgeStatus={uploadBadgeStatus} fileName={fileName} fileSize={fileSize}>
4648
<AccordionTrigger />
4749
</FileInfo>
4850

4951
<AccordionContent className="space-y-6 mt-6">
50-
{isCompleted && cid ? (
52+
{isUploadSuccessful && cid ? (
5153
<UploadCompleted cid={cid} datasetId={datasetId} fileName={fileName} pieceCid={pieceCid} />
5254
) : (
53-
<UploadProgress cid={cid} fileName={fileName} progresses={progresses} transactionHash={transactionHash} />
55+
<UploadProgress cid={cid} fileName={fileName} stepStates={stepStates} transactionHash={transactionHash} />
5456
)}
5557
</AccordionContent>
5658
</AccordionItem>

src/constants/upload-status.tsx

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)