| 1 | /** |
| 2 | * FansRefreshActions - 频道粉丝数刷新操作区 |
| 3 | * 提供全部平台刷新入口。 |
| 4 | */ |
| 5 | |
| 6 | 'use client' |
| 7 | |
| 8 | import type { PlatType } from '@/app/config/platConfig' |
| 9 | import { Loader2, RefreshCw } from 'lucide-react' |
| 10 | import { useTransClient } from '@/app/i18n/client' |
| 11 | import { Button } from '@/components/ui/button' |
| 12 | |
| 13 | interface FansRefreshActionsProps { |
| 14 | refreshingTarget: 'all' | PlatType | null |
| 15 | refreshProgress: { current: number, total: number } | null |
| 16 | onRefreshAll: () => void |
| 17 | } |
| 18 | |
| 19 | export function FansRefreshActions({ |
| 20 | refreshingTarget, |
| 21 | refreshProgress, |
| 22 | onRefreshAll, |
| 23 | }: FansRefreshActionsProps) { |
| 24 | const { t } = useTransClient('account') |
| 25 | const isRefreshingAll = refreshingTarget === 'all' |
| 26 | const isRefreshing = refreshingTarget !== null |
| 27 | const shouldShowProgress = isRefreshingAll && refreshProgress && refreshProgress.total > 0 |
| 28 | |
| 29 | return ( |
| 30 | <div className="flex flex-col gap-2 rounded-lg border border-border/70 bg-card/80 p-3 shadow-sm sm:flex-row sm:items-center sm:justify-between"> |
| 31 | <div className="min-w-0"> |
| 32 | <div className="text-sm font-semibold text-foreground"> |
| 33 | {t('channelManager.refreshFansTitle')} |
| 34 | </div> |
| 35 | <div className="mt-0.5 text-xs text-muted-foreground"> |
| 36 | {t('channelManager.refreshFansDescription')} |
| 37 | </div> |
| 38 | </div> |
| 39 | |
| 40 | <div className="flex shrink-0 flex-wrap gap-2"> |
| 41 | <Button |
| 42 | data-testid="cm-refresh-all-fans-btn" |
| 43 | type="button" |
| 44 | size="sm" |
| 45 | disabled={isRefreshing} |
| 46 | className="cursor-pointer rounded-full bg-gradient-back text-gradient-foreground hover:opacity-90" |
| 47 | onClick={onRefreshAll} |
| 48 | > |
| 49 | {isRefreshingAll ? ( |
| 50 | <Loader2 className="mr-1.5 h-4 w-4 animate-spin" /> |
| 51 | ) : ( |
| 52 | <RefreshCw className="mr-1.5 h-4 w-4" /> |
| 53 | )} |
| 54 | {t('channelManager.refreshAllFans')} |
| 55 | {shouldShowProgress ? ( |
| 56 | <span className="ml-1.5 rounded-full bg-background/20 px-2 py-0.5 text-[11px] font-semibold tabular-nums text-gradient-foreground ring-1 ring-gradient-foreground/30"> |
| 57 | {refreshProgress.current} |
| 58 | / |
| 59 | {refreshProgress.total} |
| 60 | </span> |
| 61 | ) : null} |
| 62 | </Button> |
| 63 | </div> |
| 64 | </div> |
| 65 | ) |
| 66 | } |
| 67 |