forked from GetStream/stream-react-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocation.js
More file actions
50 lines (46 loc) · 932 Bytes
/
Copy pathLocation.js
File metadata and controls
50 lines (46 loc) · 932 Bytes
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
import * as axios from 'axios';
import config from 'config';
/**
* LOAD
* @type {string}
*/
export const LOAD = 'LOCATION_LOAD';
/**
* _loadRequest
* @param location
* @private
*/
export const _loadRequest = location => ({ type: LOAD, location });
/**
* _loadResponse
* @param location
* @param response
* @private
*/
export const _loadResponse = (location, response) => ({
type: LOAD,
location,
response,
});
/**
* load
* Gets data from API for a given location
* Redux Action
* Reference: http://redux.js.org/docs/basics/Actions.html
* @param location
* @returns {Function}
*/
export function load(location) {
return dispatch => {
dispatch(_loadRequest(location));
axios
.get(`${config.api.baseUrl}/locations?q=${location}`, {
headers: {
Authorization: `Bearer ${localStorage.getItem('jwt')}`,
},
})
.then(res => {
dispatch(_loadResponse(location, res.data));
});
};
}