2025-04-17 10:10:04 -07:00
|
|
|
import { useEffect, useState } from "react";
|
2025-04-28 12:13:10 -07:00
|
|
|
import EditorPanel from "../components/EditorPanel";
|
2025-05-05 12:22:50 -07:00
|
|
|
import PreviewPanel from "../components/PreviewPanel";
|
2025-04-17 10:10:04 -07:00
|
|
|
|
|
|
|
|
const PageCodeEditor = () => {
|
2025-05-05 10:05:48 -07:00
|
|
|
const [code, setCode] = useState(
|
|
|
|
|
`# NOW LOADING`
|
|
|
|
|
);
|
|
|
|
|
const appName = "snakeapi-demo-001";
|
2025-04-28 12:13:10 -07:00
|
|
|
|
2025-04-17 10:10:04 -07:00
|
|
|
useEffect(() => {
|
2025-05-02 09:29:18 -07:00
|
|
|
document.title = "Snake Brain Editor";
|
2025-05-05 10:05:48 -07:00
|
|
|
|
|
|
|
|
fetch(`https://assignment-service.fly.dev/notebook/${appName}`)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
if (!res.ok) throw new Error("Network response was not ok");
|
|
|
|
|
return res.json();
|
|
|
|
|
})
|
|
|
|
|
.then((notebook) => {
|
|
|
|
|
// extract code cell sources and join them
|
|
|
|
|
const combined = notebook.cells
|
|
|
|
|
.filter((cell) => cell.cell_type === "code")
|
|
|
|
|
.map((cell) => cell.source.join(""))
|
|
|
|
|
.join("\n\n");
|
|
|
|
|
setCode(combined);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => console.error("Failed to fetch notebook:", err));
|
2025-04-17 10:10:04 -07:00
|
|
|
}, []);
|
|
|
|
|
|
2025-05-02 09:29:18 -07:00
|
|
|
return (
|
2025-05-05 10:05:48 -07:00
|
|
|
<main className="code-editor-page" style={{ paddingTop: "70px" }}>
|
2025-05-02 09:29:18 -07:00
|
|
|
<div
|
|
|
|
|
className="editor-page-layout"
|
|
|
|
|
style={{
|
2025-05-05 10:05:48 -07:00
|
|
|
display: "flex",
|
|
|
|
|
gap: "2rem",
|
|
|
|
|
padding: "2rem",
|
2025-05-02 09:29:18 -07:00
|
|
|
fontFamily: "'Fira Code', 'Courier New', monospace",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{/* python editor */}
|
|
|
|
|
<div
|
|
|
|
|
className="box-panel"
|
|
|
|
|
style={{
|
|
|
|
|
flex: 2,
|
2025-05-05 10:05:48 -07:00
|
|
|
background: "linear-gradient(145deg, #0d0221, #1a1a1a)",
|
|
|
|
|
borderRadius: "12px",
|
|
|
|
|
padding: "1rem",
|
|
|
|
|
color: "#eee",
|
|
|
|
|
minHeight: "80vh",
|
|
|
|
|
overflow: "auto",
|
2025-05-02 09:29:18 -07:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<h3
|
|
|
|
|
className="panel-heading"
|
|
|
|
|
style={{
|
2025-05-05 10:05:48 -07:00
|
|
|
fontSize: "1.2rem",
|
|
|
|
|
color: "#05d9e8",
|
|
|
|
|
textShadow: "0 0 5px #05d9e8",
|
|
|
|
|
marginBottom: "1rem",
|
2025-05-02 09:29:18 -07:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
🐍 Snake Brain (Python)
|
|
|
|
|
</h3>
|
|
|
|
|
<EditorPanel code={code} onChange={setCode} />
|
|
|
|
|
</div>
|
2025-04-17 10:10:04 -07:00
|
|
|
|
2025-05-05 12:22:50 -07:00
|
|
|
{/* <div className="preview-section">
|
|
|
|
|
<PreviewPanel code={code} />
|
|
|
|
|
</div> */}
|
|
|
|
|
|
|
|
|
|
|
2025-05-02 09:29:18 -07:00
|
|
|
{/* live arena */}
|
|
|
|
|
<div
|
|
|
|
|
className="box-panel"
|
|
|
|
|
style={{
|
|
|
|
|
flex: 1,
|
2025-05-05 10:05:48 -07:00
|
|
|
background: "#1a1a1a",
|
|
|
|
|
borderRadius: "12px",
|
|
|
|
|
padding: "1rem",
|
|
|
|
|
color: "#eee",
|
|
|
|
|
minHeight: "80vh",
|
2025-05-02 09:29:18 -07:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<h3
|
|
|
|
|
style={{
|
2025-05-05 10:05:48 -07:00
|
|
|
fontSize: "1.2rem",
|
|
|
|
|
color: "#d300c5",
|
|
|
|
|
textShadow: "0 0 5px #d300c5",
|
|
|
|
|
marginBottom: "1rem",
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
gap: "0.5rem",
|
2025-05-02 09:29:18 -07:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
🎯 Live Arena Output
|
|
|
|
|
</h3>
|
2025-04-28 12:13:10 -07:00
|
|
|
|
2025-05-05 10:05:48 -07:00
|
|
|
<h4 style={{ color: "#fff", textAlign: "center", marginBottom: "1rem" }}>
|
2025-05-02 09:29:18 -07:00
|
|
|
Battlesnake Preview
|
|
|
|
|
</h4>
|
2025-04-28 12:13:10 -07:00
|
|
|
|
2025-05-05 10:05:48 -07:00
|
|
|
{/* game url */}
|
2025-05-02 09:29:18 -07:00
|
|
|
<div
|
|
|
|
|
style={{
|
2025-05-05 10:05:48 -07:00
|
|
|
background: "rgba(255,255,255,0.05)",
|
|
|
|
|
borderRadius: "8px",
|
|
|
|
|
padding: "1rem",
|
|
|
|
|
marginBottom: "1rem",
|
|
|
|
|
textAlign: "center",
|
2025-05-02 09:29:18 -07:00
|
|
|
}}
|
2025-04-17 10:10:04 -07:00
|
|
|
>
|
2025-05-02 09:29:18 -07:00
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
placeholder="Game URL"
|
|
|
|
|
style={{
|
2025-05-05 10:05:48 -07:00
|
|
|
background: "transparent",
|
|
|
|
|
border: "none",
|
|
|
|
|
color: "#fff",
|
|
|
|
|
width: "100%",
|
|
|
|
|
textAlign: "center",
|
2025-05-02 09:29:18 -07:00
|
|
|
fontFamily: "'Fira Code', monospace",
|
2025-05-05 10:05:48 -07:00
|
|
|
outline: "none",
|
2025-05-02 09:29:18 -07:00
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<button
|
|
|
|
|
style={{
|
2025-05-05 10:05:48 -07:00
|
|
|
backgroundColor: "#ff2a6d",
|
|
|
|
|
color: "#fff",
|
|
|
|
|
padding: "0.5rem 1rem",
|
|
|
|
|
border: "none",
|
|
|
|
|
borderRadius: "20px",
|
|
|
|
|
marginTop: "0.5rem",
|
|
|
|
|
cursor: "pointer",
|
|
|
|
|
width: "100%",
|
|
|
|
|
fontWeight: "bold",
|
2025-05-02 09:29:18 -07:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
FETCH BOARD
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* test move button */}
|
|
|
|
|
<div
|
|
|
|
|
style={{
|
2025-05-05 10:05:48 -07:00
|
|
|
display: "flex",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
marginTop: "2rem",
|
2025-05-02 09:29:18 -07:00
|
|
|
}}
|
2025-04-17 10:10:04 -07:00
|
|
|
>
|
2025-05-02 09:29:18 -07:00
|
|
|
<button
|
|
|
|
|
style={{
|
2025-05-05 10:05:48 -07:00
|
|
|
backgroundColor: "#ff2a6d",
|
|
|
|
|
color: "#fff",
|
|
|
|
|
padding: "0.5rem 2rem",
|
|
|
|
|
border: "none",
|
|
|
|
|
borderRadius: "20px",
|
|
|
|
|
fontWeight: "bold",
|
|
|
|
|
cursor: "pointer",
|
2025-05-02 09:29:18 -07:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
TEST MOVE
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2025-04-17 10:10:04 -07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</main>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default PageCodeEditor;
|