Refactor code, split routes, change url in backend and update in frontend. Still have bugs, infinite loading after signup?

This commit is contained in:
estherdev03
2025-03-19 02:09:30 -06:00
parent 3ac9ed00a2
commit c75fa01392
14 changed files with 582 additions and 510 deletions

View File

@@ -10,7 +10,9 @@ const Home = () => {
useEffect(() => {
const fetchProducts = async () => {
try {
const response = await fetch("http://localhost:3030/get_product");
const response = await fetch(
"http://localhost:3030/api/product/get_product"
);
if (!response.ok) throw new Error("Failed to fetch products");
const data = await response.json();
@@ -27,7 +29,7 @@ const Home = () => {
seller: "Unknown", // Modify if seller info is available
datePosted: "Just now",
isFavorite: false,
})),
}))
);
} else {
throw new Error(data.message || "Error fetching products");
@@ -48,8 +50,8 @@ const Home = () => {
prevListings.map((listing) =>
listing.id === id
? { ...listing, isFavorite: !listing.isFavorite }
: listing,
),
: listing
)
);
};

View File

@@ -33,15 +33,18 @@ const Settings = () => {
}
// Make API call to fetch user data
const response = await fetch("http://localhost:3030/find_user", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: storedUser.email,
}),
});
const response = await fetch(
"http://localhost:3030/api/user/find_user",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: storedUser.email,
}),
}
);
const data = await response.json();
console.log(data);
@@ -67,7 +70,7 @@ const Settings = () => {
} catch (error) {
console.error("Error fetching user data:", error);
setError(
error.message || "An error occurred while loading your profile",
error.message || "An error occurred while loading your profile"
);
} finally {
setIsLoading(false);
@@ -153,7 +156,7 @@ const Settings = () => {
const handleDeleteAccount = async () => {
if (
window.confirm(
"Are you sure you want to delete your account? This action cannot be undone.",
"Are you sure you want to delete your account? This action cannot be undone."
)
) {
try {
@@ -166,7 +169,7 @@ const Settings = () => {
}
// Make API call to delete the account
const response = await fetch("http://localhost:3030/delete", {
const response = await fetch("http://localhost:3030/api/user/delete", {
method: "POST",
headers: {
"Content-Type": "application/json",