From 6141e6d1d9c1babe3907e56edbfd2f1c20a34a67 Mon Sep 17 00:00:00 2001 From: Jae Young Ahn Date: Wed, 7 May 2025 13:26:17 -0700 Subject: [PATCH] initial commit --- .env | 4 +- .env.development | 2 +- src/components/EditorPanel.jsx | 13 +- src/components/Navbar.jsx | 64 ++---- src/components/PreviewPanel.jsx | 200 ++++++++--------- src/pages/AssignmentPage.jsx | 385 ++++++++++++++++++++++++-------- src/pages/CodeEditor.jsx | 265 +++++++++------------- src/pages/SignIn.jsx | 14 +- src/scss/page/_login.scss | 2 +- 9 files changed, 521 insertions(+), 428 deletions(-) diff --git a/.env b/.env index ddf3a43..d44cade 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ -#VITE_AUTH_URL="http://localhost:8080" -VITE_AUTH_URL="https://byte-camp-auth-service.fly.dev" \ No newline at end of file +VITE_AUTH_URL="https://byte-camp-auth-service.fly.dev" +VITE_ASSIGNMENT_URL="http://assignment-service.internal" \ No newline at end of file diff --git a/.env.development b/.env.development index 7dc9c2c..7affb16 100644 --- a/.env.development +++ b/.env.development @@ -1,2 +1,2 @@ VITE_AUTH_URL="http://localhost:8080" -#VITE_AUTH_URL="https://byte-camp-auth-service.fly.dev" \ No newline at end of file +VITE_ASSIGNMENT_URL="http://localhost:8082" \ No newline at end of file diff --git a/src/components/EditorPanel.jsx b/src/components/EditorPanel.jsx index fadcc5d..d96b02e 100644 --- a/src/components/EditorPanel.jsx +++ b/src/components/EditorPanel.jsx @@ -4,12 +4,13 @@ import Editor from '@monaco-editor/react'; export default function EditorPanel({ code, onChange }) { return (
onChange(v || '')} theme="vs-dark" options={{ - fontSize: 16, + fontSize: 20, padding: { top: 10, bottom: 10 }, minimap: { enabled: false }, scrollbar: { - verticalScrollbarSize: 8, - horizontalScrollbarSize: 8, + verticalScrollbarSize: 12, + horizontalScrollbarSize: 12 }, lineNumbers: 'on', - scrollBeyondLastLine: false, + scrollBeyondLastLine: false }} />
diff --git a/src/components/Navbar.jsx b/src/components/Navbar.jsx index 537cb27..3d39611 100644 --- a/src/components/Navbar.jsx +++ b/src/components/Navbar.jsx @@ -14,7 +14,7 @@ const Navbar = () => { async function handleLogout() { window.open(`${authUrl}/auth/logout`, "_self"); - }; + } useEffect(() => { // Set active link based on current path @@ -114,32 +114,21 @@ const Navbar = () => { - {/* will be decided later of we shall keep NOTEBOOK or not */} - {/*
  • - - 📓 - - NOTEBOOK - - -
  • */} -
  • - - 🎯 - ASSIGNMENT - - -
  • + {user && user.role === "instructor" && ( +
  • + + 🎯 + ASSIGNMENT + + +
  • + )} + {user && user.role === "student" && (
  • {
  • + )}
  • {user ? ( { ); }; -export default Navbar; -//{user ? user.displayName : "NOTEBOOK"} - -//server side logout (was not working properly, so implemented client side logout) -// const handleLogout = async () => { -// try { -// const res = await fetch("http://localhost:8080/auth/logout", { -// method: "GET", -// credentials: "include", -// }); - -// if (res.ok) { -// setUser(null); -// } else { -// console.error("Logout failed"); -// } -// } catch (error) { -// console.error("Error during logout:", error); -// } +export default Navbar; \ No newline at end of file diff --git a/src/components/PreviewPanel.jsx b/src/components/PreviewPanel.jsx index f94a471..3e66bd7 100644 --- a/src/components/PreviewPanel.jsx +++ b/src/components/PreviewPanel.jsx @@ -2,140 +2,120 @@ import React, { useState } from 'react'; export default function PreviewPanel({ code }) { const [gameUrl, setGameUrl] = useState(''); - const [snakeApiUrl, setSnakeApiUrl] = useState(''); const [settings, setSettings] = useState(null); - const [moveRes, setMoveRes] = useState(null); const [loadingSetup, setLoadingSetup] = useState(false); - const [loadingMove, setLoadingMove] = useState(false); - - const fetchSetup = async (e) => { - e.preventDefault(); - setLoadingSetup(true); - try { - const res = await fetch( - `/api/fetch-board?url=${encodeURIComponent(gameUrl.trim())}` - ); - setSettings(await res.json()); - setMoveRes(null); - } catch (err) { - console.error(err); - } - setLoadingSetup(false); - }; - - const testMove = async (e) => { - e.preventDefault(); - if (!settings) return; - setLoadingMove(true); + const fetchBoard = async () => { + if (!gameUrl.trim()) return; + setLoadingSetup(true); try { - const res = await fetch('/api/move', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ code, boardState: settings }) - }); - setMoveRes(await res.json()); + const res = await fetch( + `/api/fetch-board?url=${encodeURIComponent(gameUrl.trim())}` + ); + if (!res.ok) throw new Error('Fetch board failed'); + setSettings(await res.json()); } catch (err) { console.error(err); + } finally { + setLoadingSetup(false); } - setLoadingMove(false); }; const gameId = gameUrl.trim().split('/').pop(); return ( -
    -

    Battlesnake Preview

    +
    +
    +

    + 🎯 Live Arena Output +

    - {/* game board URL */} -
    +
    setGameUrl(e.target.value)} - style={{ flex: 1 }} + onChange={e => setGameUrl(e.target.value)} + style={{ + width: '100%', + padding: '0.5rem', + marginBottom: '0.75rem', + border: 'none', + borderRadius: 4, + background: 'transparent', + color: '#fff', + outline: 'none' + }} /> - - - - {/* API server URL */} -
    - setSnakeApiUrl(e.target.value)} - style={{ flex: 1 }} - /> - -
    - - {/* Test Move */} -
    -
    - {settings && gameId && ( -
    + {/*
    +
    */} + +
    + {settings && gameId && (