Added redux functionality for scheduled posts
This commit is contained in:
parent
904a6b5556
commit
6ede1426f2
@ -61,6 +61,8 @@ export const COMPOSE_POLL_OPTION_CHANGE = 'COMPOSE_POLL_OPTION_CHANGE';
|
||||
export const COMPOSE_POLL_OPTION_REMOVE = 'COMPOSE_POLL_OPTION_REMOVE';
|
||||
export const COMPOSE_POLL_SETTINGS_CHANGE = 'COMPOSE_POLL_SETTINGS_CHANGE';
|
||||
|
||||
export const COMPOSE_SCHEDULED_AT_CHANGE = 'COMPOSE_SCHEDULED_AT_CHANGE';
|
||||
|
||||
const messages = defineMessages({
|
||||
uploadErrorLimit: { id: 'upload_error.limit', defaultMessage: 'File upload limit exceeded.' },
|
||||
uploadErrorPoll: { id: 'upload_error.poll', defaultMessage: 'File upload not allowed with polls.' },
|
||||
@ -140,6 +142,12 @@ export function directCompose(account, routerHistory) {
|
||||
export function handleComposeSubmit(dispatch, getState, response, status) {
|
||||
if (!dispatch || !getState) return;
|
||||
|
||||
const isScheduledStatus = response.data['scheduled_at'] !== undefined;
|
||||
if (isScheduledStatus) {
|
||||
dispatch(submitComposeSuccess({ ...response.data }));
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(insertIntoTagHistory(response.data.tags, status));
|
||||
dispatch(submitComposeSuccess({ ...response.data }));
|
||||
|
||||
@ -193,6 +201,7 @@ export function submitCompose(routerHistory, group) {
|
||||
visibility: getState().getIn(['compose', 'privacy']),
|
||||
poll: getState().getIn(['compose', 'poll'], null),
|
||||
group_id: group ? group.get('id') : null,
|
||||
scheduled_at: getState().getIn(['compose', 'scheduled_at'], null),
|
||||
}, {
|
||||
headers: {
|
||||
'Idempotency-Key': getState().getIn(['compose', 'idempotencyKey']),
|
||||
@ -580,3 +589,10 @@ export function changePollSettings(expiresIn, isMultiple) {
|
||||
isMultiple,
|
||||
};
|
||||
};
|
||||
|
||||
export function changeScheduledAt(date) {
|
||||
return {
|
||||
type: COMPOSE_SCHEDULED_AT_CHANGE,
|
||||
date,
|
||||
};
|
||||
};
|
@ -36,6 +36,7 @@ import {
|
||||
COMPOSE_POLL_OPTION_CHANGE,
|
||||
COMPOSE_POLL_OPTION_REMOVE,
|
||||
COMPOSE_POLL_SETTINGS_CHANGE,
|
||||
COMPOSE_SCHEDULED_AT_CHANGE,
|
||||
} from '../actions/compose';
|
||||
import { TIMELINE_DELETE } from '../actions/timelines';
|
||||
import { STORE_HYDRATE } from '../actions/store';
|
||||
@ -72,6 +73,7 @@ const initialState = ImmutableMap({
|
||||
resetFileKey: Math.floor((Math.random() * 0x10000)),
|
||||
idempotencyKey: null,
|
||||
tagHistory: ImmutableList(),
|
||||
scheduled_at: null,
|
||||
});
|
||||
|
||||
const initialPoll = ImmutableMap({
|
||||
@ -105,6 +107,7 @@ function clearAll(state) {
|
||||
map.update('media_attachments', list => list.clear());
|
||||
map.set('poll', null);
|
||||
map.set('idempotencyKey', uuid());
|
||||
map.set('scheduled_at', null);
|
||||
});
|
||||
};
|
||||
|
||||
@ -293,6 +296,7 @@ export default function compose(state = initialState, action) {
|
||||
map.set('privacy', state.get('default_privacy'));
|
||||
map.set('poll', null);
|
||||
map.set('idempotencyKey', uuid());
|
||||
map.set('scheduled_at', null);
|
||||
});
|
||||
case COMPOSE_SUBMIT_REQUEST:
|
||||
return state.set('is_submitting', true);
|
||||
@ -389,6 +393,8 @@ export default function compose(state = initialState, action) {
|
||||
return state.updateIn(['poll', 'options'], options => options.delete(action.index));
|
||||
case COMPOSE_POLL_SETTINGS_CHANGE:
|
||||
return state.update('poll', poll => poll.set('expires_in', action.expiresIn).set('multiple', action.isMultiple));
|
||||
case COMPOSE_SCHEDULED_AT_CHANGE:
|
||||
return state.set('scheduled_at', action.date);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user