MCPcopy
hub / github.com/027xiguapi/code-box / DownloadImages

Function DownloadImages

component/items/downloadImages.tsx:8–58  ·  view source on GitHub ↗
({ name })

Source from the content-addressed store, hash-verified

6import { i18n } from "~tools"
7
8export default function DownloadImages({ name }) {
9 const [isDownloading, setIsDownloading] = useState(false)
10 const [progress, setProgress] = useState(0)
11
12 const handleDownload = async () => {
13 if (isDownloading) return
14
15 try {
16 setIsDownloading(true)
17 setProgress(0)
18
19 const res = await sendToContentScript({
20 name: `${name}-downloadImages`,
21 body: {
22 onProgress: (current, total) => {
23 const percentage = Math.round((current / total) * 100)
24 setProgress(percentage)
25 }
26 }
27 })
28 } catch (error) {
29 console.error("Failed to download images:", error)
30 } finally {
31 setIsDownloading(false)
32 setProgress(0)
33 }
34 }
35
36 return (
37 <div
38 className={`item download ${isDownloading ? "downloading" : ""}`}
39 onClick={handleDownload}
40 style={{
41 opacity: isDownloading ? 0.7 : 1,
42 cursor: isDownloading ? "not-allowed" : "pointer"
43 }}>
44 <span>
45 <StarTwoTone twoToneColor="#eb2f96" style={{ marginRight: "5px" }} />
46 {isDownloading
47 ? `${i18n("downloading")} (${progress}%)`
48 : i18n("downloadAllImg")}
49 </span>
50 <DownloadOutlined
51 style={{
52 color: isDownloading ? "#999" : "#52c41a",
53 fontSize: "16px"
54 }}
55 />
56 </div>
57 )
58}

Callers

nothing calls this directly

Calls 1

i18nFunction · 0.85

Tested by

no test coverage detected