File size: 1,184 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import * as ApiUtil from '../util/post_api_util';

export const RECEIVE_POST_PAYLOAD = 'RECEIVE_POST_PAYLOAD';
export const RECEIVE_POST = 'RECEIVE_POST';
export const REMOVE_POST = 'REMOVE_POST';

const receivePostPayload = postPayload => ({
  type: RECEIVE_POST_PAYLOAD,
  postPayload
});

const receivePost = post => ({
  type: RECEIVE_POST,
  post
});

const removePost = postId => ({
  type: REMOVE_POST,
  postId
});

export const requestPost = postId => dispatch =>
  ApiUtil.fetchPost(postId).then(res => dispatch(receivePost(res))
);

export const requestWallPosts = userId => dispatch => (
  ApiUtil.fetchWallPosts(userId).then(res => dispatch(receivePostPayload(res)))
);

export const requestFeedPosts = userId => dispatch => (
  ApiUtil.fetchFeedPosts(userId).then(res => dispatch(receivePostPayload(res)))
);

export const createPost = post => dispatch => (
  ApiUtil.createPost(post).then(res => dispatch(receivePost(res)))
);

export const updatePost = post => dispatch => (
  ApiUtil.updatePost(post).then(res => dispatch(receivePost(res)))
);

export const deletePost = postId => dispatch => (
  ApiUtil.deletePost(postId).then(res => dispatch(removePost(res.id)))
)