bug fix on assignments
This commit is contained in:
parent
ac2461d76a
commit
64fc708bf7
4 changed files with 38 additions and 40 deletions
|
|
@ -141,7 +141,7 @@ const Navbar = () => {
|
||||||
<li>
|
<li>
|
||||||
<Link
|
<Link
|
||||||
to="/editor"
|
to="/editor"
|
||||||
state={{ qrCodeNumber: user.userId }}
|
state={{ qrCodeNumber: user.userId || user.id}}
|
||||||
className={`navbar__link ${
|
className={`navbar__link ${
|
||||||
activeLink === "/editor" ? "navbar__link--active" : ""
|
activeLink === "/editor" ? "navbar__link--active" : ""
|
||||||
}`}
|
}`}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ const AssignmentPage = () => {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
document.title = "Assignment";
|
document.title = "Assignment";
|
||||||
fetchAssignments(); // Add `await` here if it's also async
|
fetchAssignments();
|
||||||
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
@ -89,24 +89,13 @@ const AssignmentPage = () => {
|
||||||
return () => clearTimeout(timer); // Clear timeout on QR code number change
|
return () => clearTimeout(timer); // Clear timeout on QR code number change
|
||||||
}, [qrCodeNumber]);
|
}, [qrCodeNumber]);
|
||||||
|
|
||||||
const getCurrentUser = async () => {
|
const fetchAssignments = async () => {
|
||||||
try {
|
try {
|
||||||
const authResponse = await fetch(`${authUrl}/auth/current_user`, {
|
const authResponse = await fetch(`${authUrl}/auth/current_user`, {
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
});
|
});
|
||||||
const user = await authResponse.json();
|
const user = await authResponse.json();
|
||||||
console.log("Current user fetched:", user);
|
|
||||||
setUser(user);
|
setUser(user);
|
||||||
} catch (error) {
|
|
||||||
console.error("Error fetching current user:", error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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);
|
console.log("User:", user);
|
||||||
|
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
|
|
@ -138,6 +127,8 @@ const AssignmentPage = () => {
|
||||||
setStudentName("");
|
setStudentName("");
|
||||||
setCampID("");
|
setCampID("");
|
||||||
setProgramID("");
|
setProgramID("");
|
||||||
|
setQrCodeNumber("");
|
||||||
|
setAppName("");
|
||||||
setPassword("");
|
setPassword("");
|
||||||
setDescription("");
|
setDescription("");
|
||||||
setFile(null);
|
setFile(null);
|
||||||
|
|
@ -145,6 +136,7 @@ const AssignmentPage = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEditClick = (qrCodeNumber) => {
|
const handleEditClick = (qrCodeNumber) => {
|
||||||
|
console.log("Navigating to editor with QR Code Number:", qrCodeNumber);
|
||||||
navigate('/editor', { state: { qrCodeNumber: qrCodeNumber } });
|
navigate('/editor', { state: { qrCodeNumber: qrCodeNumber } });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -163,21 +155,6 @@ const AssignmentPage = () => {
|
||||||
formData.append("password", password);
|
formData.append("password", password);
|
||||||
formData.append("description", description);
|
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) {
|
if (editingIndex !== null) {
|
||||||
//edit mode
|
//edit mode
|
||||||
await fetch(`${VITE_ASSIGNMENT_URL}/instructor/update/${assignmentId}`, {
|
await fetch(`${VITE_ASSIGNMENT_URL}/instructor/update/${assignmentId}`, {
|
||||||
|
|
@ -233,6 +210,7 @@ const AssignmentPage = () => {
|
||||||
editingIndex !== null ? "Assignment updated!" : "Assignment submitted!"
|
editingIndex !== null ? "Assignment updated!" : "Assignment submitted!"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
setLoading(false);
|
||||||
fetchAssignments(); // Refresh the assignments list
|
fetchAssignments(); // Refresh the assignments list
|
||||||
resetForm();
|
resetForm();
|
||||||
setShowModal(false);
|
setShowModal(false);
|
||||||
|
|
@ -353,6 +331,16 @@ const AssignmentPage = () => {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label>QR Code Number</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
value={qrCodeNumber}
|
||||||
|
onChange={(e) => setQrCodeNumber(e.target.value)}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="password-field">
|
<div className="password-field">
|
||||||
<label>Password</label>
|
<label>Password</label>
|
||||||
<div className="input-wrapper">
|
<div className="input-wrapper">
|
||||||
|
|
@ -427,15 +415,17 @@ const AssignmentPage = () => {
|
||||||
<div key={index} className="project-item">
|
<div key={index} className="project-item">
|
||||||
<div className="project-meta">
|
<div className="project-meta">
|
||||||
<p><strong>Student Name:</strong> {project.studentname || project.studentName}</p>
|
<p><strong>Student Name:</strong> {project.studentname || project.studentName}</p>
|
||||||
<p><strong>CampID:</strong> {project.campid || project.campID}</p>
|
<p><strong>QR Number:</strong> {project.qrcodenumber || project.qrCodeNumber}</p>
|
||||||
<p><strong>ProgramID:</strong> {project.programid || project.programID}</p>
|
<p><strong>App Name:</strong> {project.appname || project.appName}</p>
|
||||||
|
<p><strong>Game Snake ID:</strong> {project.snakegameid || project.snakeGameId}</p>
|
||||||
|
<p><strong>URL:</strong> <a href={project.assignmenturl}>{project.assignmenturl || project.assignmentUrl}</a></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{project.title && <h4>{project.title}</h4>}
|
{/* {project.title && <h4>{project.title}</h4>}
|
||||||
{project.description && <p>{project.description}</p>}
|
{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 && (
|
{/* {project.assignmenturl && (
|
||||||
<p>
|
<p>
|
||||||
<a
|
<a
|
||||||
href={project.assignmenturl}
|
href={project.assignmenturl}
|
||||||
|
|
@ -445,7 +435,7 @@ const AssignmentPage = () => {
|
||||||
View Assignment
|
View Assignment
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
)}
|
)} */}
|
||||||
{project.originalfile && (
|
{project.originalfile && (
|
||||||
<p>
|
<p>
|
||||||
<a
|
<a
|
||||||
|
|
@ -469,8 +459,8 @@ const AssignmentPage = () => {
|
||||||
<div className="action-buttons">
|
<div className="action-buttons">
|
||||||
<button onClick={() => handleEdit(index)}>✏️ Edit</button>
|
<button onClick={() => handleEdit(index)}>✏️ Edit</button>
|
||||||
<button onClick={() => handleDelete(index)}>🗑️ Delete</button>
|
<button onClick={() => handleDelete(index)}>🗑️ Delete</button>
|
||||||
<button key={project.qrCodeNumber} onClick={() => handleEditClick(project.qrCodeNumber)}>
|
<button key={project.qrcodenumber} onClick={() => handleEditClick(project.qrcodenumber)}>
|
||||||
📎 QR
|
📎 Editor
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
.assignment-page {
|
.assignment-page {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
margin-top: 90rem;
|
margin-top: 50rem;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
// min-height: 100vh;
|
min-height: 100vh;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
||||||
form {
|
form {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,18 @@
|
||||||
// Assignment Page Styling
|
// Assignment Page Styling
|
||||||
|
body {
|
||||||
|
justify-content: flex-starts;
|
||||||
|
}
|
||||||
|
|
||||||
.assignment-page {
|
.assignment-page {
|
||||||
|
position: relative;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 2rem;
|
|
||||||
|
a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: #AAC5E5;
|
||||||
|
}
|
||||||
|
|
||||||
section {
|
section {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue