From 01ca83b01e88ecbe449592c506b1e3373c59e746 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Chlo=C3=A9=20JACOB?= <chloe.jacob4@etu.unistra.fr>
Date: Tue, 28 Feb 2023 09:01:34 +0100
Subject: [PATCH] nettoyage des thunks

---
 src/redux/feed/thunks.ts | 28 +++++++---------------------
 src/redux/post/thunks.ts | 33 ++++++++++-----------------------
 2 files changed, 17 insertions(+), 44 deletions(-)

diff --git a/src/redux/feed/thunks.ts b/src/redux/feed/thunks.ts
index c77cf23..674b357 100644
--- a/src/redux/feed/thunks.ts
+++ b/src/redux/feed/thunks.ts
@@ -1,7 +1,7 @@
 import { Instalike } from '@jmetterrothan/instalike';
 import { data } from 'autoprefixer';
 
-// Autres fichiers
+// AUTRES FICHIERS
 import type { AppThunkAction } from '../types';
 import { setUserFeed, likePostFeedAction, unlikePostFeedAction, deleteCommentFeedAction, followUserFeedAction, unfollowUserFeedAction } from './actions';
 
@@ -9,46 +9,32 @@ import { setUserFeed, likePostFeedAction, unlikePostFeedAction, deleteCommentFee
 // Users pour le feed
 export const fetchFeedUserAsync = (): AppThunkAction<Promise<void>> => {
   return async (dispatch, getState, api) => {
-
     const { data } = await api.users.me.feed.fetch({ cursor: null });
     dispatch(setUserFeed(data.items));
-
   };
 };
 
 // Like post
 export const likepostAsync = (postId: number): AppThunkAction<Promise<void>> => {
   return async (dispatch, getState, api) => {
-    try {
-      await api.posts.find(postId).like();
-      dispatch(likePostFeedAction(postId));
-    } catch (e) {
-      throw e;
-    }
+    await api.posts.find(postId).like();
+    dispatch(likePostFeedAction(postId));
   };
 };
 
 // Unlike post
 export const unlikePostAsync = (postId: number): AppThunkAction<Promise<void>> => {
   return async (dispatch, getState, api) => {
-    try {
-      await api.posts.find(postId).unlike();
-      dispatch(unlikePostFeedAction(postId));
-    } catch (e) {
-      throw e;
-    }
+    await api.posts.find(postId).unlike();
+    dispatch(unlikePostFeedAction(postId));
   };
 };
 
 // Delete its own comment
 export const deleteCommentFeedAsync = (postId: number, commentId: number): AppThunkAction<Promise<void>> => {
   return async (dispatch, getState, api) => {
-    try {
-      await api.posts.find(postId).comments.find(commentId).delete();
-      dispatch(deleteCommentFeedAction(commentId));
-    } catch (e) {
-      throw e;
-    }
+    await api.posts.find(postId).comments.find(commentId).delete();
+    dispatch(deleteCommentFeedAction(commentId));
   };
 };
 
diff --git a/src/redux/post/thunks.ts b/src/redux/post/thunks.ts
index 7445892..ffb05e4 100644
--- a/src/redux/post/thunks.ts
+++ b/src/redux/post/thunks.ts
@@ -4,7 +4,6 @@ import { data } from 'autoprefixer';
 // AUTRES FICHIERS
 import { AppThunkAction } from '../types';
 import { failurePostAction, loadPostAction, setPost, sucessPostAction, followUserPostAction, unfollowUserPostAction } from './actions';
-import { fetchFeedUserAsync } from '../feed/thunks';
 
 
 // Calcul temps de publication d'un post / commentaire
@@ -51,39 +50,27 @@ export const fetchPost = (postid: number): AppThunkAction<Promise<void>> => {
 // Ajouter un post
 export const addPost = (resources: File[], location: string, caption: string): AppThunkAction<Promise<void>> => { //ajouter les autres éléments (accessibilityCaption, hasCommentsDisabled) ?
   return async (dispatch, getState, api) => {
-    try {
-      const { data } = await api.posts.create({
-        resources: resources,
-        location: location,
-        caption: caption,
-      });
-      dispatch(setPost(data));
-    } catch (fff) {
-      throw fff;
-    }
+    const { data } = await api.posts.create({
+      resources: resources,
+      location: location,
+      caption: caption,
+    });
+    dispatch(setPost(data));
   };
 };
 
 // Follow someone
 export const followUserPostAsync = (userId: number): AppThunkAction<Promise<void>> => {
   return async (dispatch, getState, api) => {
-    try {
-      await api.users.me.followers.follow(userId);
-      dispatch(followUserPostAction());
-    } catch (e) {
-      throw e;
-    }
+    await api.users.me.followers.follow(userId);
+    dispatch(followUserPostAction());
   };
 };
 
 // Unfollow someone
 export const unfollowUserPostAsync = (userId: number): AppThunkAction<Promise<void>> => {
   return async (dispatch, getState, api) => {
-    try {
-      await api.users.me.followers.unfollow(userId);
-      dispatch(unfollowUserPostAction());
-    } catch (e) {
-      throw e;
-    }
+    await api.users.me.followers.unfollow(userId);
+    dispatch(unfollowUserPostAction());
   };
 };
-- 
GitLab