Skip to content
Snippets Groups Projects
Commit 01ca83b0 authored by Chloé JACOB's avatar Chloé JACOB :alien:
Browse files

nettoyage des thunks

parent b25faa0f
No related merge requests found
import { Instalike } from '@jmetterrothan/instalike'; import { Instalike } from '@jmetterrothan/instalike';
import { data } from 'autoprefixer'; import { data } from 'autoprefixer';
// Autres fichiers // AUTRES FICHIERS
import type { AppThunkAction } from '../types'; import type { AppThunkAction } from '../types';
import { setUserFeed, likePostFeedAction, unlikePostFeedAction, deleteCommentFeedAction, followUserFeedAction, unfollowUserFeedAction } from './actions'; import { setUserFeed, likePostFeedAction, unlikePostFeedAction, deleteCommentFeedAction, followUserFeedAction, unfollowUserFeedAction } from './actions';
...@@ -9,46 +9,32 @@ import { setUserFeed, likePostFeedAction, unlikePostFeedAction, deleteCommentFee ...@@ -9,46 +9,32 @@ import { setUserFeed, likePostFeedAction, unlikePostFeedAction, deleteCommentFee
// Users pour le feed // Users pour le feed
export const fetchFeedUserAsync = (): AppThunkAction<Promise<void>> => { export const fetchFeedUserAsync = (): AppThunkAction<Promise<void>> => {
return async (dispatch, getState, api) => { return async (dispatch, getState, api) => {
const { data } = await api.users.me.feed.fetch({ cursor: null }); const { data } = await api.users.me.feed.fetch({ cursor: null });
dispatch(setUserFeed(data.items)); dispatch(setUserFeed(data.items));
}; };
}; };
// Like post // Like post
export const likepostAsync = (postId: number): AppThunkAction<Promise<void>> => { export const likepostAsync = (postId: number): AppThunkAction<Promise<void>> => {
return async (dispatch, getState, api) => { return async (dispatch, getState, api) => {
try { await api.posts.find(postId).like();
await api.posts.find(postId).like(); dispatch(likePostFeedAction(postId));
dispatch(likePostFeedAction(postId));
} catch (e) {
throw e;
}
}; };
}; };
// Unlike post // Unlike post
export const unlikePostAsync = (postId: number): AppThunkAction<Promise<void>> => { export const unlikePostAsync = (postId: number): AppThunkAction<Promise<void>> => {
return async (dispatch, getState, api) => { return async (dispatch, getState, api) => {
try { await api.posts.find(postId).unlike();
await api.posts.find(postId).unlike(); dispatch(unlikePostFeedAction(postId));
dispatch(unlikePostFeedAction(postId));
} catch (e) {
throw e;
}
}; };
}; };
// Delete its own comment // Delete its own comment
export const deleteCommentFeedAsync = (postId: number, commentId: number): AppThunkAction<Promise<void>> => { export const deleteCommentFeedAsync = (postId: number, commentId: number): AppThunkAction<Promise<void>> => {
return async (dispatch, getState, api) => { return async (dispatch, getState, api) => {
try { await api.posts.find(postId).comments.find(commentId).delete();
await api.posts.find(postId).comments.find(commentId).delete(); dispatch(deleteCommentFeedAction(commentId));
dispatch(deleteCommentFeedAction(commentId));
} catch (e) {
throw e;
}
}; };
}; };
......
...@@ -4,7 +4,6 @@ import { data } from 'autoprefixer'; ...@@ -4,7 +4,6 @@ import { data } from 'autoprefixer';
// AUTRES FICHIERS // AUTRES FICHIERS
import { AppThunkAction } from '../types'; import { AppThunkAction } from '../types';
import { failurePostAction, loadPostAction, setPost, sucessPostAction, followUserPostAction, unfollowUserPostAction } from './actions'; import { failurePostAction, loadPostAction, setPost, sucessPostAction, followUserPostAction, unfollowUserPostAction } from './actions';
import { fetchFeedUserAsync } from '../feed/thunks';
// Calcul temps de publication d'un post / commentaire // Calcul temps de publication d'un post / commentaire
...@@ -51,39 +50,27 @@ export const fetchPost = (postid: number): AppThunkAction<Promise<void>> => { ...@@ -51,39 +50,27 @@ export const fetchPost = (postid: number): AppThunkAction<Promise<void>> => {
// Ajouter un post // Ajouter un post
export const addPost = (resources: File[], location: string, caption: string): AppThunkAction<Promise<void>> => { //ajouter les autres éléments (accessibilityCaption, hasCommentsDisabled) ? export const addPost = (resources: File[], location: string, caption: string): AppThunkAction<Promise<void>> => { //ajouter les autres éléments (accessibilityCaption, hasCommentsDisabled) ?
return async (dispatch, getState, api) => { return async (dispatch, getState, api) => {
try { const { data } = await api.posts.create({
const { data } = await api.posts.create({ resources: resources,
resources: resources, location: location,
location: location, caption: caption,
caption: caption, });
}); dispatch(setPost(data));
dispatch(setPost(data));
} catch (fff) {
throw fff;
}
}; };
}; };
// Follow someone // Follow someone
export const followUserPostAsync = (userId: number): AppThunkAction<Promise<void>> => { export const followUserPostAsync = (userId: number): AppThunkAction<Promise<void>> => {
return async (dispatch, getState, api) => { return async (dispatch, getState, api) => {
try { await api.users.me.followers.follow(userId);
await api.users.me.followers.follow(userId); dispatch(followUserPostAction());
dispatch(followUserPostAction());
} catch (e) {
throw e;
}
}; };
}; };
// Unfollow someone // Unfollow someone
export const unfollowUserPostAsync = (userId: number): AppThunkAction<Promise<void>> => { export const unfollowUserPostAsync = (userId: number): AppThunkAction<Promise<void>> => {
return async (dispatch, getState, api) => { return async (dispatch, getState, api) => {
try { await api.users.me.followers.unfollow(userId);
await api.users.me.followers.unfollow(userId); dispatch(unfollowUserPostAction());
dispatch(unfollowUserPostAction());
} catch (e) {
throw e;
}
}; };
}; };
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment