Skip to content

Commit

Permalink
comments instructor tab
Browse files Browse the repository at this point in the history
  • Loading branch information
el-agua committed Oct 19, 2024
1 parent d44f92e commit 3247310
Show file tree
Hide file tree
Showing 7 changed files with 297 additions and 177 deletions.
6 changes: 3 additions & 3 deletions backend/courses/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
StatusUpdate,
User,
)

from review.management.commands.mergeinstructors import resolve_duplicates


Expand Down Expand Up @@ -738,11 +739,10 @@ def get_section_from_course_instructor_semester(course_code, professors, semeste
if not course_topic:
raise ValueError(f"No topic exists for course with code ({course_code})")
course_topic_parent = course_topic.most_recent.full_code
sections = Section.objects.prefetch_related("instructors").filter(
sections = Section.objects.all().prefetch_related("instructors").filter(
course__topic__most_recent__full_code=course_topic_parent, course__semester=semester
)
print(sections.first())
print(sections[0].instructors)
print(sections)
print("HIGH")
professors_query = Q(instructors__name=professors[0])
for professor in professors[1:]:
Expand Down
20 changes: 15 additions & 5 deletions backend/review/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
PreNGSSRestriction,
Section,
)
from courses.serializers import CommentListSerializer, CommentSerializer
from courses.serializers import CommentListSerializer, CommentSerializer, CourseDetailSerializer
from courses.util import (
get_current_semester,
get_or_create_add_drop_period,
Expand Down Expand Up @@ -882,7 +882,7 @@ def get(self, request, semester, course_code):

queryset = og_queryset = self.get_queryset()

print(queryset)
print("I AM INSTRUCTOR", instructor)
# add filters
if semester_arg != "all":
queryset = queryset.all().filter(section__course__semester=semester_arg)
Expand Down Expand Up @@ -925,18 +925,25 @@ def get(self, request, semester, course_code):

def get_queryset(self):
course_code = self.kwargs["course_code"]

semester = self.kwargs["semester"] or "all"

print(semester)

print("I MADE IT HERE", semester)
try:
if semester == "all":
course = Course.objects.filter(full_code=course_code).latest("semester")
course = Course.objects.all().filter(full_code=course_code).first()
else:
print("HI1")
course = get_course_from_code_semester(course_code, None)
print("HI2")
except Http404:
return Response({"message": "Course not found."}, status=status.HTTP_404_NOT_FOUND)
print(CourseDetailSerializer(course).data)

topic = course.topic
print("this is a topic", topic)
return Comment.objects.filter(section__course__topic=topic)


Expand Down Expand Up @@ -1009,6 +1016,7 @@ class CommentViewSet(viewsets.ModelViewSet):

def retrieve(self, request, pk=None):
comment = get_object_or_404(Comment, pk=pk)
print("this is a comment")
return Response(comment, status=status.HTTP_200_OK)

def create(self, request):
Expand All @@ -1030,6 +1038,7 @@ def create(self, request):
request.data.get("instructor"),
request.data.get("semester"),
)
print("ran this")
print(section)
except Exception as e:
print(e)
Expand All @@ -1038,12 +1047,13 @@ def create(self, request):

# create comment and send response
parent_id = request.data.get("parent")
print(parent_id)
print("new section", section)
print("new comment section", section.course.topic)
parent = get_object_or_404(Comment, pk=parent_id) if parent_id is not None else None
comment = Comment.objects.create(
text=request.data.get("text"), author=request.user, section=section, parent=parent
)
print("this is a commnet lol")
print("this is a commnet lol", comment)
base = parent.base if parent else comment
prefix = parent.path + "." if parent else ""
path = prefix + "{:0{}d}".format(comment.id, 10)
Expand Down
5 changes: 3 additions & 2 deletions frontend/review/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"scripts": {
"dev": "NODE_OPTIONS=--openssl-legacy-provider react-scripts start",
"start": "NODE_OPTIONS=--openssl-legacy-provider react-scripts start",
"start": "set NODE_OPTIONS=--openssl-legacy-provider && react-scripts start",
"build": "NODE_OPTIONS=--openssl-legacy-provider react-scripts build",
"test": "exit 0",
"eject": "react-scripts eject",
Expand All @@ -52,6 +52,7 @@
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-react": "^7.18.0",
"eslint-plugin-standard": "^4.0.1",
"prettier": "^1.19.1"
"prettier": "^1.19.1",
"react-error-overlay": "6.0.9"
}
}
175 changes: 99 additions & 76 deletions frontend/review/src/components/Comments/WriteComment.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,108 @@
import React, { useState, forwardRef, useEffect } from 'react';
import { Dropdown } from '../common/Dropdown';
import { apiPostComment, apiLive } from '../../utils/api';
import { compareSemesters } from '../../utils/helpers';
import React, { useState, forwardRef, useEffect } from "react";
import { Dropdown } from "../common/Dropdown";
import { apiPostComment, apiLive } from "../../utils/api";
import { compareSemesters } from "../../utils/helpers";

export const WriteComment = forwardRef(({ course, setUserComment }, ref) => {
export const WriteComment = forwardRef(
({ course, setUserComment, instructor, semestersList }, ref) => {
const [isEditing, setIsEditing] = useState(false);
const [content, setContent] = useState("");
const [semester, setSemester] = useState("2022A");
const [semestersList, setSemestersList] = useState(["2024A", "2023B", "2023A"]);
const [activeSemesters, setActiveSemesters] = useState([]);


console.log(instructor)
console.log(semestersList);

useEffect(() => {
if (isEditing) {
}
}, [course, isEditing]);

useEffect(() => {
if (isEditing) {
}
}, [course, isEditing])
if (semestersList) {
const semList = semestersList.map((s) => s.semester);
setActiveSemesters(semList);
setSemester(semList[0]);
}
}, [semestersList]);

const handleSubmit = () => {
console.log("Comment submitted");
apiPostComment(course, semester, content).then(res => {
console.log(res)
res = {...res, created_at: new Date(res.created_at), modified_at: new Date(res.modified_at)}
setUserComment(res)
});
// setUserComment({
// content: content,
// id: 1,
// created_at: new Date(),
// modified_at: new Date(),
// author_name: "Engineering Student",
// likes: 0,
// course: course,
// semester: semester,
// professorId: [130],
// parent_id: null,
// path: "1",
// replies: 0
// })
}
console.log("Comment submitted");
apiPostComment(course, semester, content, instructor).then((res) => {
console.log(res);
res = {
...res,
created_at: new Date(res.created_at),
modified_at: new Date(res.modified_at),
};
setUserComment(res);
});
// setUserComment({
// content: content,
// id: 1,
// created_at: new Date(),
// modified_at: new Date(),
// author_name: "Engineering Student",
// likes: 0,
// course: course,
// semester: semester,
// professorId: [130],
// parent_id: null,
// path: "1",
// replies: 0
// })
};

return(
<div
className={`write-comment ${isEditing ? "active" : ""}`}
onFocus={() => setIsEditing(true)}
tabIndex={100}
ref={ref}
>
{isEditing &&
<Dropdown name={semester}>
{semestersList.map((s, i) => (
<button
key={i}
className="btn"
onClick={() => {setSemester(s); console.log(s)}}
>
{s}
</button>
))}
</Dropdown>}
<textarea
className="form-control"
id="comment"
rows="3"
value={content}
onChange={e => setContent(e.target.value)}
placeholder="Add a comment"
/>
{isEditing &&
<button
className="btn-borderless btn"
style={{float: "left"}}
onClick={() => setIsEditing(false)}
>
Cancel
</button>}
{isEditing &&
<button
className="btn-borderless btn"
style={{float: "right"}}
onClick={() => handleSubmit()}
>
Comment
</button>}
</div>
)
});
return (
<div
className={`write-comment ${isEditing ? "active" : ""}`}
onFocus={() => setIsEditing(true)}
tabIndex={100}
ref={ref}
>
{isEditing && (
<Dropdown name={semester}>
{activeSemesters.map((s, i) => (
<button
key={i}
className="btn"
onClick={() => {
setSemester(s);
}}
>
{s}
</button>
))}
</Dropdown>
)}
<textarea
className="form-control"
id="comment"
rows="3"
value={content}
onChange={(e) => setContent(e.target.value)}
placeholder="Add a comment"
/>
{isEditing && (
<button
className="btn-borderless btn"
style={{ float: "left" }}
onClick={() => setIsEditing(false)}
>
Cancel
</button>
)}
{isEditing && (
<button
className="btn-borderless btn"
style={{ float: "right" }}
onClick={() => handleSubmit()}
>
Comment
</button>
)}
</div>
);
}
);
Loading

0 comments on commit 3247310

Please sign in to comment.