Skip to content

Commit

Permalink
Merge pull request #30 from yale-swe/michal-new-branch
Browse files Browse the repository at this point in the history
pushing profiles out of the way and fixing the course search feature
  • Loading branch information
MLewkowicz authored Apr 16, 2024
2 parents a2d6951 + b771dda commit 7833902
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
12 changes: 6 additions & 6 deletions backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,19 @@ def verify_course_code():
try:
data = request.get_json()

uid = data.get("uid")
if not uid:
return jsonify({"error": "No uid provided"}), 400
# uid = data.get("uid")
# if not uid:
# return jsonify({"error": "No uid provided"}), 400

course_code = data["search"]
course_collection = app.config["courses"]
user_collection = app.config["profiles"]
course = course_collection.find_one({"course_code": course_code})
if course:
# insert into database
result = user_collection.update_one(
{"uid": uid}, {"$addToSet": {"courses": course_code}}
)
# result = user_collection.update_one(
# {"uid": uid}, {"$addToSet": {"courses": course_code}}
# )
return jsonify(
{"status": "success", "course": course["course_code"]}
), 200
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/app/page.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@

.floatingProfileButton {
position: fixed;
bottom: 20px;
right: 70px;
bottom: 770px;
right: 20px;
width: 50px;
height: 50px;
padding: 10px 15px;
Expand All @@ -310,8 +310,8 @@

.profileContainer {
position: fixed;
bottom: 70px; /* Adjust based on your design */
right: 10px;
bottom: 600px; /* Adjust based on your design */
right: 20px;
width: 300px; /* Adjust size as needed */
background: white;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
Expand Down
22 changes: 17 additions & 5 deletions frontend/src/app/profiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import React, { useState } from "react";
import styles from "./page.module.css";
import { json } from "stream/consumers";

const ProfilePopup = () => {
const [popupVisible, setPopupVisible] = useState(false);
const [chatHistoryVisible, setChatHistoryVisible] = useState(false);
const [username, setUsername] = useState("JohnDoe");
const [email, setEmail] = useState("[email protected]");
const [username, setUsername] = useState("");
const [courses, setCourses] = useState<string[]>([]);
const [search, setSearch] = useState("");
const [chatHistories, setChatHistories] = useState<{ id: number; summary: string }[]>([]);
Expand All @@ -24,7 +24,7 @@ const ProfilePopup = () => {
const response = await fetch('/api/save_profile', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({ username, email }),
body: JSON.stringify({ username }),
});
if (!response.ok) {
console.error("Failed to save profile");
Expand All @@ -40,8 +40,21 @@ const ProfilePopup = () => {
});
if (response.ok) {
const data = await response.json();
setCourses(prevCourses => [...prevCourses, data]);
setCourses(prevCourses => {
// Check if the course already exists based on the course code
const exists = prevCourses.some(course => course === data['course']);
if (!exists) {
return [...prevCourses, data['course']];
} else {
// alert the user that the course is already added
alert('This course is already added.');
return prevCourses;
}
});
setSearch('');
} else {
// Handle cases where the course code is not found or invalid
alert('Invalid course code');
}
}
};
Expand Down Expand Up @@ -74,7 +87,6 @@ const ProfilePopup = () => {
<div className={styles.profileHeader}>User Profile</div>
<div className={styles.profileDetails}>
<input type="text" value={username} onChange={(e) => setUsername(e.target.value)} placeholder="Username" />
<input type="email" value={email} onChange={(e) => setEmail(e.target.value)} placeholder="Email" />
<button onClick={handleSaveProfile}>Save</button>
</div>
<div className={styles.courseSearch}>
Expand Down

0 comments on commit 7833902

Please sign in to comment.