added deploy button functionality
This commit is contained in:
parent
b477252e5f
commit
f6f697c438
2 changed files with 29 additions and 4 deletions
|
|
@ -8,7 +8,7 @@ export default function EditorPanel({ code, onChange }) {
|
||||||
border: '1px solid #444',
|
border: '1px solid #444',
|
||||||
borderRadius: '8px',
|
borderRadius: '8px',
|
||||||
backgroundColor: '#1e1e1e',
|
backgroundColor: '#1e1e1e',
|
||||||
height: '90%',
|
height: '80%',
|
||||||
boxShadow: '0 0 10px rgba(255, 0, 255, 0.2)',
|
boxShadow: '0 0 10px rgba(255, 0, 255, 0.2)',
|
||||||
overflow: 'hidden'
|
overflow: 'hidden'
|
||||||
}}>
|
}}>
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,12 @@ const ASSIGNMENT_BASE = "http://localhost:8082";
|
||||||
|
|
||||||
export default function PageCodeEditor() {
|
export default function PageCodeEditor() {
|
||||||
const { qrCodeNumber: routeId } = useParams();
|
const { qrCodeNumber: routeId } = useParams();
|
||||||
const qrCodeNumber = routeId || "6656";
|
const qrCodeNumber = routeId;
|
||||||
|
|
||||||
const [appName, setAppName] = useState("");
|
const [appName, setAppName] = useState("");
|
||||||
const [code, setCode] = useState("# NOW LOADING");
|
const [code, setCode] = useState("# NOW LOADING");
|
||||||
const [isSaving, setIsSaving] = useState(false);
|
const [isSaving, setIsSaving] = useState(false);
|
||||||
|
const [isDeploying, setIsDeploying] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
document.title = "Snake Brain Editor";
|
document.title = "Snake Brain Editor";
|
||||||
|
|
@ -63,6 +64,25 @@ export default function PageCodeEditor() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleDeploy = async () => {
|
||||||
|
if (isDeploying) return;
|
||||||
|
setIsDeploying(true);
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${ASSIGNMENT_BASE}/student/restart`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ appName })
|
||||||
|
});
|
||||||
|
if (!res.ok) throw new Error("Restart failed");
|
||||||
|
alert("App restarted");
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Restart error:", err);
|
||||||
|
alert(`Restart error: ${err.message}`);
|
||||||
|
} finally {
|
||||||
|
setIsDeploying(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="code-editor-page" style={{ paddingTop: "35px" }}>
|
<main className="code-editor-page" style={{ paddingTop: "35px" }}>
|
||||||
<div
|
<div
|
||||||
|
|
@ -107,6 +127,7 @@ export default function PageCodeEditor() {
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: "#ff2a6d",
|
backgroundColor: "#ff2a6d",
|
||||||
color: "#fff",
|
color: "#fff",
|
||||||
|
marginLeft: "50rem",
|
||||||
padding: "0.5rem 2rem",
|
padding: "0.5rem 2rem",
|
||||||
border: "none",
|
border: "none",
|
||||||
borderRadius: "20px",
|
borderRadius: "20px",
|
||||||
|
|
@ -116,7 +137,11 @@ export default function PageCodeEditor() {
|
||||||
>
|
>
|
||||||
{isSaving ? "Saving..." : "Save"}
|
{isSaving ? "Saving..." : "Save"}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
|
||||||
<button
|
<button
|
||||||
|
onClick={handleDeploy}
|
||||||
|
disabled={isDeploying}
|
||||||
style={{
|
style={{
|
||||||
marginLeft: "1rem",
|
marginLeft: "1rem",
|
||||||
backgroundColor: "#ff2a6d",
|
backgroundColor: "#ff2a6d",
|
||||||
|
|
@ -125,10 +150,10 @@ export default function PageCodeEditor() {
|
||||||
border: "none",
|
border: "none",
|
||||||
borderRadius: "20px",
|
borderRadius: "20px",
|
||||||
fontWeight: "bold",
|
fontWeight: "bold",
|
||||||
cursor: "pointer"
|
cursor: isDeploying ? "not-allowed" : "pointer"
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Deploy
|
{isDeploying ? "Deploying..." : "Deploy"}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue