You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
142 lines
3.1 KiB
142 lines
3.1 KiB
8 years ago
|
import api from '../api';
|
||
|
|
||
|
import { deleteFromTimelines } from './timelines';
|
||
8 years ago
|
import { fetchStatusCard } from './cards';
|
||
8 years ago
|
|
||
|
export const STATUS_FETCH_REQUEST = 'STATUS_FETCH_REQUEST';
|
||
|
export const STATUS_FETCH_SUCCESS = 'STATUS_FETCH_SUCCESS';
|
||
|
export const STATUS_FETCH_FAIL = 'STATUS_FETCH_FAIL';
|
||
8 years ago
|
|
||
8 years ago
|
export const STATUS_DELETE_REQUEST = 'STATUS_DELETE_REQUEST';
|
||
|
export const STATUS_DELETE_SUCCESS = 'STATUS_DELETE_SUCCESS';
|
||
|
export const STATUS_DELETE_FAIL = 'STATUS_DELETE_FAIL';
|
||
|
|
||
8 years ago
|
export const CONTEXT_FETCH_REQUEST = 'CONTEXT_FETCH_REQUEST';
|
||
|
export const CONTEXT_FETCH_SUCCESS = 'CONTEXT_FETCH_SUCCESS';
|
||
|
export const CONTEXT_FETCH_FAIL = 'CONTEXT_FETCH_FAIL';
|
||
|
|
||
8 years ago
|
export function fetchStatusRequest(id, skipLoading) {
|
||
8 years ago
|
return {
|
||
|
type: STATUS_FETCH_REQUEST,
|
||
8 years ago
|
id,
|
||
|
skipLoading
|
||
8 years ago
|
};
|
||
|
};
|
||
|
|
||
|
export function fetchStatus(id) {
|
||
|
return (dispatch, getState) => {
|
||
8 years ago
|
const skipLoading = getState().getIn(['statuses', id], null) !== null;
|
||
|
|
||
8 years ago
|
dispatch(fetchContext(id));
|
||
8 years ago
|
dispatch(fetchStatusCard(id));
|
||
8 years ago
|
|
||
|
if (skipLoading) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
8 years ago
|
dispatch(fetchStatusRequest(id, skipLoading));
|
||
8 years ago
|
|
||
8 years ago
|
api(getState).get(`/api/v1/statuses/${id}`).then(response => {
|
||
8 years ago
|
dispatch(fetchStatusSuccess(response.data, skipLoading));
|
||
8 years ago
|
}).catch(error => {
|
||
8 years ago
|
dispatch(fetchStatusFail(id, error, skipLoading));
|
||
8 years ago
|
});
|
||
|
};
|
||
|
};
|
||
|
|
||
8 years ago
|
export function fetchStatusSuccess(status, skipLoading) {
|
||
8 years ago
|
return {
|
||
|
type: STATUS_FETCH_SUCCESS,
|
||
8 years ago
|
status,
|
||
|
skipLoading
|
||
8 years ago
|
};
|
||
|
};
|
||
|
|
||
8 years ago
|
export function fetchStatusFail(id, error, skipLoading) {
|
||
8 years ago
|
return {
|
||
|
type: STATUS_FETCH_FAIL,
|
||
8 years ago
|
id,
|
||
|
error,
|
||
8 years ago
|
skipLoading,
|
||
|
skipAlert: true
|
||
8 years ago
|
};
|
||
|
};
|
||
8 years ago
|
|
||
|
export function deleteStatus(id) {
|
||
|
return (dispatch, getState) => {
|
||
|
dispatch(deleteStatusRequest(id));
|
||
|
|
||
|
api(getState).delete(`/api/v1/statuses/${id}`).then(response => {
|
||
|
dispatch(deleteStatusSuccess(id));
|
||
8 years ago
|
dispatch(deleteFromTimelines(id));
|
||
8 years ago
|
}).catch(error => {
|
||
|
dispatch(deleteStatusFail(id, error));
|
||
|
});
|
||
|
};
|
||
|
};
|
||
|
|
||
|
export function deleteStatusRequest(id) {
|
||
|
return {
|
||
|
type: STATUS_DELETE_REQUEST,
|
||
|
id: id
|
||
|
};
|
||
|
};
|
||
|
|
||
|
export function deleteStatusSuccess(id) {
|
||
|
return {
|
||
|
type: STATUS_DELETE_SUCCESS,
|
||
|
id: id
|
||
|
};
|
||
|
};
|
||
|
|
||
|
export function deleteStatusFail(id, error) {
|
||
|
return {
|
||
|
type: STATUS_DELETE_FAIL,
|
||
|
id: id,
|
||
|
error: error
|
||
|
};
|
||
|
};
|
||
8 years ago
|
|
||
|
export function fetchContext(id) {
|
||
|
return (dispatch, getState) => {
|
||
|
dispatch(fetchContextRequest(id));
|
||
|
|
||
|
api(getState).get(`/api/v1/statuses/${id}/context`).then(response => {
|
||
|
dispatch(fetchContextSuccess(id, response.data.ancestors, response.data.descendants));
|
||
8 years ago
|
|
||
8 years ago
|
}).catch(error => {
|
||
8 years ago
|
if (error.response.status === 404) {
|
||
8 years ago
|
dispatch(deleteFromTimelines(id));
|
||
|
}
|
||
8 years ago
|
|
||
|
dispatch(fetchContextFail(id, error));
|
||
8 years ago
|
});
|
||
|
};
|
||
|
};
|
||
|
|
||
|
export function fetchContextRequest(id) {
|
||
|
return {
|
||
|
type: CONTEXT_FETCH_REQUEST,
|
||
|
id
|
||
|
};
|
||
|
};
|
||
|
|
||
|
export function fetchContextSuccess(id, ancestors, descendants) {
|
||
|
return {
|
||
|
type: CONTEXT_FETCH_SUCCESS,
|
||
|
id,
|
||
|
ancestors,
|
||
|
descendants,
|
||
|
statuses: ancestors.concat(descendants)
|
||
|
};
|
||
|
};
|
||
|
|
||
|
export function fetchContextFail(id, error) {
|
||
|
return {
|
||
|
type: CONTEXT_FETCH_FAIL,
|
||
|
id,
|
||
8 years ago
|
error,
|
||
|
skipAlert: true
|
||
8 years ago
|
};
|
||
|
};
|