Merge remote-tracking branch

This commit is contained in:
Anton Kupriianov 2025-05-07 13:10:14 -07:00
commit dd9b9c4ad6
7 changed files with 320 additions and 135 deletions

4
.env
View file

@ -1,2 +1,2 @@
VITE_AUTH_URL="http://localhost:8080/auth/google" #VITE_AUTH_URL="http://localhost:8080"
#VITE_AUTH_URL="https://byte-camp-auth-service.fly.dev/auth/google" VITE_AUTH_URL="https://byte-camp-auth-service.fly.dev"

2
.env.development Normal file
View file

@ -0,0 +1,2 @@
VITE_AUTH_URL="http://localhost:8080"
#VITE_AUTH_URL="https://byte-camp-auth-service.fly.dev"

View file

@ -1,7 +1,9 @@
import React, { useState, useEffect, useRef } from "react"; import React, { useState, useEffect, useRef } from "react";
import "../scss/styles.scss"; import "../scss/styles.scss";
import "../scss/components/_navbar.scss"; import "../scss/components/_navbar.scss";
import { Link, useNavigate } from "react-router-dom"; import { Link } from "react-router-dom";
const authUrl = import.meta.env.VITE_AUTH_URL;
// Using URL reference for ByteCamp logo // Using URL reference for ByteCamp logo
const bytecampLogo = "/images/bytecamp.png"; const bytecampLogo = "/images/bytecamp.png";
@ -12,23 +14,9 @@ const Navbar = () => {
const [user, setUser] = useState(null); const [user, setUser] = useState(null);
const [menuOpen, setMenuOpen] = useState(false); const [menuOpen, setMenuOpen] = useState(false);
const menuRef = useRef(null); const menuRef = useRef(null);
const navigate = useNavigate();
const handleLogout = () => { async function handleLogout() {
// Implement client-side logout without calling the backend window.open(`${authUrl}/auth/logout`, "_self");
// This clears the user state in the frontend
setUser(null);
// Clear any authentication cookies if they exist
document.cookie.split(";").forEach((cookie) => {
const [name] = cookie.trim().split("=");
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
});
// Redirect to home page
navigate("/");
console.log("Logged out successfully");
}; };
useEffect(() => { useEffect(() => {
@ -54,7 +42,7 @@ const Navbar = () => {
document.addEventListener("mousedown", handleClickOutside); document.addEventListener("mousedown", handleClickOutside);
async function fetchUser() { async function fetchUser() {
const res = await fetch("http://localhost:8080/auth/current_user", { const res = await fetch(`${authUrl}/auth/current_user`, {
credentials: "include", // very important credentials: "include", // very important
}); });
if (res.ok) { if (res.ok) {

View file

@ -1,4 +1,4 @@
import React, { useState } from "react"; import React, { useState, useEffect } from "react";
import "../scss/components/_assignment.scss"; import "../scss/components/_assignment.scss";
const AssignmentPage = () => { const AssignmentPage = () => {
@ -13,6 +13,32 @@ const AssignmentPage = () => {
const [showModal, setShowModal] = useState(false); const [showModal, setShowModal] = useState(false);
const [editingIndex, setEditingIndex] = useState(null); const [editingIndex, setEditingIndex] = useState(null);
useEffect(() => {
document.title = "Assignment";
fetchAssignments();
}, []);
const fetchAssignments = async () => {
try {
const res = await fetch("http://localhost:8082/instructor/list/9", {
// credentials: "include",
});
if (!res.ok) throw new Error("Failed to fetch");
const data = await res.json();
// Optional: Remove duplicate assignment IDs if needed
const unique = Array.from(
new Map(data.map((item) => [item.assignmentid, item])).values()
);
setProjects(unique);
} catch (error) {
console.error("Error fetching assignments:", error);
}
};
const resetForm = () => { const resetForm = () => {
setStudentName(""); setStudentName("");
setCampID(""); setCampID("");
@ -28,21 +54,19 @@ const AssignmentPage = () => {
e.preventDefault(); e.preventDefault();
const newProject = { const newProject = {
studentName, studentname: studentName,
campID, campid: campID,
programID, programid: programID,
title, title,
description, description,
fileName: file ? file.name : null, fileName: file ? file.name : null,
}; };
if (editingIndex !== null) { if (editingIndex !== null) {
// Edit mode: update the project at the index
const updatedProjects = [...projects]; const updatedProjects = [...projects];
updatedProjects[editingIndex] = newProject; updatedProjects[editingIndex] = newProject;
setProjects(updatedProjects); setProjects(updatedProjects);
} else { } else {
// New submission
setProjects([...projects, newProject]); setProjects([...projects, newProject]);
} }
@ -53,12 +77,12 @@ const AssignmentPage = () => {
const handleEdit = (index) => { const handleEdit = (index) => {
const project = projects[index]; const project = projects[index];
setStudentName(project.studentName); setStudentName(project.studentname || project.studentName || "");
setCampID(project.campID); setCampID(project.campid || project.campID || "");
setProgramID(project.programID); setProgramID(project.programid || project.programID || "");
setTitle(project.title); setTitle(project.title || "");
setDescription(project.description); setDescription(project.description || "");
setFile(null); // File can't be set again for editing, usually. You could add note about this. setFile(null);
setEditingIndex(index); setEditingIndex(index);
setShowModal(true); setShowModal(true);
}; };
@ -70,8 +94,10 @@ const AssignmentPage = () => {
return ( return (
<div className="assignment-page"> <div className="assignment-page">
<h2>📘 Assignments</h2> <div className="assignment-header-box">
<button onClick={() => { resetForm(); setShowModal(true); }}> Add New</button> <h2>Assignments</h2>
<button onClick={() => { resetForm(); setShowModal(true); }}> Add New</button>
</div>
{showModal && ( {showModal && (
<div className="modal-overlay"> <div className="modal-overlay">
@ -80,110 +106,83 @@ const AssignmentPage = () => {
<form onSubmit={handleSubmit}> <form onSubmit={handleSubmit}>
<div> <div>
<label>Student Name</label> <label>Student Name</label>
<input <input type="text" value={studentName} onChange={(e) => setStudentName(e.target.value)} required />
type="text"
value={studentName}
onChange={(e) => setStudentName(e.target.value)}
required
/>
</div> </div>
<div> <div>
<label>Camp ID</label> <label>Camp ID</label>
<input <input type="text" value={campID} onChange={(e) => setCampID(e.target.value)} required />
type="text"
value={campID}
onChange={(e) => setCampID(e.target.value)}
required
/>
</div> </div>
<div> <div>
<label>Program ID</label> <label>Program ID</label>
<input <input type="text" value={programID} onChange={(e) => setProgramID(e.target.value)} required />
type="text"
value={programID}
onChange={(e) => setProgramID(e.target.value)}
required
/>
</div> </div>
<div> <div>
<label>Password</label> <label>Password</label>
<input <input type="password" value={password} onChange={(e) => setPassword(e.target.value)} required />
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
/>
</div> </div>
<div> <div>
<label>Assignment Title</label> <label>Assignment Title</label>
<input <input type="text" value={title} onChange={(e) => setTitle(e.target.value)} required />
type="text"
value={title}
onChange={(e) => setTitle(e.target.value)}
required
/>
</div> </div>
<div> <div>
<label>Description</label> <label>Description</label>
<textarea <textarea value={description} onChange={(e) => setDescription(e.target.value)} required></textarea>
value={description}
onChange={(e) => setDescription(e.target.value)}
required
></textarea>
</div> </div>
<div> <div>
<label>File Upload (optional)</label> <label>File Upload (optional)</label>
<input <input type="file" onChange={(e) => setFile(e.target.files[0])} />
type="file"
onChange={(e) => setFile(e.target.files[0])}
/>
</div> </div>
<div className="modal-buttons"> <div className="modal-buttons">
<button type="submit">{editingIndex !== null ? "Update" : "Submit"}</button> <button type="submit">{editingIndex !== null ? "Update" : "Submit"}</button>
<button <button type="button" onClick={() => { resetForm(); setShowModal(false); }}>Cancel</button>
type="button"
onClick={() => {
resetForm();
setShowModal(false);
}}
>
Cancel
</button>
</div> </div>
</form> </form>
</div> </div>
</div> </div>
)} )}
<div className="project-list"> {projects.length > 0 && (
<h3>📋 Projects</h3> <div className="project-list">
{projects.map((project, index) => ( {projects.map((project, index) => (
<div key={index} className="project-item"> <div key={index} className="project-item">
<div className="project-meta"> <div className="project-meta">
<strong>Student Name: {project.studentName}</strong> | CampID: {project.campID} | ProgramID: {project.programID} <strong>Student Name:</strong> {project.studentname || project.studentName} |{" "}
</div> <strong>CampID:</strong> {project.campid || project.campID} |{" "}
<h4>{project.title}</h4> <strong>ProgramID:</strong> {project.programid || project.programID}
<p>{project.description}</p> </div>
{project.fileName && (
<p><strong>Uploaded File:</strong> {project.fileName}</p> {project.title && <h4>{project.title}</h4>}
{project.description && <p>{project.description}</p>}
{project.fileName && <p><strong>Uploaded File:</strong> {project.fileName}</p>}
{project.assignmenturl && (
<p>
<a href={project.assignmenturl} target="_blank" rel="noopener noreferrer">View Assignment</a>
</p>
)}
{project.originalfile && (
<p>
<a href={project.originalfile} target="_blank" rel="noopener noreferrer">Original File</a> |{" "}
<a href={project.editablefile} target="_blank" rel="noopener noreferrer">Editable File</a>
</p>
)}
<div className="action-buttons">
<button onClick={() => handleEdit(index)}> Edit</button>
<button onClick={() => handleDelete(index)}>🗑 Delete</button>
<button onClick={() => alert("QR feature coming soon!")}>📎 QR</button>
</div>
</div>
))}
</div>
)} )}
<div className="action-buttons">
<button onClick={() => handleEdit(index)}> Edit</button>
<button onClick={() => handleDelete(index)}>🗑 Delete</button>
<button onClick={() => alert("QR feature coming soon!")}>📎 QR</button>
</div>
</div>
))}
</div>
</div> </div>
); );
}; };

View file

@ -1,9 +1,11 @@
import React from "react"; import React from "react";
import "@fortawesome/fontawesome-free/css/all.min.css"; import "@fortawesome/fontawesome-free/css/all.min.css";
const authUrl = import.meta.env.VITE_AUTH_URL;
function SignInForm() { function SignInForm() {
const [state, setState] = React.useState({ const [state, setState] = React.useState({
email: "", assignmentID: "",
password: "", password: "",
}); });
const handleChange = (evt) => { const handleChange = (evt) => {
@ -17,15 +19,33 @@ function SignInForm() {
const handleOnSubmit = (evt) => { const handleOnSubmit = (evt) => {
evt.preventDefault(); evt.preventDefault();
const { email, password } = state; const { assignmentId, password } = state;
alert(`You are login with email: ${email} and password: ${password}`); console.log(`You are loggind in with email: ${assignmentId} and password: ${password}`);
for (const key in state) { console.log("Submitting login request with state:", state);
setState({ fetch(`${authUrl}/auth/student/login`, {
...state, method: "POST",
[key]: "", headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(state),
credentials: "include",
})
.then((response) => {
console.log("Received response:", response);
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
})
.then((data) => {
console.log("Success:", data);
window.location.href = "/";
})
.catch((error) => {
console.error("Error occurred during login:", error);
alert("Login failed!");
}); });
}
}; };
return ( return (
@ -39,10 +59,10 @@ function SignInForm() {
</div> */} </div> */}
<input <input
type="email" type="assignmentId"
placeholder="Student Name" placeholder="Assignment ID"
name="email" name="assignmentId"
value={state.email} value={state.assignmentId}
onChange={handleChange} onChange={handleChange}
/> />
<input <input

View file

@ -18,9 +18,9 @@ function SignUpForm() {
const handleOnSubmit = (evt) => { const handleOnSubmit = (evt) => {
evt.preventDefault(); evt.preventDefault();
const { name, email, password } = state; const { assignmentID, password } = state;
alert( alert(
`You are signed in with name: ${name} email: ${email} and password: ${password}` `You are signed in with assignmentID: ${assignmentID} and password: ${password}`
); );
for (const key in state) { for (const key in state) {
@ -32,7 +32,12 @@ function SignUpForm() {
}; };
const googleAuth = () => { const googleAuth = () => {
<<<<<<< HEAD
window.open(authUrl, "_self"); window.open(authUrl, "_self");
=======
window.open(`${authUrl}/auth/google`, "_self");
>>>>>>> refs/remotes/origin/homepage-2nd-sprint
}; };
return ( return (

View file

@ -1,7 +1,11 @@
.assignment-page { .assignment-page {
max-width: 600px; max-width: 100%;
margin: auto;
padding: 20px; padding: 20px;
margin-top: 70rem;
overflow-x: hidden;
overflow-y: auto;
min-height: 100vh;
box-sizing: border-box;
form { form {
margin-bottom: 20px; margin-bottom: 20px;
@ -44,32 +48,97 @@
} }
} }
.project-list { // .project-list {
margin-top: 2rem; // display: grid;
// grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
// gap: 1.5rem;
// margin-top: 2rem;
// padding-bottom: 3rem;
// .project-item {
// background: #ffffff;
// border: 1px solid #e0e0e0;
// border-radius: 12px;
// padding: 1.5rem;
// box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
// transition: transform 0.2s ease, box-shadow 0.2s ease;
// .project-meta {
// margin-bottom: 0.75rem;
// strong {
// color: #34495e;
// }
// }
// h4 {
// margin: 0.5rem 0;
// font-size: 1.2rem;
// color: #2d3436;
// }
// p {
// margin: 0.25rem 0;
// color: #555;
// line-height: 1.4;
// strong {
// color: #2d3436;
// }
// }
// .action-buttons {
// display: flex;
// gap: 0.5rem;
// margin-top: 0.75rem;
// button {
// background-color: #f4f4f4;
// border: 1px solid #ddd;
// border-radius: 6px;
// padding: 0.4rem 0.8rem;
// cursor: pointer;
// font-size: 0.9rem;
// &:hover {
// background-color: #e9ecef;
// }
// &:nth-child(1) {
// color: #2c3e50;
// }
// &:nth-child(2) {
// color: #c0392b;
// }
// &:nth-child(3) {
// color: #16a085;
// }
// }
// }
// }
// }
h3 { .project-list {
color: #4a90e2; display: grid;
} grid-template-columns: repeat(3, 1fr); // exactly 2 columns
gap: 1.5rem;
margin-top: 2rem;
padding-bottom: 3rem;
.project-item { .project-item {
background: #ffffff; background: #ffffff;
border: 1px solid #e0e0e0; border: 1px solid #e0e0e0;
border-radius: 12px; border-radius: 12px;
padding: 1.5rem; padding: 1.5rem;
margin-bottom: 1.5rem;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
transition: transform 0.2s ease, box-shadow 0.2s ease; transition: transform 0.2s ease, box-shadow 0.2s ease;
overflow-wrap: break-word;
// &:hover { box-shadow: rgb(211, 0, 197) 0px 0px 15px, rgb(255, 42, 109) 0px 0px 25px;
// transform: translateY(-2px);
// box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
// }
.project-meta { .project-meta {
justify-content: space-between;
align-items: center;
margin-bottom: 0.75rem; margin-bottom: 0.75rem;
flex-wrap: wrap;
strong { strong {
color: #34495e; color: #34495e;
@ -104,7 +173,6 @@
padding: 0.4rem 0.8rem; padding: 0.4rem 0.8rem;
cursor: pointer; cursor: pointer;
font-size: 0.9rem; font-size: 0.9rem;
transition: background-color 0.2s ease;
&:hover { &:hover {
background-color: #e9ecef; background-color: #e9ecef;
@ -126,6 +194,7 @@
} }
} }
.modal-overlay { .modal-overlay {
position: fixed; position: fixed;
@ -138,6 +207,7 @@
align-items: center; align-items: center;
justify-content: center; justify-content: center;
z-index: 1000; z-index: 1000;
overflow: hidden;
} }
.modal { .modal {
@ -148,6 +218,7 @@
width: 100%; width: 100%;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15); box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
animation: fadeIn 0.3s ease; animation: fadeIn 0.3s ease;
overflow: auto;
} }
.modal h3 { .modal h3 {
@ -235,4 +306,104 @@
transform: translateY(0); transform: translateY(0);
} }
} }
} }
.assignment-header-box {
background: #0f0f1a;
border: 2px solid #00bfff;
border-radius: 12px;
padding: 50px;
text-align: center;
margin-bottom: 2rem;
// box-shadow: 0 0 20px #00bfff;
box-shadow: rgb(211, 0, 197) 0px 0px 15px, rgb(255, 42, 109) 0px 0px 25px;
border: 1px solid rgb(211, 0, 197);
animation: pulseNeonBlue 2s infinite alternate;
h2 {
color: #00bfff;
margin-bottom: 1rem;
font-weight: bold;
// text-shadow: rgb(5, 217, 232) 0px 0px 5px;
}
button {
background-color: #000;
border: 2px solid #00bfff;
color: #00bfff;
padding: 10px 20px;
border-radius: 8px;
cursor: pointer;
font-size: 1rem;
font-weight: bold;
transition: all 0.3s ease;
&:hover {
background-color: #00bfff;
color: #000;
}
}
}
// @keyframes pulseNeonBlue {
// from {
// box-shadow: 0 0 10px #00bfff, 0 0 20px #00bfff;
// }
// to {
// box-shadow: 0 0 25px #00bfff, 0 0 40px #00bfff;
// }
// }
@keyframes pulseNeonHybrid {
from {
box-shadow:
0 0 10px rgba(211, 0, 197, 0.7),
0 0 20px rgba(255, 42, 109, 0.7),
0 0 10px rgba(0, 191, 255, 0.7);
}
to {
box-shadow:
0 0 25px rgba(211, 0, 197, 0.9),
0 0 40px rgba(255, 42, 109, 0.9),
0 0 30px rgba(0, 191, 255, 0.9);
}
}
.assignment-list-box {
margin-top: 40px;
h3 {
font-size: 1.5rem;
margin-bottom: 20px;
}
.assignment-cards {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: 20px;
}
.assignment-card {
background: #f5f5f5;
padding: 20px;
border-radius: 12px;
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
transition: all 0.3s ease;
p {
margin: 6px 0;
}
a {
color: #2c7be5;
text-decoration: underline;
word-break: break-word;
}
&:hover {
transform: translateY(-4px);
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
}
}