|
| 1 | +import { View } from 'react-native'; |
| 2 | + |
| 3 | +import { FINDING_ROW_FRAME_CLASS } from '@/components/security-agent/finding-row'; |
| 4 | +import { Skeleton } from '@/components/ui/skeleton'; |
| 5 | +import { cn } from '@/lib/utils'; |
| 6 | + |
| 7 | +const SKELETON_ROW_COUNT = 3; |
| 8 | + |
| 9 | +/** Title bar widths, varied per row so the list does not read as a grid. */ |
| 10 | +const TITLE_WIDTHS = ['w-3/4', 'w-2/3', 'w-1/2'] as const; |
| 11 | +const REPO_WIDTHS = ['w-1/3', 'w-2/5', 'w-1/4'] as const; |
| 12 | + |
| 13 | +/** |
| 14 | + * The line boxes a finding card gives its text at the app's 14pt rem: the 11px |
| 15 | + * severity label, a one-line `text-sm` title, the `text-xs` repository, the meta |
| 16 | + * row beside it behind `pt-0.5`, and the quick action behind `mt-1`, which is the |
| 17 | + * card's button. Each box holds a bar of its own, so the placeholder stands in |
| 18 | + * the card's frame and the cards replace it in place. |
| 19 | + * |
| 20 | + * A card is content-sized, so the frame covers the shape the list shows for a |
| 21 | + * finding that offers an action: 143.6 points measured against the card's own |
| 22 | + * 144.0. Three variants differ, and neither is reserved because a placeholder |
| 23 | + * cannot stand for all of them: a card whose quick action is the one-line |
| 24 | + * `text-xs` label is shorter by the button's height, a card with no action |
| 25 | + * measured 99.0 points, and a title that wraps to its second line adds one |
| 26 | + * `text-sm` box while a meta row that wraps adds one `text-xs` box. |
| 27 | + */ |
| 28 | +const SEVERITY_LINE_CLASS = 'h-[15px] justify-center'; |
| 29 | +const TITLE_LINE_CLASS = 'h-[17.5px] justify-center'; |
| 30 | +const REPO_LINE_CLASS = 'h-[14px] justify-center'; |
| 31 | +const META_LINE_CLASS = 'h-[14px] flex-row items-center gap-3'; |
| 32 | +const ACTION_CLASS = 'mt-1'; |
| 33 | + |
| 34 | +/** |
| 35 | + * One finding card's placeholder. `index` only varies the bar widths; every |
| 36 | + * row reserves the same card frame, so a three-row placeholder stands exactly |
| 37 | + * where three cards will. |
| 38 | + */ |
| 39 | +export function FindingRowSkeleton({ index }: Readonly<{ index: number }>) { |
| 40 | + const variant = index % TITLE_WIDTHS.length; |
| 41 | + return ( |
| 42 | + <View testID="finding-row-skeleton" className={FINDING_ROW_FRAME_CLASS}> |
| 43 | + <View className="gap-1.5"> |
| 44 | + <View className={SEVERITY_LINE_CLASS}> |
| 45 | + <Skeleton className="h-2.5 w-16 rounded-full" /> |
| 46 | + </View> |
| 47 | + <View className={TITLE_LINE_CLASS}> |
| 48 | + <Skeleton className={cn('h-3.5 rounded-full', TITLE_WIDTHS[variant])} /> |
| 49 | + </View> |
| 50 | + <View className={REPO_LINE_CLASS}> |
| 51 | + <Skeleton className={cn('h-2.5 rounded-full', REPO_WIDTHS[variant])} /> |
| 52 | + </View> |
| 53 | + <View className="pt-0.5"> |
| 54 | + <View className={META_LINE_CLASS}> |
| 55 | + <Skeleton className="h-2.5 w-20 rounded-full" /> |
| 56 | + <Skeleton className="h-2.5 w-16 rounded-full" /> |
| 57 | + </View> |
| 58 | + </View> |
| 59 | + </View> |
| 60 | + <View className={ACTION_CLASS}> |
| 61 | + <Skeleton className="h-[36px] w-24 rounded-md" /> |
| 62 | + </View> |
| 63 | + </View> |
| 64 | + ); |
| 65 | +} |
| 66 | + |
| 67 | +/** |
| 68 | + * The placeholder rows of a findings list, separated by the same `h-3` band the |
| 69 | + * loaded list's item separator paints, so a row keeps its place from the first |
| 70 | + * paint to the loaded card. |
| 71 | + */ |
| 72 | +export function FindingListSkeletonRows() { |
| 73 | + return ( |
| 74 | + <> |
| 75 | + {Array.from({ length: SKELETON_ROW_COUNT }, (_, index) => ( |
| 76 | + <View key={index} className={index === 0 ? undefined : 'pt-3'}> |
| 77 | + <FindingRowSkeleton index={index} /> |
| 78 | + </View> |
| 79 | + ))} |
| 80 | + </> |
| 81 | + ); |
| 82 | +} |
0 commit comments