Spaces:
Sleeping
Sleeping
Update src/components/deploy-button/deploy-button.tsx
Browse files
src/components/deploy-button/deploy-button.tsx
CHANGED
@@ -2,6 +2,8 @@
|
|
2 |
import { useState } from "react";
|
3 |
import classNames from "classnames";
|
4 |
import { toast } from "react-toastify";
|
|
|
|
|
5 |
|
6 |
import SpaceIcon from "@/assets/space.svg";
|
7 |
import Loading from "../loading/loading";
|
@@ -73,6 +75,30 @@ function DeployButton({
|
|
73 |
}
|
74 |
};
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
return (
|
77 |
<div className="relative flex items-center justify-end">
|
78 |
{auth && (
|
@@ -99,6 +125,15 @@ function DeployButton({
|
|
99 |
>
|
100 |
{path ? "Update Space" : "Deploy to Space"}
|
101 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
<div
|
103 |
className={classNames(
|
104 |
"h-screen w-screen bg-black/20 fixed left-0 top-0 z-10",
|
|
|
2 |
import { useState } from "react";
|
3 |
import classNames from "classnames";
|
4 |
import { toast } from "react-toastify";
|
5 |
+
import JSZip from "jszip";
|
6 |
+
|
7 |
|
8 |
import SpaceIcon from "@/assets/space.svg";
|
9 |
import Loading from "../loading/loading";
|
|
|
75 |
}
|
76 |
};
|
77 |
|
78 |
+
const downloadZipFile = async () => {
|
79 |
+
const zip = new JSZip();
|
80 |
+
|
81 |
+
// Assume HTML is always present
|
82 |
+
zip.file("index.html", html);
|
83 |
+
|
84 |
+
// Optional: Add more files if available from your generator logic
|
85 |
+
// You may modify this depending on how your app stores code
|
86 |
+
if (state?.reactCode) zip.file("index.tsx", state.reactCode);
|
87 |
+
if (state?.cssCode) zip.file("style.css", state.cssCode);
|
88 |
+
if (state?.jsCode) zip.file("script.js", state.jsCode);
|
89 |
+
|
90 |
+
const blob = await zip.generateAsync({ type: "blob" });
|
91 |
+
const url = URL.createObjectURL(blob);
|
92 |
+
const a = document.createElement("a");
|
93 |
+
a.href = url;
|
94 |
+
a.download = config.title?.trim()
|
95 |
+
? `${config.title.trim()}.zip`
|
96 |
+
: "website.zip";
|
97 |
+
document.body.appendChild(a);
|
98 |
+
a.click();
|
99 |
+
document.body.removeChild(a);
|
100 |
+
};
|
101 |
+
|
102 |
return (
|
103 |
<div className="relative flex items-center justify-end">
|
104 |
{auth && (
|
|
|
125 |
>
|
126 |
{path ? "Update Space" : "Deploy to Space"}
|
127 |
</button>
|
128 |
+
<div className="pt-2 text-right">
|
129 |
+
<button
|
130 |
+
className="rounded-full bg-gray-800 px-5 py-2 text-white font-semibold text-xs hover:bg-gray-700 transition-all duration-100"
|
131 |
+
onClick={downloadZipFile}
|
132 |
+
>
|
133 |
+
Download Full Source (.zip)
|
134 |
+
</button>
|
135 |
+
</div>
|
136 |
+
|
137 |
<div
|
138 |
className={classNames(
|
139 |
"h-screen w-screen bg-black/20 fixed left-0 top-0 z-10",
|