File size: 1,374 Bytes
604cfe9
 
 
 
 
 
 
 
 
 
 
 
 
9cf5a85
 
02dd4b1
9cf5a85
 
02dd4b1
9cf5a85
02dd4b1
ea6c2a8
 
6b62e9d
ea6c2a8
42c94bf
604cfe9
42c94bf
5680859
ea6c2a8
 
 
a582fa0
ea6c2a8
 
42c94bf
 
604cfe9
42c94bf
ea6c2a8
6b62e9d
604cfe9
ea6c2a8
9cf5a85
ea6c2a8
 
 
 
604cfe9
 
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
import { useState } from "react";
import classNames from "classnames";

const downloadFile = (filename: string, content: string) => {
  const blob = new Blob([content], { type: "text/html" });
  const url = URL.createObjectURL(blob);
  const a = document.createElement("a");
  a.href = url;
  a.download = filename;
  a.click();
  URL.revokeObjectURL(url);
};

function DeployButton({
  html,
  error: _error, // ✅ Renamed to "_error" to avoid unused warning
}: {
  html: string;
  error?: boolean;
}) {

  const [loading, setLoading] = useState(false);

  const handleDownload = () => {
    setLoading(true);
    setTimeout(() => {
      downloadFile("index.html", html);
      setLoading(false);
    }, 300);
  };

  return (
    <div className="relative flex items-center justify-end">
      <button
        className={classNames(
          "relative cursor-pointer flex-none flex items-center justify-center rounded-md text-xs lg:text-sm font-semibold leading-5 lg:leading-6 py-2 px-6 hover:bg-pink-400 text-white bg-pink-500 shadow-sm dark:shadow-highlight/20 transition-all duration-100",
          {
            "opacity-50 cursor-not-allowed": loading,
          }
        )}
        onClick={handleDownload}
        disabled={loading}
      >
        {loading ? "Preparing..." : "Download Project"}
      </button>
    </div>
  );
}

export default DeployButton;