added functional my favorites posts

This commit is contained in:
SlimusMinus
2026-08-24 00:46:00 +03:00
parent d4f12e98d4
commit 1f0cbc50bf
8 changed files with 78 additions and 11 deletions

View File

@@ -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,
};
}