2018-12-01 16:10:41 +00:00
|
|
|
import config from '../config';
|
2018-12-02 14:05:51 +00:00
|
|
|
import { START_LOADING_VIDEOS, RECEIVE_VIDEOS } from './action_types';
|
2018-12-01 16:10:41 +00:00
|
|
|
|
|
|
|
function fetchVideos() {
|
|
|
|
console.log('fetchVideos called');
|
|
|
|
return dispatch => {
|
|
|
|
console.log('inside dispatch function');
|
|
|
|
dispatch(startLoadingVideos());
|
|
|
|
const params = {
|
|
|
|
"keys":["editable","modified","title","source","project","topic","language","duration","id"],
|
|
|
|
"query": {
|
|
|
|
"conditions":[],
|
|
|
|
"operator":"&"
|
|
|
|
},
|
|
|
|
"range":[0,100],
|
|
|
|
"sort": [{"key":"title","operator":"+"}]
|
|
|
|
};
|
|
|
|
let formData = new FormData();
|
|
|
|
formData.append('action', 'find');
|
|
|
|
formData.append('data', JSON.stringify(params));
|
|
|
|
fetch(config.apiUrl, {
|
|
|
|
method: 'POST',
|
|
|
|
// headers: {
|
|
|
|
// "Content-Type": "application/x-www-form-urlencoded"
|
|
|
|
// },
|
|
|
|
body: formData
|
|
|
|
})
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(json => {
|
|
|
|
dispatch(receiveVideos(json.data.items));
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function startLoadingVideos() {
|
|
|
|
return {
|
2018-12-02 14:05:51 +00:00
|
|
|
type: START_LOADING_VIDEOS
|
2018-12-01 16:10:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function receiveVideos(videos) {
|
|
|
|
return {
|
2018-12-02 14:05:51 +00:00
|
|
|
type: RECEIVE_VIDEOS,
|
2018-12-01 16:10:41 +00:00
|
|
|
payload: videos
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default fetchVideos;
|