forked from PinSpace-Org/GistPin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExportButton.tsx
More file actions
64 lines (55 loc) 路 1.62 KB
/
Copy pathExportButton.tsx
File metadata and controls
64 lines (55 loc) 路 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use client';
import { useState } from 'react';
interface ExportButtonProps {
label?: string;
onExport: (onProgress: (progress: number) => void) => Promise<void>;
}
export default function ExportButton({
label = 'Export CSV',
onExport,
}: ExportButtonProps) {
const [progress, setProgress] = useState<number | null>(null);
const [error, setError] = useState<string | null>(null);
const handleExport = async () => {
setError(null);
setProgress(0);
try {
await onExport((value) => setProgress(Math.min(100, Math.max(0, value))));
setProgress(100);
window.setTimeout(() => setProgress(null), 900);
} catch (err) {
setProgress(null);
setError(err instanceof Error ? err.message : 'Export failed');
}
};
return (
<div style={{ marginBottom: 12 }}>
<button
onClick={handleExport}
disabled={progress !== null}
style={{
border: '1px solid #cbd5e1',
borderRadius: 999,
background: progress !== null ? '#e2e8f0' : '#ffffff',
color: '#0f172a',
padding: '8px 14px',
fontSize: 13,
fontWeight: 600,
cursor: progress !== null ? 'wait' : 'pointer',
}}
>
{progress !== null ? `Exporting ${progress}%` : label}
</button>
{progress !== null && (
<div style={{ marginTop: 8, fontSize: 12, color: '#475569' }}>
Preparing CSV and starting download automatically.
</div>
)}
{error && (
<div style={{ marginTop: 8, fontSize: 12, color: '#b91c1c' }}>
{error}
</div>
)}
</div>
);
}