Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
guzmanalejandro committed Dec 14, 2023
1 parent 13d3367 commit 437899a
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/components/UserFeed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function UserFeed() {
setFilters(loggedOutFilters);
setRecipeName(null);
console.error("hola")
getRecipes(loggedOutFilters, null, 0, 9, true, feedType);
getRecipesLogout(loggedOutFilters, null, 0, 9, true, feedType);
}
fetchMyUserData()
}, [isLogged]);
Expand Down Expand Up @@ -60,6 +60,34 @@ function UserFeed() {
}
};

const getRecipesLogout = async (filters, recipeName, page, numRecipes, reset, feedType) => {
setLoading(true);
let url = buildRequestUrl(filters, recipeName, page, numRecipes, feedType);
try {
const response = await fetch(url, {
method: 'GET',
});
if (!response.ok) {
if (response.status === 400) {
setPage(page - 1);
setFinished(true);
}
throw new Error('Failed to fetch recipes');
}
const data = await response.json();
console.log(data)
if (reset) {
setRecipes(data)
} else {
setRecipes(recipes.concat(data));
}
} catch (error) {
console.error('Error fetching recipes:', error);
} finally {
setLoading(false);
}
};

const getRecipes = async (filters, recipeName, page, numRecipes, reset, feedType) => {
setLoading(true);
let url = buildRequestUrl(filters, recipeName, page, numRecipes, feedType);
Expand Down Expand Up @@ -122,6 +150,7 @@ function UserFeed() {
localStorage.setItem('feedType', tab);
if (!isLogged() && tab === "following") {
setShowLoginRedirectModal(true);
setFeedType('foryou');
return;
}
getRecipes(filters, recipeName, 0, numRecipes, true, tab);
Expand Down

0 comments on commit 437899a

Please sign in to comment.