From d742d93a5ddb9386c5b9f6fbccd5cdf8870bc7d7 Mon Sep 17 00:00:00 2001 From: MLewkowicz Date: Mon, 15 Apr 2024 23:09:41 -0400 Subject: [PATCH 1/2] profile frontend fixes --- backend/app.py | 12 ++++++------ frontend/src/app/page.module.css | 8 ++++---- frontend/src/app/profiles.tsx | 8 +++----- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/backend/app.py b/backend/app.py index 8faba23ec..3c23b1dcd 100644 --- a/backend/app.py +++ b/backend/app.py @@ -144,9 +144,9 @@ 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"] @@ -154,9 +154,9 @@ def verify_course_code(): 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 diff --git a/frontend/src/app/page.module.css b/frontend/src/app/page.module.css index 9cef48973..a68b7906b 100644 --- a/frontend/src/app/page.module.css +++ b/frontend/src/app/page.module.css @@ -289,8 +289,8 @@ .floatingProfileButton { position: fixed; - bottom: 20px; - right: 70px; + bottom: 770px; + right: 20px; width: 50px; height: 50px; padding: 10px 15px; @@ -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); diff --git a/frontend/src/app/profiles.tsx b/frontend/src/app/profiles.tsx index deb181c8e..35f9a3b2c 100644 --- a/frontend/src/app/profiles.tsx +++ b/frontend/src/app/profiles.tsx @@ -6,8 +6,7 @@ import styles from "./page.module.css"; const ProfilePopup = () => { const [popupVisible, setPopupVisible] = useState(false); const [chatHistoryVisible, setChatHistoryVisible] = useState(false); - const [username, setUsername] = useState("JohnDoe"); - const [email, setEmail] = useState("johndoe@example.com"); + const [username, setUsername] = useState(""); const [courses, setCourses] = useState([]); const [search, setSearch] = useState(""); const [chatHistories, setChatHistories] = useState<{ id: number; summary: string }[]>([]); @@ -24,7 +23,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"); @@ -40,7 +39,7 @@ const ProfilePopup = () => { }); if (response.ok) { const data = await response.json(); - setCourses(prevCourses => [...prevCourses, data]); + setCourses(prevCourses => [...prevCourses, data['course']]); setSearch(''); } } @@ -74,7 +73,6 @@ const ProfilePopup = () => {
User Profile
setUsername(e.target.value)} placeholder="Username" /> - setEmail(e.target.value)} placeholder="Email" />
From b771dda1debc9c8aec5a42498b885b13bb60f190 Mon Sep 17 00:00:00 2001 From: MLewkowicz Date: Mon, 15 Apr 2024 23:17:01 -0400 Subject: [PATCH 2/2] moved profiles out of the way --- frontend/src/app/profiles.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/profiles.tsx b/frontend/src/app/profiles.tsx index 35f9a3b2c..e522faabb 100644 --- a/frontend/src/app/profiles.tsx +++ b/frontend/src/app/profiles.tsx @@ -2,6 +2,7 @@ import React, { useState } from "react"; import styles from "./page.module.css"; +import { json } from "stream/consumers"; const ProfilePopup = () => { const [popupVisible, setPopupVisible] = useState(false); @@ -39,8 +40,21 @@ const ProfilePopup = () => { }); if (response.ok) { const data = await response.json(); - setCourses(prevCourses => [...prevCourses, data['course']]); + 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'); } } };