merge with main

This commit is contained in:
JBB0807 2025-05-07 21:05:39 -07:00
commit ac2461d76a
16 changed files with 599 additions and 242 deletions

View file

@ -1,6 +1,6 @@
import React, { useState, useEffect } from "react";
import "../scss/components/_assignment.scss";
import { useLocation, useNavigate } from "react-router-dom";
import {useNavigate } from "react-router-dom";
const AssignmentPage = () => {
const [assignmentId, setAssignmentId] = useState("");
@ -21,12 +21,14 @@ const AssignmentPage = () => {
const VITE_ASSIGNMENT_URL = import.meta.env.VITE_ASSIGNMENT_URL;
const authUrl = import.meta.env.VITE_AUTH_URL;
const [searchTerm, setSearchTerm] = useState("");
const [showPassword, setShowPassword] = useState(false);
const [loading, setLoading] = useState(false);
const navigate = useNavigate();
useEffect(() => {
document.title = "Assignment";
fetchAssignments(); // Add `await` here if it's also async
}, []);
@ -102,6 +104,8 @@ const AssignmentPage = () => {
const fetchAssignments = async () => {
try {
await getCurrentUser(); // Fetch the current user first
if (!user.userId) return; // Check if user is logged in
// Check if user is logged in
console.log("User:", user);
@ -146,6 +150,7 @@ const AssignmentPage = () => {
const handleSubmit = async (e) => {
e.preventDefault();
setLoading(true);
if (!user.userId) return alert("Please login to submit an assignment.");
@ -158,6 +163,21 @@ const AssignmentPage = () => {
formData.append("password", password);
formData.append("description", description);
setTimeout(() => {
//replace with api
// if (editingIndex !== null) {
// const updatedProjects = [...projects];
// updatedProjects[editingIndex] = newProject;
// setProjects(updatedProjects);
// } else {
// setProjects([...projects, newProject]);
// }
alert(editingIndex !== null ? "Assignment updated!" : "Assignment submitted!");
resetForm();
setShowModal(false);
setLoading(false);
}, 2000);
if (editingIndex !== null) {
//edit mode
await fetch(`${VITE_ASSIGNMENT_URL}/instructor/update/${assignmentId}`, {
@ -180,7 +200,7 @@ const AssignmentPage = () => {
});
} else {
//create mode
formData.append("instructorid", userId);
formData.append("instructorid", user.userId);
formData.append("appname", appName);
if (file) {
@ -275,6 +295,15 @@ const AssignmentPage = () => {
</button>
</div>
<div className="assignment-search-box">
<input
type="text"
placeholder="🔍︎ Search"
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
/>
</div>
{showModal && (
<div className="modal-overlay">
<div className="modal">
@ -324,24 +353,22 @@ const AssignmentPage = () => {
/>
</div>
<div>
<label>QR Code Number</label>
<input
type="text"
value={qrCodeNumber}
onChange={(e) => setQrCodeNumber(e.target.value)}
required
/>
</div>
<div>
<div className="password-field">
<label>Password</label>
<input
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
/>
<div className="input-wrapper">
<input
type={showPassword ? "text" : "password"}
value={password}
onChange={(e) => setPassword(e.target.value)}
required
/>
<span
className="eye-icon"
onClick={() => setShowPassword((prev) => !prev)}
>
{showPassword ? "Hide" : "Show"}
</span>
</div>
</div>
<div>
@ -353,27 +380,23 @@ const AssignmentPage = () => {
></textarea>
</div>
{editingIndex === null && (
<div>
<label>File Upload (optional)</label>
<input
type="file"
onChange={(e) => setFile(e.target.files[0])}
/>
<div>
<label>File Upload (optional)</label>
<input type="file" onChange={(e) => setFile(e.target.files[0])} />
</div>
{loading && (
<div className="spinner-container">
<div className="spinner"></div>
<p>Uploading...</p>
</div>
)}
<div className="modal-buttons">
<button type="submit">
<button type="submit" disabled={loading}>
{editingIndex !== null ? "Update" : "Submit"}
</button>
<button
type="button"
onClick={() => {
resetForm();
setShowModal(false);
}}
>
<button type="button" onClick={() => { resetForm(); setShowModal(false); }} disabled={loading}>
Cancel
</button>
</div>
@ -384,23 +407,33 @@ const AssignmentPage = () => {
{projects.length > 0 && (
<div className="project-list">
{projects.map((project, index) => (
<div key={index} className="project-item">
<div className="project-meta">
<strong>Student Name:</strong>{" "}
{project.studentname || project.studentName} |{" "}
<strong>CampID:</strong> {project.campid || project.campID} |{" "}
<strong>ProgramID:</strong>{" "}
{project.programid || project.programID}
</div>
{projects
.filter((project) => {
if (!searchTerm.trim()) return true;
const regex = new RegExp(searchTerm, "i");
return (
regex.test(project.studentname || project.studentName || "") ||
regex.test(project.campid || project.campID || "") ||
regex.test(project.programid || project.programID || "") ||
regex.test(project.title || "") ||
regex.test(project.description || "") ||
regex.test(project.fileName || "") ||
regex.test(project.assignmenturl || "") ||
regex.test(project.originalfile || "") ||
regex.test(project.editablefile || "")
);
})
.map((project, index) => (
<div key={index} className="project-item">
<div className="project-meta">
<p><strong>Student Name:</strong> {project.studentname || project.studentName}</p>
<p><strong>CampID:</strong> {project.campid || project.campID}</p>
<p><strong>ProgramID:</strong> {project.programid || project.programID}</p>
</div>
{project.title && <h4>{project.title}</h4>}
{project.description && <p>{project.description}</p>}
{project.fileName && (
<p>
<strong>Uploaded File:</strong> {project.fileName}
</p>
)}
{project.fileName && <p><strong>Uploaded File:</strong> {project.fileName}</p>}
{project.assignmenturl && (
<p>
@ -437,7 +470,7 @@ const AssignmentPage = () => {
<button onClick={() => handleEdit(index)}> Edit</button>
<button onClick={() => handleDelete(index)}>🗑 Delete</button>
<button key={project.qrCodeNumber} onClick={() => handleEditClick(project.qrCodeNumber)}>
📎 {project.qrcodenumber}
📎 QR
</button>
</div>
</div>
@ -448,4 +481,4 @@ const AssignmentPage = () => {
);
};
export default AssignmentPage;
export default AssignmentPage;

View file

@ -2,7 +2,6 @@ import React from "react";
function SignUpForm() {
const authUrl = import.meta.env.VITE_AUTH_URL;
const [state, setState] = React.useState({
name: "",
email: "",
@ -33,7 +32,6 @@ function SignUpForm() {
};
const googleAuth = () => {
window.open(`${authUrl}/auth/google`, "_self");
};