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

nettoyage des thunks

parent b25faa0f
Branches
Tags
No related merge requests found
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));
};
};
......
......@@ -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());
};
};
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