diff --git a/backend/courses/util.py b/backend/courses/util.py index 05b295c8..ad5e55f7 100644 --- a/backend/courses/util.py +++ b/backend/courses/util.py @@ -30,6 +30,7 @@ StatusUpdate, User, ) + from review.management.commands.mergeinstructors import resolve_duplicates @@ -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:]: diff --git a/backend/review/views.py b/backend/review/views.py index a1bd01a6..9949298c 100644 --- a/backend/review/views.py +++ b/backend/review/views.py @@ -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, @@ -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) @@ -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) @@ -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): @@ -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) @@ -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) diff --git a/frontend/review/package.json b/frontend/review/package.json index ca348bdd..de6a469b 100644 --- a/frontend/review/package.json +++ b/frontend/review/package.json @@ -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", @@ -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" } } diff --git a/frontend/review/src/components/Comments/WriteComment.js b/frontend/review/src/components/Comments/WriteComment.js index fe896f97..5dc8c694 100644 --- a/frontend/review/src/components/Comments/WriteComment.js +++ b/frontend/review/src/components/Comments/WriteComment.js @@ -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( -
setIsEditing(true)} - tabIndex={100} - ref={ref} - > - {isEditing && - - {semestersList.map((s, i) => ( - - ))} - } -