scinote-web/app/javascript/packs/shared/actions/ActivitiesActions.js

34 lines
751 B
JavaScript
Raw Normal View History

import axios from "../../app/axios";
2017-08-02 23:27:05 +08:00
import { ACTIVITIES_PATH } from "../../app/routes";
2017-08-22 19:20:06 +08:00
import {
GLOBAL_ACTIVITIES_DATA,
DESTROY_GLOBAL_ACTIVITIES_DATA
} from "../../app/action_types";
2017-08-02 23:27:05 +08:00
2017-08-03 22:03:15 +08:00
function addActivitiesData(data) {
2017-08-02 23:27:05 +08:00
return {
type: GLOBAL_ACTIVITIES_DATA,
payload: data
};
}
2017-08-22 19:20:06 +08:00
export function destroyActivities() {
return {
type: DESTROY_GLOBAL_ACTIVITIES_DATA
};
}
export function getActivities(lastId = 0) {
2017-08-02 23:27:05 +08:00
return dispatch => {
2017-08-22 19:20:06 +08:00
const path = `${ACTIVITIES_PATH}?from=${lastId}`;
2017-08-02 23:27:05 +08:00
axios
.get(path, { withCredentials: true })
.then(response => {
dispatch(addActivitiesData(response.data));
})
.catch(error => {
console.log("get Activites Error: ", error);
});
};
}