Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: move on top obejct and delete return
Browse files Browse the repository at this point in the history
GBAJS754 committed Apr 4, 2024
1 parent 0322994 commit e1ae742
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/pages/Articles/useFetchArticles.tsx
Original file line number Diff line number Diff line change
@@ -6,25 +6,27 @@ type useFetchArticlesProps = {
followingUsersIds: string[];
};

const ARTICLES_LIMIT = {
newest: 10,
subscribed: 3,
};

const QUERY_KEY = {
newest: 'newestArticles',
subscribed: 'followingArticles',
};

const useFetchArticles = ({ type, followingUsersIds }: useFetchArticlesProps) => {
const LIMIT = {
newest: 10,
subscribed: 3,
};

const QUERY_KEY = {
newest: 'newestArticles',
subscribed: 'followingArticles',
};

const FETCH_API = {
newest: async ({ pageParam = 0 }) => {
return await fetchAllPosts({ offset: pageParam, limit: LIMIT[type] });
return await fetchAllPosts({ offset: pageParam, limit: ARTICLES_LIMIT[type] });
},
subscribed: async ({ pageParam = 0 }) => {
const newArticles = await Promise.all(
followingUsersIds.map((user) =>
fetchUserPosts({ offset: pageParam, limit: LIMIT[type], authorId: user }),
fetchUserPosts({ offset: pageParam, limit: ARTICLES_LIMIT[type], authorId: user }),
),
);
return newArticles.flat();
@@ -35,9 +37,8 @@ const useFetchArticles = ({ type, followingUsersIds }: useFetchArticlesProps) =>
[QUERY_KEY[type]],
FETCH_API[type],
{
getNextPageParam: (lastPage, pages) => {
return lastPage.length < LIMIT[type] ? undefined : pages.length * LIMIT[type];
},
getNextPageParam: (lastPage, pages) => lastPage.length < ARTICLES_LIMIT[type] ? undefined : pages.length * ARTICLES_LIMIT[type]

},
);

0 comments on commit e1ae742

Please sign in to comment.