Spaces:
Sleeping
Sleeping
Update src/components/deploy-button/deploy-button.tsx
Browse files
src/components/deploy-button/deploy-button.tsx
CHANGED
@@ -3,8 +3,6 @@ import { useState } from "react";
|
|
3 |
import classNames from "classnames";
|
4 |
import { toast } from "react-toastify";
|
5 |
|
6 |
-
|
7 |
-
|
8 |
import SpaceIcon from "@/assets/space.svg";
|
9 |
import Loading from "../loading/loading";
|
10 |
import Login from "../login/login";
|
@@ -15,15 +13,24 @@ const MsgToast = ({ url }: { url: string }) => (
|
|
15 |
Your space is live!
|
16 |
<button
|
17 |
className="bg-black text-sm block text-white rounded-md px-3 py-1.5 hover:bg-gray-900 cursor-pointer"
|
18 |
-
onClick={() =>
|
19 |
-
window.open(url, "_blank");
|
20 |
-
}}
|
21 |
>
|
22 |
See Space
|
23 |
</button>
|
24 |
</div>
|
25 |
);
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
function DeployButton({
|
28 |
html,
|
29 |
error = false,
|
@@ -36,14 +43,10 @@ function DeployButton({
|
|
36 |
const [open, setOpen] = useState(false);
|
37 |
const [loading, setLoading] = useState(false);
|
38 |
const [path, setPath] = useState<string | undefined>(undefined);
|
39 |
-
|
40 |
-
const [config, setConfig] = useState({
|
41 |
-
title: "",
|
42 |
-
});
|
43 |
|
44 |
const createSpace = async () => {
|
45 |
setLoading(true);
|
46 |
-
|
47 |
try {
|
48 |
const request = await fetch("/api/deploy", {
|
49 |
method: "POST",
|
@@ -75,16 +78,6 @@ function DeployButton({
|
|
75 |
}
|
76 |
};
|
77 |
|
78 |
-
const downloadFile = (filename: string, content: string) => {
|
79 |
-
const blob = new Blob([content], { type: "text/html" });
|
80 |
-
const url = URL.createObjectURL(blob);
|
81 |
-
const a = document.createElement("a");
|
82 |
-
a.href = url;
|
83 |
-
a.download = filename;
|
84 |
-
a.click();
|
85 |
-
URL.revokeObjectURL(url);
|
86 |
-
};
|
87 |
-
|
88 |
return (
|
89 |
<div className="relative flex items-center justify-end">
|
90 |
{auth && (
|
@@ -99,6 +92,8 @@ const downloadFile = (filename: string, content: string) => {
|
|
99 |
</a>
|
100 |
</p>
|
101 |
)}
|
|
|
|
|
102 |
<button
|
103 |
className={classNames(
|
104 |
"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-1.5 px-5 hover:bg-pink-400 text-white shadow-sm dark:shadow-highlight/20",
|
@@ -111,15 +106,8 @@ const downloadFile = (filename: string, content: string) => {
|
|
111 |
>
|
112 |
{path ? "Update Space" : "Deploy to Space"}
|
113 |
</button>
|
114 |
-
<div className="pt-2 text-right">
|
115 |
-
|
116 |
-
<button
|
117 |
-
className="mt-2 rounded-full bg-gray-800 px-5 py-2 text-white font-semibold text-xs hover:bg-gray-700 transition-all duration-100"
|
118 |
-
onClick={() => downloadFile("index.html", html)}
|
119 |
-
>
|
120 |
-
Download index.html
|
121 |
-
</button>
|
122 |
|
|
|
123 |
<div
|
124 |
className={classNames(
|
125 |
"h-screen w-screen bg-black/20 fixed left-0 top-0 z-10",
|
@@ -129,6 +117,8 @@ const downloadFile = (filename: string, content: string) => {
|
|
129 |
)}
|
130 |
onClick={() => setOpen(false)}
|
131 |
></div>
|
|
|
|
|
132 |
<div
|
133 |
className={classNames(
|
134 |
"absolute top-[calc(100%+8px)] right-0 z-10 w-80 bg-white border border-gray-200 rounded-lg shadow-lg transition-all duration-75 overflow-hidden",
|
@@ -155,7 +145,7 @@ const downloadFile = (filename: string, content: string) => {
|
|
155 |
<main className="px-4 pt-3 pb-4 space-y-3">
|
156 |
<p className="text-xs text-amber-600 bg-amber-500/10 rounded-md p-2">
|
157 |
{path ? (
|
158 |
-
|
159 |
Your space is live at{" "}
|
160 |
<a
|
161 |
href={`https://huggingface.co/spaces/${path}`}
|
@@ -165,7 +155,7 @@ const downloadFile = (filename: string, content: string) => {
|
|
165 |
huggingface.co/{path}
|
166 |
</a>
|
167 |
. You can update it by deploying again.
|
168 |
-
|
169 |
) : (
|
170 |
"Deploy your project to a space on the Hub. Spaces are a way to share your project with the world."
|
171 |
)}
|
@@ -191,10 +181,20 @@ const downloadFile = (filename: string, content: string) => {
|
|
191 |
Your code has errors. Fix them before deploying.
|
192 |
</p>
|
193 |
)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
<div className="pt-2 text-right">
|
195 |
<button
|
196 |
disabled={error || loading || !config.title}
|
197 |
-
className="relative rounded-full bg-black px-5 py-2 text-white font-semibold text-xs hover:bg-black/90 transition-all duration-100 disabled:bg-gray-300 disabled:text-gray-500 disabled:cursor-not-allowed
|
198 |
onClick={createSpace}
|
199 |
>
|
200 |
{path ? "Update Space" : "Create Space"}
|
|
|
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";
|
8 |
import Login from "../login/login";
|
|
|
13 |
Your space is live!
|
14 |
<button
|
15 |
className="bg-black text-sm block text-white rounded-md px-3 py-1.5 hover:bg-gray-900 cursor-pointer"
|
16 |
+
onClick={() => window.open(url, "_blank")}
|
|
|
|
|
17 |
>
|
18 |
See Space
|
19 |
</button>
|
20 |
</div>
|
21 |
);
|
22 |
|
23 |
+
// ✅ DOWNLOAD FUNCTION (no JSZip needed)
|
24 |
+
const downloadFile = (filename: string, content: string) => {
|
25 |
+
const blob = new Blob([content], { type: "text/html" });
|
26 |
+
const url = URL.createObjectURL(blob);
|
27 |
+
const a = document.createElement("a");
|
28 |
+
a.href = url;
|
29 |
+
a.download = filename;
|
30 |
+
a.click();
|
31 |
+
URL.revokeObjectURL(url);
|
32 |
+
};
|
33 |
+
|
34 |
function DeployButton({
|
35 |
html,
|
36 |
error = false,
|
|
|
43 |
const [open, setOpen] = useState(false);
|
44 |
const [loading, setLoading] = useState(false);
|
45 |
const [path, setPath] = useState<string | undefined>(undefined);
|
46 |
+
const [config, setConfig] = useState({ title: "" });
|
|
|
|
|
|
|
47 |
|
48 |
const createSpace = async () => {
|
49 |
setLoading(true);
|
|
|
50 |
try {
|
51 |
const request = await fetch("/api/deploy", {
|
52 |
method: "POST",
|
|
|
78 |
}
|
79 |
};
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
return (
|
82 |
<div className="relative flex items-center justify-end">
|
83 |
{auth && (
|
|
|
92 |
</a>
|
93 |
</p>
|
94 |
)}
|
95 |
+
|
96 |
+
{/* Deploy to Space Button */}
|
97 |
<button
|
98 |
className={classNames(
|
99 |
"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-1.5 px-5 hover:bg-pink-400 text-white shadow-sm dark:shadow-highlight/20",
|
|
|
106 |
>
|
107 |
{path ? "Update Space" : "Deploy to Space"}
|
108 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
+
{/* Pop-up Overlay */}
|
111 |
<div
|
112 |
className={classNames(
|
113 |
"h-screen w-screen bg-black/20 fixed left-0 top-0 z-10",
|
|
|
117 |
)}
|
118 |
onClick={() => setOpen(false)}
|
119 |
></div>
|
120 |
+
|
121 |
+
{/* Pop-up Content */}
|
122 |
<div
|
123 |
className={classNames(
|
124 |
"absolute top-[calc(100%+8px)] right-0 z-10 w-80 bg-white border border-gray-200 rounded-lg shadow-lg transition-all duration-75 overflow-hidden",
|
|
|
145 |
<main className="px-4 pt-3 pb-4 space-y-3">
|
146 |
<p className="text-xs text-amber-600 bg-amber-500/10 rounded-md p-2">
|
147 |
{path ? (
|
148 |
+
<>
|
149 |
Your space is live at{" "}
|
150 |
<a
|
151 |
href={`https://huggingface.co/spaces/${path}`}
|
|
|
155 |
huggingface.co/{path}
|
156 |
</a>
|
157 |
. You can update it by deploying again.
|
158 |
+
</>
|
159 |
) : (
|
160 |
"Deploy your project to a space on the Hub. Spaces are a way to share your project with the world."
|
161 |
)}
|
|
|
181 |
Your code has errors. Fix them before deploying.
|
182 |
</p>
|
183 |
)}
|
184 |
+
|
185 |
+
{/* ✅ DOWNLOAD HTML BUTTON */}
|
186 |
+
<button
|
187 |
+
className="mt-2 rounded-full bg-gray-800 px-5 py-2 text-white font-semibold text-xs hover:bg-gray-700 transition-all duration-100"
|
188 |
+
onClick={() => downloadFile("index.html", html)}
|
189 |
+
>
|
190 |
+
Download index.html
|
191 |
+
</button>
|
192 |
+
|
193 |
+
{/* ✅ CREATE / UPDATE SPACE BUTTON */}
|
194 |
<div className="pt-2 text-right">
|
195 |
<button
|
196 |
disabled={error || loading || !config.title}
|
197 |
+
className="relative rounded-full bg-black px-5 py-2 text-white font-semibold text-xs hover:bg-black/90 transition-all duration-100 disabled:bg-gray-300 disabled:text-gray-500 disabled:cursor-not-allowed"
|
198 |
onClick={createSpace}
|
199 |
>
|
200 |
{path ? "Update Space" : "Create Space"}
|