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

pushing profiles out of the way and fixing the course search feature #30

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading