assignment functionalities added and scss updated

This commit is contained in:
Jae Young Ahn 2025-05-07 13:06:05 -07:00
parent eb9e055287
commit bd9237f81a
2 changed files with 207 additions and 141 deletions

View file

@ -12,6 +12,9 @@ const AssignmentPage = () => {
const [projects, setProjects] = useState([]); const [projects, setProjects] = useState([]);
const [showModal, setShowModal] = useState(false); const [showModal, setShowModal] = useState(false);
const [editingIndex, setEditingIndex] = useState(null); const [editingIndex, setEditingIndex] = useState(null);
const [searchTerm, setSearchTerm] = useState("");
const [showPassword, setShowPassword] = useState(false);
const [loading, setLoading] = useState(false);
useEffect(() => { useEffect(() => {
document.title = "Assignment"; document.title = "Assignment";
@ -20,15 +23,10 @@ const AssignmentPage = () => {
const fetchAssignments = async () => { const fetchAssignments = async () => {
try { try {
const res = await fetch("http://localhost:8082/instructor/list/9", { const res = await fetch("http://localhost:8082/instructor/list/9");
// credentials: "include",
});
if (!res.ok) throw new Error("Failed to fetch"); if (!res.ok) throw new Error("Failed to fetch");
const data = await res.json(); const data = await res.json();
// Optional: Remove duplicate assignment IDs if needed
const unique = Array.from( const unique = Array.from(
new Map(data.map((item) => [item.assignmentid, item])).values() new Map(data.map((item) => [item.assignmentid, item])).values()
); );
@ -52,6 +50,7 @@ const AssignmentPage = () => {
const handleSubmit = (e) => { const handleSubmit = (e) => {
e.preventDefault(); e.preventDefault();
setLoading(true);
const newProject = { const newProject = {
studentname: studentName, studentname: studentName,
@ -62,6 +61,7 @@ const AssignmentPage = () => {
fileName: file ? file.name : null, fileName: file ? file.name : null,
}; };
setTimeout(() => {
if (editingIndex !== null) { if (editingIndex !== null) {
const updatedProjects = [...projects]; const updatedProjects = [...projects];
updatedProjects[editingIndex] = newProject; updatedProjects[editingIndex] = newProject;
@ -73,6 +73,8 @@ const AssignmentPage = () => {
alert(editingIndex !== null ? "Assignment updated!" : "Assignment submitted!"); alert(editingIndex !== null ? "Assignment updated!" : "Assignment submitted!");
resetForm(); resetForm();
setShowModal(false); setShowModal(false);
setLoading(false);
}, 2000);
}; };
const handleEdit = (index) => { const handleEdit = (index) => {
@ -99,6 +101,15 @@ const AssignmentPage = () => {
<button onClick={() => { resetForm(); setShowModal(true); }}> Add New</button> <button onClick={() => { resetForm(); setShowModal(true); }}> Add New</button>
</div> </div>
<div className="assignment-search-box">
<input
type="text"
placeholder="🔍︎ Search"
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
/>
</div>
{showModal && ( {showModal && (
<div className="modal-overlay"> <div className="modal-overlay">
<div className="modal"> <div className="modal">
@ -119,9 +130,22 @@ const AssignmentPage = () => {
<input type="text" value={programID} onChange={(e) => setProgramID(e.target.value)} required /> <input type="text" value={programID} onChange={(e) => setProgramID(e.target.value)} required />
</div> </div>
<div> <div className="password-field">
<label>Password</label> <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>
<div> <div>
@ -139,9 +163,20 @@ const AssignmentPage = () => {
<input type="file" onChange={(e) => setFile(e.target.files[0])} /> <input type="file" onChange={(e) => setFile(e.target.files[0])} />
</div> </div>
{loading && (
<div className="spinner-container">
<div className="spinner"></div>
<p>Uploading...</p>
</div>
)}
<div className="modal-buttons"> <div className="modal-buttons">
<button type="submit">{editingIndex !== null ? "Update" : "Submit"}</button> <button type="submit" disabled={loading}>
<button type="button" onClick={() => { resetForm(); setShowModal(false); }}>Cancel</button> {editingIndex !== null ? "Update" : "Submit"}
</button>
<button type="button" onClick={() => { resetForm(); setShowModal(false); }} disabled={loading}>
Cancel
</button>
</div> </div>
</form> </form>
</div> </div>
@ -150,34 +185,53 @@ const AssignmentPage = () => {
{projects.length > 0 && ( {projects.length > 0 && (
<div className="project-list"> <div className="project-list">
{projects.map((project, index) => ( {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 key={index} className="project-item">
<div className="project-meta"> <div className="project-meta">
<strong>Student Name:</strong> {project.studentname || project.studentName} |{" "} <p><strong>Student Name:</strong> {project.studentname || project.studentName}</p>
<strong>CampID:</strong> {project.campid || project.campID} |{" "} <p><strong>CampID:</strong> {project.campid || project.campID}</p>
<strong>ProgramID:</strong> {project.programid || project.programID} <p><strong>ProgramID:</strong> {project.programid || project.programID}</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 className="assignment-links">
<a href={project.assignmenturl} target="_blank" rel="noopener noreferrer">View Assignment</a> <a href={project.assignmenturl} target="_blank" rel="noopener noreferrer">View Assignment</a>
</p> </p>
)} )}
{project.originalfile && ( {project.originalfile && (
<p> <p className="assignment-links">
<a href={project.originalfile} target="_blank" rel="noopener noreferrer">Original File</a> |{" "} <a href={project.originalfile} target="_blank" rel="noopener noreferrer">Original File</a>{" "}
<a href={project.editablefile} target="_blank" rel="noopener noreferrer">Editable File</a> <a href={project.editablefile} target="_blank" rel="noopener noreferrer">Editable File</a>
</p> </p>
)} )}
<div className="action-buttons"> <div className="action-buttons">
<button onClick={() => handleEdit(index)}> Edit</button> <button onClick={() => handleEdit(index)}> View Edit</button>
<button onClick={() => handleDelete(index)}>🗑 Delete</button> <button onClick={() => handleDelete(index)}>🗑 Delete</button>
<button onClick={() => alert("QR feature coming soon!")}>📎 QR</button> <button onClick={() => alert("QR feature coming soon!")}>🧮 Editor</button>
</div> </div>
</div> </div>
))} ))}

View file

@ -1,10 +1,10 @@
.assignment-page { .assignment-page {
max-width: 100%; max-width: 100%;
padding: 20px; padding: 20px;
margin-top: 70rem; margin-top: 90rem;
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 {
@ -48,116 +48,55 @@
} }
} }
// .project-list {
// display: grid;
// grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
// gap: 1.5rem;
// margin-top: 2rem;
// padding-bottom: 3rem;
// .project-item { .assignment-links a {
// background: #ffffff; color: white !important;
// 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;
// }
// }
// }
// }
// }
.project-list { .project-list {
display: grid; display: grid;
grid-template-columns: repeat(3, 1fr); // exactly 2 columns grid-template-columns: repeat(3, 1fr);
gap: 1.5rem; gap: 1.5rem;
margin-top: 2rem; margin-top: 2rem;
padding-bottom: 3rem; padding-bottom: 7rem;
.project-item { .project-item {
background: #ffffff; background: #0f0f1a;
border: 1px solid #e0e0e0;
border-radius: 12px; border-radius: 12px;
padding: 1.5rem; padding: 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; overflow-wrap: break-word;
box-shadow: rgb(211, 0, 197) 0px 0px 15px, rgb(255, 42, 109) 0px 0px 25px; // box-shadow: rgb(211, 0, 197) 0px 0px 15px, rgb(255, 42, 109) 0px 0px 25px;
border: 2px solid rgb(75 187 236);
.project-meta { .project-meta {
margin-bottom: 0.75rem; margin-bottom: 0.75rem;
color: lightgray;
strong { strong {
color: #34495e; color: #00bfff;
font-weight: bold;
} }
} }
h4 { h4 {
margin: 0.5rem 0; margin: 0.5rem 0;
font-size: 1.2rem; font-size: 1.2rem;
color: #2d3436; color: white;
} }
p { p {
margin: 0.25rem 0; margin: 1rem 0;
color: #555; color: white;
line-height: 1.4; line-height: 1.4;
font-size: 15px;
// margin-bottom: 10px;
strong { strong {
color: #2d3436; color: #00bfff;
font-weight: bold;
} }
} }
@ -167,19 +106,20 @@
margin-top: 0.75rem; margin-top: 0.75rem;
button { button {
background-color: #f4f4f4; background-color: #000000;
border: 1px solid #ddd; border: 2px solid #00bfff;
border-radius: 6px; border-radius: 6px;
padding: 0.4rem 0.8rem; padding: 0.4rem 0.8rem;
cursor: pointer; cursor: pointer;
font-size: 0.9rem; font-size: 0.9rem;
&:hover { &:hover {
background-color: #e9ecef; background-color: #E4E4E4;
border: 2px solid #E4E4E4;
} }
&:nth-child(1) { &:nth-child(1) {
color: #2c3e50; color: #007fff;
} }
&:nth-child(2) { &:nth-child(2) {
@ -211,7 +151,7 @@
} }
.modal { .modal {
background: #fff; background: #f3f3f3;
padding: 2rem; padding: 2rem;
border-radius: 12px; border-radius: 12px;
max-width: 500px; max-width: 500px;
@ -221,6 +161,10 @@
overflow: auto; overflow: auto;
} }
.modal form {
background-color: #f3f3f3;
}
.modal h3 { .modal h3 {
margin-bottom: 1rem; margin-bottom: 1rem;
font-size: 1.5rem; font-size: 1.5rem;
@ -237,7 +181,7 @@
font-size: 0.9rem; font-size: 0.9rem;
font-weight: 500; font-weight: 500;
margin-bottom: 0.4rem; margin-bottom: 0.4rem;
color: #555; color: black
} }
.modal input[type="text"], .modal input[type="text"],
@ -246,10 +190,11 @@
.modal textarea { .modal textarea {
width: 100%; width: 100%;
padding: 0.6rem 0.8rem; padding: 0.6rem 0.8rem;
border: 1px solid #ccc; border: 1px solid #BBBBBB;
border-radius: 6px; border-radius: 6px;
font-size: 0.95rem; font-size: 0.95rem;
transition: border-color 0.2s ease; transition: border-color 0.2s ease;
background-color: white;
&:focus { &:focus {
border-color: #007bff; border-color: #007bff;
@ -288,7 +233,7 @@
} }
.modal-buttons button[type="button"] { .modal-buttons button[type="button"] {
background-color: #e0e0e0; background-color: #d3d3d3;
color: #333; color: #333;
&:hover { &:hover {
@ -312,7 +257,7 @@
background: #0f0f1a; background: #0f0f1a;
border: 2px solid #00bfff; border: 2px solid #00bfff;
border-radius: 12px; border-radius: 12px;
padding: 50px; padding: 50px 100px;
text-align: center; text-align: center;
margin-bottom: 2rem; margin-bottom: 2rem;
// box-shadow: 0 0 20px #00bfff; // box-shadow: 0 0 20px #00bfff;
@ -407,3 +352,70 @@
} }
} }
} }
// Search Bar Styling
.assignment-search-box {
margin: 1rem 0;
input {
width: 100%;
// padding: 0.5rem;
font-size: 1rem;
border-radius: 8px;
border: 1px solid #ccc;
background-color: #1a1a2b;
color: #fefefe;
box-shadow: rgb(211, 0, 197) 0px 0px 15px, rgb(255, 42, 109) 0px 0px 25px;
&::placeholder {
color: #aaa;
}
&:focus {
outline: none;
border-color: rgb(211, 0, 197);
}
}
}
.password-field {
.input-wrapper {
position: relative;
input {
width: 100%;
padding-right: 2.5rem;
}
.eye-icon {
position: absolute;
top: 50%;
right: 0.75rem;
transform: translateY(-50%);
cursor: pointer;
color: #555;
user-select: none;
}
}
}
.spinner-container {
display: flex;
align-items: center;
gap: 0.5rem;
margin: 10px 0;
}
.spinner {
width: 16px;
height: 16px;
border: 3px solid rgba(0, 0, 0, 0.2);
border-top: 3px solid #333;
border-radius: 50%;
animation: spin 0.6s linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}