| 1 | /** |
| 2 | * PluginUpdatePopover - 插件更新提示气泡 |
| 3 | * 用于在 hover trigger 时展示插件更新信息、下载入口和教程链接 |
| 4 | */ |
| 5 | |
| 6 | 'use client' |
| 7 | |
| 8 | import type * as HoverCardPrimitive from '@radix-ui/react-hover-card' |
| 9 | import { BookOpen, CloudDownload, TriangleAlert } from 'lucide-react' |
| 10 | import Link from 'next/link' |
| 11 | import React from 'react' |
| 12 | import { useTransClient } from '@/app/i18n/client' |
| 13 | import { isChineseLanguage } from '@/app/i18n/languageConfig' |
| 14 | import { Button } from '@/components/ui/button' |
| 15 | import { HoverCard, HoverCardContent, HoverCardTrigger } from '@/components/ui/hover-card' |
| 16 | import { PluginVersionLast } from '@/constant' |
| 17 | import { useGetClientLng } from '@/hooks/useSystem' |
| 18 | import { PLUGIN_DOWNLOAD_LINKS } from '@/store/plugin/constants' |
| 19 | |
| 20 | interface PluginUpdatePopoverProps { |
| 21 | /** 当前插件版本 */ |
| 22 | currentVersion: string |
| 23 | /** 触发器 */ |
| 24 | children: React.ReactElement |
| 25 | /** 气泡对齐方式 */ |
| 26 | align?: HoverCardPrimitive.HoverCardContentProps['align'] |
| 27 | /** 气泡方向 */ |
| 28 | side?: HoverCardPrimitive.HoverCardContentProps['side'] |
| 29 | /** 气泡偏移 */ |
| 30 | sideOffset?: number |
| 31 | } |
| 32 | |
| 33 | export function PluginUpdatePopover({ |
| 34 | currentVersion, |
| 35 | children, |
| 36 | align = 'end', |
| 37 | side = 'top', |
| 38 | sideOffset = 8, |
| 39 | }: PluginUpdatePopoverProps) { |
| 40 | const { t } = useTransClient('plugin') |
| 41 | const lng = useGetClientLng() |
| 42 | const updateLink = isChineseLanguage(lng) |
| 43 | ? PLUGIN_DOWNLOAD_LINKS.china |
| 44 | : PLUGIN_DOWNLOAD_LINKS.github |
| 45 | |
| 46 | return ( |
| 47 | <HoverCard openDelay={120} closeDelay={120}> |
| 48 | <HoverCardTrigger asChild>{children}</HoverCardTrigger> |
| 49 | <HoverCardContent |
| 50 | align={align} |
| 51 | side={side} |
| 52 | sideOffset={sideOffset} |
| 53 | className="w-[320px] rounded-xl border border-border p-3" |
| 54 | > |
| 55 | <div className="space-y-3"> |
| 56 | <div className="space-y-1"> |
| 57 | <p className="text-sm font-medium text-foreground"> |
| 58 | {t('version.popoverTitle', { version: PluginVersionLast })} |
| 59 | </p> |
| 60 | <p className="text-xs leading-5 text-muted-foreground"> |
| 61 | {t('version.current')} |
| 62 | {' '} |
| 63 | v |
| 64 | {currentVersion} |
| 65 | <span className="mx-1.5">·</span> |
| 66 | {t('version.latest')} |
| 67 | {' '} |
| 68 | v |
| 69 | {PluginVersionLast} |
| 70 | </p> |
| 71 | </div> |
| 72 | |
| 73 | <div className="flex items-center gap-2"> |
| 74 | <Button size="sm" className="h-8 gap-1.5 px-3 text-xs" asChild> |
| 75 | <a |
| 76 | href={updateLink} |
| 77 | target="_blank" |
| 78 | rel="noopener noreferrer" |
| 79 | > |
| 80 | <CloudDownload className="h-3.5 w-3.5" /> |
| 81 | {t('version.updateButton')} |
| 82 | </a> |
| 83 | </Button> |
| 84 | |
| 85 | <Link |
| 86 | href="/websit/plugin-update-docs" |
| 87 | className="inline-flex h-8 items-center text-xs text-muted-foreground transition-colors hover:text-foreground" |
| 88 | > |
| 89 | <BookOpen className="mr-1.5 h-3.5 w-3.5" /> |
| 90 | {t('version.viewUpdateGuide')} |
| 91 | </Link> |
| 92 | </div> |
| 93 | |
| 94 | <div className="flex items-start gap-2 rounded-lg border border-warning/20 bg-warning/10 px-2.5 py-2"> |
| 95 | <TriangleAlert className="mt-0.5 h-4 w-4 shrink-0 text-warning" /> |
| 96 | <p className="text-[11px] leading-4 text-muted-foreground"> |
| 97 | {t('version.googleStoreNotice')} |
| 98 | </p> |
| 99 | </div> |
| 100 | </div> |
| 101 | </HoverCardContent> |
| 102 | </HoverCard> |
| 103 | ) |
| 104 | } |
| 105 |