diff --git a/src/redux/feed/thunks.ts b/src/redux/feed/thunks.ts index 93fa162e4c27323cd63ceec0f5c08da22b50ee4c..bdce4f82070356b09402940ae98f497e3fd135a8 100644 --- a/src/redux/feed/thunks.ts +++ b/src/redux/feed/thunks.ts @@ -6,10 +6,10 @@ import type { AppThunkAction } from '../types'; import { setUserFeed, likePostFeedAction, unlikePostFeedAction, deleteCommentFeedAction, followUserFeedAction, unfollowUserFeedAction } from './actions'; -// Users pour le feed +// User posts for feed export const fetchFeedUserAsync = (): AppThunkAction<Promise<void>> => { return async (dispatch, getState, api) => { - const { data } = await api.users.me.feed.fetch({ cursor: null, amount: 12 }); // charger 12 posts que ce soit dans le feed ou le discover + const { data } = await api.users.me.feed.fetch({ cursor: null, amount: 12 }); // chargement de 12 posts dispatch(setUserFeed(data.items)); }; }; @@ -64,4 +64,12 @@ export const unfollowUserFeedAsync = (postId: number, userId: number): AppThunkA await api.users.me.followers.unfollow(userId); dispatch(unfollowUserFeedAction(postId)); }; +}; + +// User posts for discover +export const fetchDiscoverAsync = (): AppThunkAction<Promise<void>> => { + return async (dispatch, getState, api) => { + const { data } = await api.posts.fetch({ cursor: null, amount: 20 }); + dispatch(setUserFeed(data.items)); + } }; \ No newline at end of file diff --git a/src/views/DiscoverView.tsx b/src/views/DiscoverView.tsx index 880664ed878c66444c7f69238f2b473838f213f9..ac02afeabfa9f7adc8ac9f50004dec76ada350e0 100644 --- a/src/views/DiscoverView.tsx +++ b/src/views/DiscoverView.tsx @@ -10,7 +10,7 @@ import DiscoverPost from '../components/DiscoverPost'; // AUTRES FICHIERS import useAppDispatch from '../hooks/useAppDispatch'; import useFeedItems from '../hooks/useFeedItems'; -import { fetchFeedUserAsync } from '../redux/feed/thunks'; +import { fetchDiscoverAsync } from '../redux/feed/thunks'; import { Link } from 'react-router-dom'; // ICONS @@ -28,7 +28,7 @@ const DiscoverView = () => { // }, []); useEffect(() => { - dispatch(fetchFeedUserAsync()); + dispatch(fetchDiscoverAsync()); }, []); const feedItems = useFeedItems();