File size: 1,520 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
45
46
47
48
49
50
51
52
53
54
55
56
import * as PostApiUtil from '../util/posts_api_util';
import {receiveErrors} from './session_actions';
export const RECEIVE_POST = 'RECEIVE_POST';
export const RECEIVE_ALL_POSTS = 'RECEIVE_ALL_POSTS';
export const RECEIVE_WALL_POSTS = 'RECEIVE_WALL_POSTS';
export const RECEIVE_NEWS_FEED_POSTS = 'RECEIVE_NEWS_FEED_POSTS';

export const createPost = postForm => dispatch =>
  PostApiUtil.createPost(postForm).then(post => dispatch(receivePost(post)));

export const updatePost = postForm => dispatch =>
  PostApiUtil.updatePost(postForm).then(post => dispatch(receivePost(post)));

export const deletePost = id => dispatch =>
  PostApiUtil.deletePost(id);

export const fetchWallPosts = id => dispatch =>
  PostApiUtil.fetchWallPosts(id).then(posts =>
    dispatch(receiveWallPosts(posts))
  );

export const fetchNewsFeed =() => dispatch =>
  PostApiUtil.fetchNewsFeed().then(posts =>
    dispatch(receiveAllPosts(posts)));


export const fetchPost = id => dispatch => (
    PostApiUtil.fetchPost(id).then(post => dispatch(receivePost(post)))
);

export const fetchAllPosts = ()=> dispatch => (
    PostApiUtil.fetchAllPosts()
    .then(posts => dispatch(receiveAllPosts(posts)))
);

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

export const receiveWallPosts = posts => ({
  type: RECEIVE_WALL_POSTS,
  posts
});

export const receiveAllPosts = posts => ({
  type: RECEIVE_ALL_POSTS,
  posts
});


export const receiveNewsFeedPosts = posts => ({
  type: RECEIVE_NEWS_FEED_POSTS,
  posts
});