|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { useState, useEffect } from "react"; |
| 4 | +import { isFileSystemObserverSupported } from "../lib/fileObserver"; |
| 5 | +import { useTranslations } from "./LocaleProvider"; |
| 6 | +import { motion, AnimatePresence } from "framer-motion"; |
| 7 | + |
| 8 | +export default function IncrementalScanAlert() { |
| 9 | + const [showAlert, setShowAlert] = useState(false); |
| 10 | + const [isSupported, setIsSupported] = useState(true); |
| 11 | + const { t } = useTranslations(); |
| 12 | + |
| 13 | + useEffect(() => { |
| 14 | + // 只在客户端执行 |
| 15 | + if (typeof window === "undefined") return; |
| 16 | + |
| 17 | + // 检查是否支持FileSystemObserver API |
| 18 | + const supported = isFileSystemObserverSupported(); |
| 19 | + setIsSupported(supported); |
| 20 | + |
| 21 | + // 无论是否支持,都显示提示 |
| 22 | + setShowAlert(true); |
| 23 | + }, []); |
| 24 | + |
| 25 | + // 如果用户关闭了提示,则不显示 |
| 26 | + if (!showAlert) return null; |
| 27 | + |
| 28 | + return ( |
| 29 | + <AnimatePresence> |
| 30 | + <motion.div |
| 31 | + initial={{ opacity: 0, y: -10 }} |
| 32 | + animate={{ opacity: 1, y: 0 }} |
| 33 | + exit={{ opacity: 0, y: -10 }} |
| 34 | + className={`mb-4 ${ |
| 35 | + isSupported |
| 36 | + ? "bg-green-50 dark:bg-green-900/30 border-green-200 dark:border-green-700" |
| 37 | + : "bg-yellow-50 dark:bg-yellow-900/30 border-yellow-200 dark:border-yellow-700" |
| 38 | + } border rounded-lg p-4 flex items-start`} |
| 39 | + > |
| 40 | + <div |
| 41 | + className={`flex-shrink-0 ${ |
| 42 | + isSupported |
| 43 | + ? "text-green-500 dark:text-green-400" |
| 44 | + : "text-yellow-500 dark:text-yellow-400" |
| 45 | + }`} |
| 46 | + > |
| 47 | + {isSupported ? ( |
| 48 | + // 支持增量扫描时显示的图标 |
| 49 | + <svg |
| 50 | + xmlns="http://www.w3.org/2000/svg" |
| 51 | + className="h-5 w-5" |
| 52 | + viewBox="0 0 20 20" |
| 53 | + fill="currentColor" |
| 54 | + > |
| 55 | + <path |
| 56 | + fillRule="evenodd" |
| 57 | + d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" |
| 58 | + clipRule="evenodd" |
| 59 | + /> |
| 60 | + </svg> |
| 61 | + ) : ( |
| 62 | + // 不支持增量扫描时显示的图标 |
| 63 | + <svg |
| 64 | + xmlns="http://www.w3.org/2000/svg" |
| 65 | + className="h-5 w-5" |
| 66 | + viewBox="0 0 20 20" |
| 67 | + fill="currentColor" |
| 68 | + > |
| 69 | + <path |
| 70 | + fillRule="evenodd" |
| 71 | + d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" |
| 72 | + clipRule="evenodd" |
| 73 | + /> |
| 74 | + </svg> |
| 75 | + )} |
| 76 | + </div> |
| 77 | + <div className="ml-3 flex-1"> |
| 78 | + <div |
| 79 | + className={`text-sm ${ |
| 80 | + isSupported |
| 81 | + ? "text-green-700 dark:text-green-300" |
| 82 | + : "text-yellow-700 dark:text-yellow-300" |
| 83 | + }`} |
| 84 | + > |
| 85 | + {isSupported ? ( |
| 86 | + // 支持增量扫描时显示的文本 |
| 87 | + <> |
| 88 | + <p className="font-medium mb-1"> |
| 89 | + {t("incrementalScan.supported")} |
| 90 | + </p> |
| 91 | + </> |
| 92 | + ) : ( |
| 93 | + // 不支持增量扫描时显示的文本 |
| 94 | + <> |
| 95 | + <p className="font-medium mb-1"> |
| 96 | + {t("incrementalScan.notSupported")} |
| 97 | + </p> |
| 98 | + </> |
| 99 | + )} |
| 100 | + </div> |
| 101 | + </div> |
| 102 | + <button |
| 103 | + onClick={() => setShowAlert(false)} |
| 104 | + className={`ml-auto flex-shrink-0 ${ |
| 105 | + isSupported |
| 106 | + ? "text-green-500 hover:text-green-700 dark:text-green-400 dark:hover:text-green-300" |
| 107 | + : "text-yellow-500 hover:text-yellow-700 dark:text-yellow-400 dark:hover:text-yellow-300" |
| 108 | + } focus:outline-none`} |
| 109 | + aria-label="关闭提示" |
| 110 | + > |
| 111 | + <svg |
| 112 | + className="h-5 w-5" |
| 113 | + xmlns="http://www.w3.org/2000/svg" |
| 114 | + viewBox="0 0 20 20" |
| 115 | + fill="currentColor" |
| 116 | + > |
| 117 | + <path |
| 118 | + fillRule="evenodd" |
| 119 | + d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" |
| 120 | + clipRule="evenodd" |
| 121 | + /> |
| 122 | + </svg> |
| 123 | + </button> |
| 124 | + </motion.div> |
| 125 | + </AnimatePresence> |
| 126 | + ); |
| 127 | +} |
0 commit comments