bigbuffet-rw/app/soapbox/actions/pin_statuses.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-01-10 14:01:24 -08:00
import { isLoggedIn } from 'soapbox/utils/auth';
2020-03-27 13:59:38 -07:00
import api from '../api';
2020-03-27 13:59:38 -07:00
import { importFetchedStatuses } from './importer';
export const PINNED_STATUSES_FETCH_REQUEST = 'PINNED_STATUSES_FETCH_REQUEST';
export const PINNED_STATUSES_FETCH_SUCCESS = 'PINNED_STATUSES_FETCH_SUCCESS';
export const PINNED_STATUSES_FETCH_FAIL = 'PINNED_STATUSES_FETCH_FAIL';
export function fetchPinnedStatuses() {
return (dispatch, getState) => {
2021-03-25 10:28:53 -07:00
if (!isLoggedIn(getState)) return;
const me = getState().get('me');
2020-03-27 13:59:38 -07:00
dispatch(fetchPinnedStatusesRequest());
api(getState).get(`/api/v1/accounts/${me}/statuses`, { params: { pinned: true } }).then(response => {
dispatch(importFetchedStatuses(response.data));
dispatch(fetchPinnedStatusesSuccess(response.data, null));
}).catch(error => {
dispatch(fetchPinnedStatusesFail(error));
});
};
2021-08-03 12:22:51 -07:00
}
2020-03-27 13:59:38 -07:00
export function fetchPinnedStatusesRequest() {
return {
type: PINNED_STATUSES_FETCH_REQUEST,
};
2021-08-03 12:22:51 -07:00
}
2020-03-27 13:59:38 -07:00
export function fetchPinnedStatusesSuccess(statuses, next) {
return {
type: PINNED_STATUSES_FETCH_SUCCESS,
statuses,
next,
};
2021-08-03 12:22:51 -07:00
}
2020-03-27 13:59:38 -07:00
export function fetchPinnedStatusesFail(error) {
return {
type: PINNED_STATUSES_FETCH_FAIL,
error,
};
2021-08-03 12:22:51 -07:00
}