more bug fixes, fix to run on fly.io

This commit is contained in:
JBB0807 2025-05-20 17:03:56 -07:00
parent 42188f5c37
commit c76437057f
3 changed files with 31 additions and 23 deletions

View file

@ -4,7 +4,7 @@
"version": "0.0.0", "version": "0.0.0",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite --mode development",
"build": "vite build", "build": "vite build",
"lint": "eslint .", "lint": "eslint .",
"preview": "vite preview" "preview": "vite preview"

View file

@ -19,7 +19,7 @@ const AssignmentPage = () => {
const [user, setUser] = useState([]); const [user, setUser] = useState([]);
const VITE_ASSIGNMENT_URL = import.meta.env.VITE_ASSIGNMENT_URL; const ASSIGNMENT_BASE = import.meta.env.VITE_ASSIGNMENT_URL;
const authUrl = import.meta.env.VITE_AUTH_URL; const authUrl = import.meta.env.VITE_AUTH_URL;
const [searchTerm, setSearchTerm] = useState(""); const [searchTerm, setSearchTerm] = useState("");
const [showPassword, setShowPassword] = useState(false); const [showPassword, setShowPassword] = useState(false);
@ -36,7 +36,7 @@ const AssignmentPage = () => {
if (!appName) return; // Don't alert for empty name if (!appName) return; // Don't alert for empty name
const timer = setTimeout(() => { const timer = setTimeout(() => {
fetch( fetch(
`${VITE_ASSIGNMENT_URL}/instructor/checkAssignmentByAppName/${appName}` `${ASSIGNMENT_BASE}/instructor/checkAssignmentByAppName/${appName}`
) )
.then((response) => { .then((response) => {
if (!response.ok) { if (!response.ok) {
@ -64,7 +64,7 @@ const AssignmentPage = () => {
console.log("Checking QR code number:", qrCodeNumber); // Added console log console.log("Checking QR code number:", qrCodeNumber); // Added console log
const timer = setTimeout(() => { const timer = setTimeout(() => {
fetch( fetch(
`${VITE_ASSIGNMENT_URL}/instructor/checkAssignmentByQRCode/${qrCodeNumber}` `${ASSIGNMENT_BASE}/instructor/checkAssignmentByQRCode/${qrCodeNumber}`
) )
.then((response) => { .then((response) => {
if (!response.ok) { if (!response.ok) {
@ -98,7 +98,7 @@ const AssignmentPage = () => {
console.log("User:", user); console.log("User:", user);
const res = await fetch( const res = await fetch(
`${VITE_ASSIGNMENT_URL}/instructor/list/${user.userId}`, `${ASSIGNMENT_BASE}/instructor/list/${user.userId}`,
{ {
method: "GET", method: "GET",
} }
@ -156,7 +156,7 @@ const AssignmentPage = () => {
if (editingIndex !== null) { if (editingIndex !== null) {
//edit mode //edit mode
await fetch(`${VITE_ASSIGNMENT_URL}/instructor/update/${assignmentId}`, { await fetch(`${ASSIGNMENT_BASE}/instructor/update/${assignmentId}`, {
method: "PUT", method: "PUT",
body: formData, body: formData,
}) })
@ -185,7 +185,7 @@ const AssignmentPage = () => {
throw new Error("Failed to submit assignment: file not found."); throw new Error("Failed to submit assignment: file not found.");
} }
await fetch(`${VITE_ASSIGNMENT_URL}/instructor/create`, { await fetch(`${ASSIGNMENT_BASE}/instructor/create`, {
method: "POST", method: "POST",
body: formData, body: formData,
}) })
@ -234,7 +234,7 @@ const AssignmentPage = () => {
const project = projects[index]; const project = projects[index];
if (window.confirm("Are you sure you want to delete this assignment?")) { if (window.confirm("Are you sure you want to delete this assignment?")) {
fetch( fetch(
`${VITE_ASSIGNMENT_URL}/instructor/delete/${project.assignmentid}`, `${ASSIGNMENT_BASE}/instructor/delete/${project.assignmentid}`,
{ {
method: "DELETE", method: "DELETE",
} }

View file

@ -3,10 +3,9 @@ import { useLocation } from "react-router-dom";
import EditorPanel from "../components/EditorPanel"; import EditorPanel from "../components/EditorPanel";
import PreviewPanel from "../components/PreviewPanel"; import PreviewPanel from "../components/PreviewPanel";
const ASSIGNMENT_BASE = "http://localhost:8082"; const ASSIGNMENT_BASE = import.meta.env.VITE_ASSIGNMENT_URL;
export default function PageCodeEditor() { export default function PageCodeEditor() {
const location = useLocation(); const location = useLocation();
const qrCodeNumber = location.state?.qrCodeNumber; const qrCodeNumber = location.state?.qrCodeNumber;
@ -55,7 +54,7 @@ export default function PageCodeEditor() {
const res = await fetch(`${ASSIGNMENT_BASE}/student/save`, { const res = await fetch(`${ASSIGNMENT_BASE}/student/save`, {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ appName, code }) body: JSON.stringify({ appName, code }),
}); });
if (!res.ok) throw new Error("Save failed"); if (!res.ok) throw new Error("Save failed");
alert("Notebook saved"); alert("Notebook saved");
@ -74,7 +73,7 @@ export default function PageCodeEditor() {
const res = await fetch(`${ASSIGNMENT_BASE}/student/restart`, { const res = await fetch(`${ASSIGNMENT_BASE}/student/restart`, {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ appName }) body: JSON.stringify({ appName }),
}); });
if (!res.ok) throw new Error("Restart failed"); if (!res.ok) throw new Error("Restart failed");
alert("App restarted"); alert("App restarted");
@ -87,16 +86,19 @@ export default function PageCodeEditor() {
}; };
return ( return (
<main className="code-editor-page" style={{ paddingTop: "35px", width: "100vw" }}> <main
className="code-editor-page"
style={{ paddingTop: "35px", width: "100vw" }}
>
<div <div
className="editor-page-layout" className="editor-page-layout"
style={{ style={{
display: "grid", display: "grid",
gridTemplateColumns: '1fr 0.8fr', gridTemplateColumns: "1fr 0.8fr",
//gap: "1rem", //gap: "1rem",
width: "100%", width: "100%",
padding: "1rem", padding: "1rem",
fontFamily: "'Fira Code', 'Courier New', monospace" fontFamily: "'Fira Code', 'Courier New', monospace",
}} }}
> >
{/* Python Editor */} {/* Python Editor */}
@ -118,13 +120,20 @@ export default function PageCodeEditor() {
fontSize: "1.2rem", fontSize: "1.2rem",
color: "#05d9e8", color: "#05d9e8",
textShadow: "0 0 5px #05d9e8", textShadow: "0 0 5px #05d9e8",
marginBottom: "1rem" marginBottom: "1rem",
}} }}
> >
🐍 Snake Brain (Python) 🐍 Snake Brain (Python)
</h3> </h3>
<EditorPanel code={code} onChange={setCode} /> <EditorPanel code={code} onChange={setCode} />
<div style={{ marginTop: "1rem", display: "flex", flexDirection: "row", justifyContent: "center" }}> <div
style={{
marginTop: "1rem",
display: "flex",
flexDirection: "row",
justifyContent: "center",
}}
>
<button <button
onClick={handleSave} onClick={handleSave}
disabled={isSaving} disabled={isSaving}
@ -135,13 +144,12 @@ export default function PageCodeEditor() {
border: "none", border: "none",
borderRadius: "20px", borderRadius: "20px",
fontWeight: "bold", fontWeight: "bold",
cursor: isSaving ? "not-allowed" : "pointer" cursor: isSaving ? "not-allowed" : "pointer",
}} }}
> >
{isSaving ? "Saving..." : "Save"} {isSaving ? "Saving..." : "Save"}
</button> </button>
<button <button
onClick={handleDeploy} onClick={handleDeploy}
disabled={isDeploying} disabled={isDeploying}
@ -153,7 +161,7 @@ export default function PageCodeEditor() {
border: "none", border: "none",
borderRadius: "20px", borderRadius: "20px",
fontWeight: "bold", fontWeight: "bold",
cursor: isDeploying ? "not-allowed" : "pointer" cursor: isDeploying ? "not-allowed" : "pointer",
}} }}
> >
{isDeploying ? "Deploying..." : "Deploy"} {isDeploying ? "Deploying..." : "Deploy"}
@ -170,7 +178,7 @@ export default function PageCodeEditor() {
borderRadius: "12px", borderRadius: "12px",
padding: "0.8rem", padding: "0.8rem",
color: "#eee", color: "#eee",
minHeight: "20vh" minHeight: "20vh",
}} }}
> >
<h3 <h3
@ -181,7 +189,7 @@ export default function PageCodeEditor() {
marginBottom: "0.8rem", marginBottom: "0.8rem",
display: "flex", display: "flex",
alignItems: "center", alignItems: "center",
gap: "0.8rem" gap: "0.8rem",
}} }}
> >
🎯 Live Arena Output 🎯 Live Arena Output
@ -190,7 +198,7 @@ export default function PageCodeEditor() {
style={{ style={{
color: "#fff", color: "#fff",
textAlign: "center", textAlign: "center",
marginBottom: "0.8rem" marginBottom: "0.8rem",
}} }}
> >
Battlesnake Preview Battlesnake Preview