Skip to content

Commit

Permalink
fix: key to cirle_list; proper response handling in Electives.tsx;
Browse files Browse the repository at this point in the history
  • Loading branch information
rohan-b-84 committed Jul 14, 2024
1 parent c1aaf28 commit 7938d1e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
21 changes: 10 additions & 11 deletions frontend/src/components/Circles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ let circles_list = [
const Circles: React.FC = () => {
return (
<div className="circle-container">
{circles_list.map((x) => (
<>
<div
className="circle"
style={{
top: `${x.position[0]}%`,
left: `${x.position[1]}%`,
boxShadow: x.color,
}}
/>
</>
{circles_list.map((x, i) => (
<div
key={i}
className="circle"
style={{
top: `${x.position[0]}%`,
left: `${x.position[1]}%`,
boxShadow: x.color,
}}
/>
))}
</div>
);
Expand Down
26 changes: 13 additions & 13 deletions frontend/src/components/Electives.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ const Electives: React.FC = () => {
const { user, logout } = useAppContext();
const [isBreadthDownloading, setIsBreadthDownloading] = useState(false);
const [isDepthDownloading, setIsDepthDownloading] = useState(false);

const getElective = async (elective: string) => {
const formData = new URLSearchParams();
formData.append("roll_number", user.rollNo);
{
elective == "breadth"
? setIsBreadthDownloading(true)
: setIsDepthDownloading(true);
}

elective == "breadth"
? setIsBreadthDownloading(true)
: setIsDepthDownloading(true);

try {
const res = await fetch(`${BACKEND_URL}/elective/${elective}`, {
Expand All @@ -27,12 +27,14 @@ const Electives: React.FC = () => {
body: formData.toString(),
});

const resData = await res.json();

if (!res.ok) {
const resData = await res.json();
toast.error(resData.message);
if (res.status == 401)
if (resData.message == "Session isn't alive. PLease login again.")
if (
resData.message ==
"Session isn't alive. PLease login again."
)
logout();
return;
}
Expand All @@ -51,11 +53,9 @@ const Electives: React.FC = () => {
toast.error(`Error fetching ${elective} electives!`);
console.error("Error fetching breadth electives:", error);
} finally {
{
elective == "breadth"
? setIsBreadthDownloading(false)
: setIsDepthDownloading(false);
}
elective == "breadth"
? setIsBreadthDownloading(false)
: setIsDepthDownloading(false);
}
};

Expand Down

0 comments on commit 7938d1e

Please sign in to comment.