-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from yale-swe/michal-new-branch
pushing profiles out of the way and fixing the course search feature
- Loading branch information
Showing
3 changed files
with
27 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 }[]>([]); | ||
|
@@ -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"); | ||
|
@@ -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'); | ||
} | ||
} | ||
}; | ||
|
@@ -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}> | ||
|