added functional my favorites posts
This commit is contained in:
@@ -59,9 +59,36 @@ export function useFavorites() {
|
||||
}
|
||||
}, [t]);
|
||||
|
||||
/**
|
||||
* Загружает полные посты из избранного текущего пользователя.
|
||||
* @returns {Promise<Array>} - массив постов (PostResponse)
|
||||
*/
|
||||
const loadFavoritePosts = useCallback(async () => {
|
||||
setError("");
|
||||
try {
|
||||
const response = await apiFetch(`${API_URL}/api/v1/favorites/posts`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(t('favorites.loadError'));
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
const posts = Array.isArray(data) ? data : [];
|
||||
return posts.map(post => ({
|
||||
...post,
|
||||
type: post.type ? post.type.toLowerCase() : "loss",
|
||||
}));
|
||||
} catch (err) {
|
||||
console.error('Error loading favorite posts:', err);
|
||||
setError(err.message || t('favorites.loadError'));
|
||||
return [];
|
||||
}
|
||||
}, [t]);
|
||||
|
||||
return {
|
||||
toggleFavorite,
|
||||
loadFavorites,
|
||||
loadFavoritePosts,
|
||||
error,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user