import { getUser } from '../../lib/jwt'; import { getPercentage } from '../../helper/number'; import { ResourceProgressActions } from './ResourceProgressActions'; import { cn } from '../../lib/classname'; type ResourceProgressType = { resourceType: 'roadmap' | 'best-practice'; resourceId: string; title: string; updatedAt: string; totalCount: number; doneCount: number; learningCount: number; skippedCount: number; onCleared?: () => void; showClearButton?: boolean; isCustomResource: boolean; roadmapSlug?: string; showActions?: boolean; onResourceClick?: () => void; }; export function ResourceProgress(props: ResourceProgressType) { const { showClearButton = true, isCustomResource, showActions = true, onResourceClick, } = props; const userId = getUser()?.id; const { updatedAt, resourceType, resourceId, title, totalCount, learningCount, doneCount, skippedCount, onCleared, roadmapSlug, } = props; let url = resourceType === 'roadmap' ? `/${resourceId}` : `/best-practices/${resourceId}`; if (isCustomResource) { url = `/r/${roadmapSlug}`; } const totalMarked = doneCount + skippedCount; const progressPercentage = getPercentage(totalMarked, totalCount); const Slot = onResourceClick ? 'button' : 'a'; return (
{title} {parseInt(progressPercentage, 10)}% {showActions && (
)}
); }