-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
tweetsActions.js
45 lines (40 loc) · 1.04 KB
/
tweetsActions.js
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
import axios from "axios";
export function fetchTweets() {
return function(dispatch) {
dispatch({type: "FETCH_TWEETS"});
/*
http://rest.learncode.academy is a public test server, so another user's experimentation can break your tests
If you get console errors due to bad data:
- change "reacttest" below to any other username
- post some tweets to http://rest.learncode.academy/api/yourusername/tweets
*/
axios.get("http://rest.learncode.academy/api/reacttest/tweets")
.then((response) => {
dispatch({type: "FETCH_TWEETS_FULFILLED", payload: response.data})
})
.catch((err) => {
dispatch({type: "FETCH_TWEETS_REJECTED", payload: err})
})
}
}
export function addTweet(id, text) {
return {
type: 'ADD_TWEET',
payload: {
id,
text,
},
}
}
export function updateTweet(id, text) {
return {
type: 'UPDATE_TWEET',
payload: {
id,
text,
},
}
}
export function deleteTweet(id) {
return { type: 'DELETE_TWEET', payload: id}
}