Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cindyrzheng/dropclass #66

Merged
merged 25 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d5ad247
Add DropStudent endpoint.
krashanoff Feb 23, 2022
213eae3
Adding drop api call (still not working since class id and student id…
Feb 24, 2022
66d80e0
Adding drop api call (still not working since class id and student id…
Feb 24, 2022
947f109
Merge branch 'cindyrzheng/dropclass' of https://github.com/cs130-w22/…
Mar 2, 2022
6642d75
edit to add some error states
Mar 2, 2022
7bd0f5f
Revert "edit to add some error states"
Mar 2, 2022
36cf520
add error changes
Mar 2, 2022
f43f7a8
Adding drop api call (still not working since class id and student id…
Feb 24, 2022
7feae3e
edit to add some error states
Mar 2, 2022
eae6c74
Revert "edit to add some error states"
Mar 2, 2022
bdda285
add error changes
Mar 2, 2022
832124e
Merge branch 'cindyrzheng/dropclass' of https://github.com/cs130-w22/…
Mar 7, 2022
5c4bb7b
rebase
Mar 7, 2022
0b6f29f
Revert "edit to add some error states"
Mar 2, 2022
90ef384
add error changes
Mar 2, 2022
8e1b71c
edit to add some error states
Mar 2, 2022
52626ca
Revert "edit to add some error states"
Mar 2, 2022
af47368
Merge branch 'cindyrzheng/dropclass' of https://github.com/cs130-w22/…
Mar 7, 2022
729d846
remaking classlist + dropping
Mar 7, 2022
1eb5e1d
Editing endpoint method call to include id as the parameter name inst…
Mar 7, 2022
8b31303
Update frontend/src/ClassView/ClassList.tsx
cindyrzheng Mar 7, 2022
f86ff89
Update frontend/src/ClassView/ClassList.tsx
cindyrzheng Mar 7, 2022
53ed0e1
Update frontend/src/api.ts
cindyrzheng Mar 7, 2022
ff1eebc
change to use studentId
Mar 7, 2022
61329da
hit linter
Mar 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ClassView from "./ClassView/ClassView";
import Me from "./Me";
import Assignment from "./Assignment";
import Results from "./Results";
import ClassList from "./ClassView/ClassList";

function App() {
const [cookies, setCookies] = useCookies(["jwt"]);
Expand All @@ -19,7 +20,7 @@ function App() {
<Route path="/create" element={<CreateAccount />} />
<Route path="/results/:id" element={<Results />} />
<Route path="/:classId/:assignmentId" element={<Assignment />} />

<Route path="/:classId/classList" element={<ClassList />} />
<Route path="/class" element={<ClassView />} />
</Routes>
</Router>
Expand Down
25 changes: 25 additions & 0 deletions frontend/src/Card/ClassCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from "react";
import { useCookies } from "react-cookie";
import { useNavigate } from "react-router-dom";

import Card from "react-bootstrap/Card";
import Stack from "react-bootstrap/Stack";
Expand All @@ -9,6 +10,8 @@ import { createAssignment } from "../api";
import CreateAssignmentModal from "../Modal/CreateAssignmentModal";
import CreateInviteModal from "../Modal/CreateInviteModal";

import { dropStudent } from "../api";

export default function ClassCard({
id,
name,
Expand All @@ -26,6 +29,18 @@ export default function ClassCard({
const [errors, setErrors] = useState<Array<Error>>([]);
const [showCreateAssignment, setShowCreateAssignment] = useState(false);
const [showCreateInvite, setShowCreateInvite] = useState(false);
const nav = useNavigate();
const navToClassList = () => {
nav(`/${id}/classlist`);
};
const dropHandler = (classId: string) => {
dropStudent(
cookies.jwt,
{ classId, studentId: "" },
() => true,
() => true
);
};

return (
<>
Expand Down Expand Up @@ -70,6 +85,16 @@ export default function ClassCard({
>
Create invite
</Button>
<Button variant="primary" onClick={() => navToClassList()}>
View Class Stats
</Button>
</>
)}
{!showCreate && (
<>
<Button variant="primary" onClick={() => dropHandler(id)}>
Drop This Class
</Button>
</>
)}
</Stack>
Expand Down
108 changes: 108 additions & 0 deletions frontend/src/ClassView/ClassList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import React, { useState, useEffect } from "react";

import { useParams } from "react-router-dom";
import { useCookies } from "react-cookie";

import Container from "react-bootstrap/Container";
import Button from "react-bootstrap/Button";
import Table from "react-bootstrap/Table";
import Modal from "react-bootstrap/Modal";
import Alert from "react-bootstrap/Alert";

import { dropStudent, getClass } from "../api";

function ClassListView() {
const params = useParams();
const arr: { id: number; username: string }[] = [];
const [cookies, setCookies] = useCookies(["jwt"]);
const [show, setShow] = useState(false);
const [error, setError] = useState("");
const [students, setStudents] = useState(arr);
const [classId, setClassId] = useState(params.classId);

useEffect(() => {
setClassId(params.classId);
if (classId) {
getClass(
cookies.jwt,
{ classId },
(res) => {
console.log(res);
setStudents(res.members);
console.log(students);
},
() => {
setError("can't find class");
}
);
}
}, []);

function handleDropStudent(studentId: string) {
if (classId && studentId) {
dropStudent(
cookies.jwt,
{ classId, studentId },
() => {
setError("Dropped student!");
},
() => {
setError("Failed dropping student!");
}
);
}
handleClose();
}

const handleClose = () => setShow(false);
const handleShow = () => setShow(true);
return (
<Container>
{error && <Alert variant={"danger"}>Failed to login: {error}</Alert>}
<h1>My Students</h1>
<Table striped bordered hover>
<thead>
<tr>
<th>Name</th>
<th>Grade</th>
<th />
</tr>
</thead>
<tbody>
{students.map((x, id) => (
<tr key={x.username}>
<td>{x.username}</td>
<td>
<>
<Button variant="primary" onClick={handleShow}>
Drop Student
</Button>
<Modal show={show} onHide={handleClose}>
<Modal.Body>
Are you sure you want to drop {x.id}?
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose}>
Cancel
</Button>
<Button
variant="primary"
onClick={() => {
handleDropStudent(x.id + "");
}}
>
Drop Student
</Button>
</Modal.Footer>
</Modal>
</>
</td>
</tr>
))}
</tbody>
</Table>
</Container>
);
}

export default ClassListView;
8 changes: 5 additions & 3 deletions frontend/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export interface AssignmentData {
* @param onSuccess Fired on success.
* @param onFailure Fired on failure.
*/

export const getAssignment = authorized<
{ classId: string; assignmentId: string },
AssignmentData
Expand Down Expand Up @@ -320,9 +321,10 @@ export const createInvite = authorized<
* @param onSuccess Fired on successful request.
* @param onFailure Fired on failed request.
*/
const dropStudent = authorized<{ classId: string; studentId: string }, void>(
({ classId, studentId }) => [`/class/${classId}/drop`, { studentId }]
);
export const dropStudent = authorized<
{ classId: string; studentId: string },
void
>(({ classId, studentId }) => [`/class/${classId}/drop`, { id: studentId }]);

export interface UserInformation {
professor?: boolean;
Expand Down