diff --git a/app/javascript/mastodon/actions/compose.js b/app/javascript/mastodon/actions/compose.js index aa1c6de20e..28d484a73a 100644 --- a/app/javascript/mastodon/actions/compose.js +++ b/app/javascript/mastodon/actions/compose.js @@ -81,6 +81,8 @@ export const COMPOSE_CHANGE_MEDIA_ORDER = 'COMPOSE_CHANGE_MEDIA_ORDER'; export const COMPOSE_SET_STATUS = 'COMPOSE_SET_STATUS'; export const COMPOSE_FOCUS = 'COMPOSE_FOCUS'; +export const COMPOSE_CHANGE_IS_SCHEDULED = 'COMPOSE_CHANGE_IS_SCHEDULED'; + 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.' }, @@ -835,3 +837,9 @@ export const changeMediaOrder = (a, b) => ({ a, b, }); + +export function changeIsScheduled() { + return { + type: COMPOSE_IS_SCHEDULED_CHANGE, + }; +} diff --git a/app/javascript/mastodon/features/compose/components/compose_form.jsx b/app/javascript/mastodon/features/compose/components/compose_form.jsx index c7678c8ce9..ab3212bb63 100644 --- a/app/javascript/mastodon/features/compose/components/compose_form.jsx +++ b/app/javascript/mastodon/features/compose/components/compose_form.jsx @@ -71,6 +71,11 @@ class ComposeForm extends ImmutablePureComponent { singleColumn: PropTypes.bool, lang: PropTypes.string, maxChars: PropTypes.number, + + schedule_time: PropTypes.string, + schedule_timezone: PropTypes.string, + is_scheduled: PropTypes.bool.isRequired, + scheduled_at: PropTypes.string, }; static defaultProps = { @@ -312,6 +317,7 @@ class ComposeForm extends ImmutablePureComponent {
diff --git a/app/javascript/mastodon/features/compose/containers/schedule_button_container.js b/app/javascript/mastodon/features/compose/containers/schedule_button_container.js index e428270597..963bf920bc 100644 --- a/app/javascript/mastodon/features/compose/containers/schedule_button_container.js +++ b/app/javascript/mastodon/features/compose/containers/schedule_button_container.js @@ -1,31 +1,26 @@ -import { injectIntl,defineMessages } from "react-intl"; +import { injectIntl, defineMessages } from "react-intl"; import { connect } from "react-redux"; import ScheduleIcon from '@/material-icons/400-20px/schedule.svg?react'; import { IconButton } from "@/mastodon/components/icon_button"; +import { changeIsScheduled } from '../../actions/compose'; - -const mapStateToProps = () => ({ +const mapStateToProps = (state) => ({ iconComponent: ScheduleIcon, - title: defineMessages({ - title: { - id: 'compose.schedule_button.title', - defaultMessage: 'Schedule', - }, - }), - active: false, - ariaControls: 'schedule-compose-form', + title: 'schedule', + active: state.getIn(['compose', 'is_scheduled']), + size: 18, inverted: true, }); const mapDispatchToProps = dispatch => ({ onClick () { - dispatch({ type: 'SCHEDULE_COMPOSE' }); + dispatch(changeIsScheduled()); }, }); diff --git a/app/javascript/mastodon/reducers/compose.js b/app/javascript/mastodon/reducers/compose.js index bfa2ec6a06..3d8dc315fd 100644 --- a/app/javascript/mastodon/reducers/compose.js +++ b/app/javascript/mastodon/reducers/compose.js @@ -50,6 +50,7 @@ import { COMPOSE_CHANGE_MEDIA_ORDER, COMPOSE_SET_STATUS, COMPOSE_FOCUS, + COMPOSE_CHANGE_IS_SCHEDULED, } from '../actions/compose'; import { REDRAFT } from '../actions/statuses'; import { STORE_HYDRATE } from '../actions/store'; @@ -94,6 +95,11 @@ const initialState = ImmutableMap({ focusY: 0, dirty: false, }), + + schedule_time: new Date().toLocaleString('zh-CN').split('/').join('-').split(' ').join('T')+'.0', + schedule_timezone: new Date().getTimezoneOffset() > 0?'-':'+' + (0 - new Date().getTimezoneOffset() / 60) + ':' + ((0 - new Date().getTimezoneOffset() % 60) === 30 ? '30' :'00'), + is_scheduled: false, + scheduled_at: null, }); const initialPoll = ImmutableMap({ @@ -560,6 +566,12 @@ export default function compose(state = initialState, action) { return list.splice(indexA, 1).splice(indexB, 0, moveItem); }); + case COMPOSE_CHANGE_IS_SCHEDULED: + return state.withMutations(map => { + map.set('is_scheduled', !state.get('is_scheduled')); + map.set('scheduled_at', state.get('schedule_time') + state.get('schedule_timezone')); + map.set('idempotencyKey', uuid()); + }); default: return state; }